// File: /workspace/github_c_makefile_star2_O0/johnvtan[P]ccccc/asm.c
// Function: binop_to_instrs
static list_t *binop_to_instrs(bin_expr_t *bin, env_t *env) {
    if (!bin) {
        UNREACHABLE("binop_to_instrs: bin is null wtf are you doing\n");
    }

    list_t *ret = expr_to_instrs(bin->lhs, env);
    if (!ret) {
        UNREACHABLE("binop_to_instrs: failed to generate lhs\n");
    }

    // AND and OR short circuit, so we don't want to evaluate the RHS if we're not certain we need
    // to.
    debug("Found bin op expr\n");
    if (bin->op == BIN_OR) {
        string_t *or_clause_2 = unique_label("second_or_clause");
        string_t *end = unique_label("or_end");

        list_push(ret, instr_i2r(OP_CMP, 0, REG_RAX));
        list_push(ret, instr_label(OP_JE, or_clause_2));
        list_push(ret, instr_i2r(OP_MOV, 1, REG_RAX));
        list_push(ret, instr_label(OP_JMP, end));
        list_push(ret, new_label(or_clause_2, LABEL_STATIC));

        list_concat(ret, expr_to_instrs(bin->rhs, env));

        list_push(ret, new_label(end, LABEL_STATIC));
        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_SETNE, REG_AL));
        return ret;
    }

    if (bin->op == BIN_AND) {
        string_t *and_clause_2 = unique_label("second_and_clause");
        string_t *end = unique_label("and_end");
        list_push(ret, instr_i2r(OP_CMP, 0, REG_RAX));
        list_push(ret, instr_label(OP_JNE, and_clause_2));
        list_push(ret, instr_label(OP_JMP, end));
        list_push(ret, new_label(and_clause_2, LABEL_STATIC));
        list_concat(ret, expr_to_instrs(bin->rhs, env));
        list_push(ret, new_label(end, LABEL_STATIC));
        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_SETNE, REG_AL));
        return ret;
    }

    list_push(ret, instr_r(OP_PUSH, REG_RAX));
    list_concat(ret, expr_to_instrs(bin->rhs, env));
    list_push(ret, instr_r(OP_POP, REG_RCX));

    if (bin->op == BIN_ADD) {
        list_push(ret, instr_r2r(OP_ADD, REG_RCX, REG_RAX));
        return ret;
    }

    if (bin->op == BIN_SUB) {
        // sub src, dst computes dst - src
        // so we want to compute e1 - e2, and e1 is in rcx
        // so we'll do rcx - rax, then move rcx into rax
        list_push(ret, instr_r2r(OP_SUB, REG_RAX, REG_RCX));
        list_push(ret, instr_r2r(OP_MOV, REG_RCX, REG_RAX));
        return ret;
    }

    if (bin->op == BIN_MUL) {
        list_push(ret, instr_r2r(OP_MUL, REG_RCX, REG_RAX));
        return ret;
    }

    if (bin->op == BIN_DIV) {
        list_push(ret, instr_r2r(OP_XCHG, REG_RAX, REG_RCX));
        list_push(ret, instr_noarg(OP_CQO));
        list_push(ret, instr_r(OP_DIV, REG_RCX));
        return ret;
    } 

    if (bin->op == BIN_MODULO) {
        // idivq puts quotient in RAX, remainder in RDX
        list_push(ret, instr_r2r(OP_XCHG, REG_RAX, REG_RCX));
        list_push(ret, instr_noarg(OP_CQO));
        list_push(ret, instr_r(OP_DIV, REG_RCX));
        list_push(ret, instr_r2r(OP_MOV, REG_RDX, REG_RAX));
        return ret;
    }

    if (bin->op == BIN_EQ) {
        list_push(ret, instr_r2r(OP_CMP, REG_RAX, REG_RCX));
        list_push(ret, instr_i2r(OP_MOV, 0, REG_RAX));
        list_push(ret, instr_r(OP_SETE, REG_AL));
        return ret;
    }

    if (bin->op == BIN_NE) {
        list_push(ret, instr_r2r(OP_CMP, REG_RAX, REG_RCX));
        list_push(ret, instr_i2r(OP_MOV, 0, REG_RAX));
        list_push(ret, instr_r(OP_SETNE, REG_AL));
        return ret;
    }

    if (bin->op == BIN_LT) {
        list_push(ret, instr_r2r(OP_CMP, REG_RAX, REG_RCX));
        list_push(ret, instr_i2r(OP_MOV, 0, REG_RAX));
        list_push(ret, instr_r(OP_SETL, REG_AL));
        return ret;
    }

    if (bin->op == BIN_LTE) {
        list_push(ret, instr_r2r(OP_CMP, REG_RAX, REG_RCX));
        list_push(ret, instr_i2r(OP_MOV, 0, REG_RAX));
        list_push(ret, instr_r(OP_SETLE, REG_AL));
        return ret;
    }

    if (bin->op == BIN_GT) {
        list_push(ret, instr_r2r(OP_CMP, REG_RAX, REG_RCX));
        list_push(ret, instr_i2r(OP_MOV, 0, REG_RAX));
        list_push(ret, instr_r(OP_SETG, REG_AL));
        return ret;
    }

    if (bin->op == BIN_GTE) {
        list_push(ret, instr_r2r(OP_CMP, REG_RAX, REG_RCX));
        list_push(ret, instr_i2r(OP_MOV, 0, REG_RAX));
        list_push(ret, instr_r(OP_SETGE, REG_AL));
        return ret;
    }
    UNREACHABLE("Unknown binary op\n");
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3357
jmp 0x332c
leaq 0x5cd1(%rip), %rdi      # 0x9004
leaq 0x5d04(%rip), %rsi      # 0x903e
movl $0x1a5, %edx            # imm = 0x1A5
leaq 0x6126(%rip), %rcx      # 0x946c
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x2a50
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x33a0
jmp 0x3375
leaq 0x5c88(%rip), %rdi      # 0x9004
leaq 0x5cbb(%rip), %rsi      # 0x903e
movl $0x1aa, %edx            # imm = 0x1AA
leaq 0x610d(%rip), %rcx      # 0x949c
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
jmp 0x33a2
jmp 0x33a4
movq -0x10(%rbp), %rax
cmpl $0xb, (%rax)
jne 0x354b
leaq 0x610d(%rip), %rdi      # 0x94c5
callq 0x1830
movq %rax, -0x28(%rbp)
leaq 0x610e(%rip), %rdi      # 0x94d6
callq 0x1830
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
movl $0x4, %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x2810
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rsi
movl $0x15, %edi
callq 0x2b90
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movl $0x1, %edx
movl $0x1, %esi
movl %edx, %edi
callq 0x2810
movq -0x80(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rsi
movl $0x14, %edi
callq 0x2b90
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x1660
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x2a50
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x4740
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x1660
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x4, %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x2810
movq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %esi
movl %edx, %edi
callq 0x2810
movq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0xf, %edi
movl $0x11, %esi
callq 0x2650
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0xa, (%rax)
jne 0x36f7
leaq 0x5f7e(%rip), %rdi      # 0x94dd
callq 0x1830
movq %rax, -0x38(%rbp)
leaq 0x5f80(%rip), %rdi      # 0x94ef
callq 0x1830
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl $0x4, %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x2810
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rsi
movl $0x16, %edi
callq 0x2b90
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x40(%rbp), %rsi
movl $0x14, %edi
callq 0x2b90
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x1660
movq -0xc0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x2a50
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
callq 0x4740
movq -0x20(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x1660
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl $0x4, %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x2810
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %esi
movl %edx, %edi
callq 0x2810
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0xf, %edi
movl $0x11, %esi
callq 0x2650
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x20(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl $0x8, %edi
movl $0x1, %esi
callq 0x2650
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x2a50
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
callq 0x4740
movq -0x20(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl $0x9, %edi
movl $0x3, %esi
callq 0x2650
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x37b8
movq -0x20(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl $0x2, %edi
movl $0x3, %esi
movl $0x1, %edx
callq 0x2720
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x3827
movq -0x20(%rbp), %rax
movq %rax, -0x108(%rbp)
movl $0xa, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x2720
movq -0x108(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x100(%rbp)
movl $0x1, %edx
movl $0x3, %esi
movl %edx, %edi
callq 0x2720
movq -0x100(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x386b
movq -0x20(%rbp), %rax
movq %rax, -0x110(%rbp)
movl $0xb, %edi
movl $0x3, %esi
movl $0x1, %edx
callq 0x2720
movq -0x110(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x3900
movq -0x20(%rbp), %rax
movq %rax, -0x128(%rbp)
movl $0xd, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x2720
movq -0x128(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x120(%rbp)
movl $0xe, %edi
callq 0x2590
movq -0x120(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x118(%rbp)
movl $0xc, %edi
movl $0x3, %esi
callq 0x2650
movq -0x118(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0xc, (%rax)
jne 0x39c0
movq -0x20(%rbp), %rax
movq %rax, -0x148(%rbp)
movl $0xd, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x2720
movq -0x148(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x140(%rbp)
movl $0xe, %edi
callq 0x2590
movq -0x140(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x138(%rbp)
movl $0xc, %edi
movl $0x3, %esi
callq 0x2650
movq -0x138(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x130(%rbp)
movl $0x1, %edx
movl $0x4, %esi
movl %edx, %edi
callq 0x2720
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0x8, (%rax)
jne 0x3a5b
movq -0x20(%rbp), %rax
movq %rax, -0x160(%rbp)
movl $0x4, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x2720
movq -0x160(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x158(%rbp)
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %esi
movl %edx, %edi
callq 0x2810
movq -0x158(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x150(%rbp)
movl $0x5, %edi
movl $0x11, %esi
callq 0x2650
movq -0x150(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0x9, (%rax)
jne 0x3af6
movq -0x20(%rbp), %rax
movq %rax, -0x178(%rbp)
movl $0x4, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x2720
movq -0x178(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x170(%rbp)
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %esi
movl %edx, %edi
callq 0x2810
movq -0x170(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x168(%rbp)
movl $0xf, %edi
movl $0x11, %esi
callq 0x2650
movq -0x168(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x3b91
movq -0x20(%rbp), %rax
movq %rax, -0x190(%rbp)
movl $0x4, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x2720
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x188(%rbp)
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %esi
movl %edx, %edi
callq 0x2810
movq -0x188(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x180(%rbp)
movl $0x10, %edi
movl $0x11, %esi
callq 0x2650
movq -0x180(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x3c29
movq -0x20(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movl $0x4, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x2720
movq -0x1a8(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %esi
movl %edx, %edi
callq 0x2810
movq -0x1a0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x198(%rbp)
movl $0x11, %esi
movl %esi, %edi
callq 0x2650
movq -0x198(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x3cc4
movq -0x20(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movl $0x4, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x2720
movq -0x1c0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %esi
movl %edx, %edi
callq 0x2810
movq -0x1b8(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movl $0x12, %edi
movl $0x11, %esi
callq 0x2650
movq -0x1b0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
movq -0x10(%rbp), %rax
cmpl $0x7, (%rax)
jne 0x3d5c
movq -0x20(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movl $0x4, %edi
movl $0x1, %esi
movl $0x3, %edx
callq 0x2720
movq -0x1d8(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %esi
movl %edx, %edi
callq 0x2810
movq -0x1d0(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movl $0x13, %edi
movl $0x11, %esi
callq 0x2650
movq -0x1c8(%rbp), %rdi
movq %rax, %rsi
callq 0x46a0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d89
jmp 0x3d5e
leaq 0x529f(%rip), %rdi      # 0x9004
leaq 0x52d2(%rip), %rsi      # 0x903e
movl $0x222, %edx            # imm = 0x222
leaq 0x577f(%rip), %rcx      # 0x94f7
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
movq -0x8(%rbp), %rax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
nopw %cs:(%rax,%rax)