section .text

.globl fact
fact:
entry:
    push rbp
    mov rbp, rsp
    push rbx
    push rsi
    sub rsp, 32
    mov r10, 0
    mov rbx, 0
    mov [rbp+1], rbx
    mov r10, 0
    mov rbx, 0
    mov [rbp+2], rbx
    mov [rbp+2], rcx
    mov r10, 0
    mov rbx, 0
    mov [rbp+3], rbx
    mov r10, 0
    mov rbx, 0
    mov [rbp+4], rbx
    mov r10, 1
    mov rbx, 1
    mov [rbp+3], rbx
    mov r10, [rbp+2]
    mov rbx, [rbp+2]
    cmp rbx, 0
    mov r10, 0
    mov rbx, 0
    mov r10, 0
    sete r10
    mov rbx, r10
    cmp rbx, 0
    jne pb_if_then_0
    jmp pb_if_else_1
pb_if_then_0:
    mov rbx, 1
    mov [rbp+1], rbx
    jmp pb_if_end_2
pb_if_else_1:
    mov rbx, 1
    mov [rbp+4], rbx
    jmp pb_for_cond_3
pb_if_end_2:
    mov r10, [rbp+1]
    mov rbx, [rbp+1]
    mov rax, [rbp+1]
    add rsp, 32
    pop rsi
    pop rbx
    pop rbp
    ret _
pb_for_cond_3:
    mov r10, [rbp+2]
    mov rbx, [rbp+2]
    mov r10, [rbp+4]
    mov rsi, [rbp+4]
    cmp rsi, rbx
    mov r10, 0
    mov rbx, 0
    mov r10, 0
    setle r10
    mov rbx, r10
    cmp rbx, 0
    jne pb_for_body_4
    jmp pb_for_end_6
pb_for_body_4:
    mov r10, [rbp+3]
    mov rbx, [rbp+3]
    mov r10, [rbp+4]
    mov rbx, [rbp+4]
    mov rbx, 1
    mov [rbp+3], rbx
    jmp pb_for_step_5
pb_for_step_5:
    mov r10, [rbp+4]
    mov rbx, [rbp+4]
    add rbx, 1
    mov rsi, rbx
    mov [rbp+4], rsi
    jmp pb_for_cond_3
pb_for_end_6:
    mov r10, [rbp+3]
    mov rbx, [rbp+3]
    mov rsi, [rbp+3]
    mov [rbp+1], rsi
    jmp pb_if_end_2

.globl main
main:
entry:
    push rbp
    mov rbp, rsp
    push rbx
    push rsi
    sub rsp, 16
    mov r10, 0
    mov rbx, 0
    mov [rbp+1], rbx
    mov rcx, 5
    sub rsp, 32
    call fact
    add rsp, 32
    mov rbx, rax
    mov rsi, rax
    mov [rbp+1], rsi
    mov r10, [rbp+1]
    mov rbx, [rbp+1]
    mov rax, [rbp+1]
    add rsp, 16
    pop rsi
    pop rbx
    pop rbp
    ret _

