// File: /workspace/github_c_makefile_star2_O0/johnvtan[P]ccccc/asm.c
// Function: unary_to_instrs
static list_t *unary_to_instrs(unary_expr_t *unary, env_t *env) {
    list_t *ret = expr_to_instrs(unary->expr, env);
    if (!ret) {
        UNREACHABLE("unary_to_instrs: unary expr could not be generated\n");
    }
    debug("unary to instrs\n");
    if (unary->op == UNARY_MATH_NEG) {
        list_push(ret, instr_r(OP_NEG, REG_RAX));
        return ret;
    } 

    if (unary->op == UNARY_LOGICAL_NEG) {
        list_push(ret, instr_i2r(OP_CMP, 0, REG_RAX));
        list_push(ret, instr_i2r(OP_MOV, 0, REG_RAX));
        list_push(ret, instr_r(OP_SETE, REG_AL));
        return ret;
    }

    if (unary->op == UNARY_BITWISE_COMP) {
        list_push(ret, instr_r(OP_NOT, REG_RAX));
        return ret;
    }

    if (unary->op == UNARY_POSTINC) {
        debug("post inc\n");
        var_info_t *var_info = env_get_declared(env, unary->expr->primary->var);
        if (!var_info) {
            UNREACHABLE("assign_to_instrs: variable is used before declaration");
        }

        // Note that while we could add 1 directly to the memory location, this code is more
        // generic and will be easier to use when dereference/array code is supported
        list_push(ret, instr_i2m(OP_ADD, 1, var_info->home));
        //list_push(ret, instr_r2m(OP_MOV, REG_RAX, var_info->home));
        return ret;
    }

    if (unary->op == UNARY_POSTDEC) {
        var_info_t *var_info = env_get_declared(env, unary->expr->primary->var);
        debug("Found postdec\n");
        if (!var_info) {
            UNREACHABLE("assign_to_instrs: variable is used before declaration");
        }
        //list_push(ret, instr_i2r(OP_SUB, 1, REG_RAX));
        //list_push(ret, instr_r2m(OP_MOV, REG_RAX, var_info->home));
        list_push(ret, instr_i2m(OP_SUB, 1, var_info->home));
        return ret;
    }

    UNREACHABLE("unexpected unary expr\n");
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x2a50
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x30a9
jmp 0x307e
leaq 0x5f7f(%rip), %rdi      # 0x9004
leaq 0x5fb2(%rip), %rsi      # 0x903e
movl $0x171, %edx            # imm = 0x171
leaq 0x6353(%rip), %rcx      # 0x93eb
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
jmp 0x30ab
jmp 0x30ad
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x30e6
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x6, %edi
movl $0x1, %esi
callq 0x2650
movq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3305
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x316a
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x4, %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x2810
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %esi
movl %edx, %edi
callq 0x2810
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x5, %edi
movl $0x11, %esi
callq 0x2650
movq -0x40(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3305
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x31a3
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x7, %edi
movl $0x1, %esi
callq 0x2650
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3305
movq -0x10(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x3240
jmp 0x31b2
jmp 0x31b4
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x4520
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3205
jmp 0x31da
leaq 0x5e23(%rip), %rdi      # 0x9004
leaq 0x5e56(%rip), %rsi      # 0x903e
movl $0x189, %edx            # imm = 0x189
leaq 0x622b(%rip), %rcx      # 0x941f
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edx
movq 0x10(%rax), %rcx
movl $0x2, %edi
movl $0x1, %esi
callq 0x4340
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3305
movq -0x10(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x32d8
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x4520
movq %rax, -0x30(%rbp)
jmp 0x326c
cmpq $0x0, -0x30(%rbp)
jne 0x32a0
jmp 0x3275
leaq 0x5d88(%rip), %rdi      # 0x9004
leaq 0x5dbb(%rip), %rsi      # 0x903e
movl $0x197, %edx            # imm = 0x197
leaq 0x6190(%rip), %rcx      # 0x941f
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %edx
movq 0x10(%rax), %rcx
movl $0xa, %edi
movl $0x1, %esi
callq 0x4340
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3305
jmp 0x32da
leaq 0x5d23(%rip), %rdi      # 0x9004
leaq 0x5d56(%rip), %rsi      # 0x903e
movl $0x19f, %edx            # imm = 0x19F
leaq 0x6161(%rip), %rcx      # 0x9455
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nop