// File: fondoger[P]C0-Compiler/src/mips.cpp
// Function: gen_ADD_SUB_MUL_DIV(_FourTuple const&)
static void gen_ADD_SUB_MUL_DIV(const FourTuple &ft)
{
    int ignored;

    /* use pseudo instructions here */
    std::string op = (ft.op == ADD ? "addu" :
            ft.op == SUB ? "subu" : 
            ft.op == MUL ? "mul" :
            ft.op == DIV ? "div" : "FUCK");
    // can't be both const value
    assert(!(isConstValue(ft.a, ignored) && isConstValue(ft.b, ignored)));


    loadToReg("$v0", ft.a);
    std::string operand1 = "$v0";
    std::string operand2 = "$v1";
    if (isConstValue(ft.b, ignored)) {
        operand2 = std::to_string(ignored);
    } else {
        loadToReg("$v1", ft.b);
    }

    // result is always stored into $v0
    MIPS(T << op << HT << "$v0, " << operand1 << ", " << operand2);
    // write result back
    MIPS(T << "sw" << HT << "$v0, " << getVariableAddr(ft.res));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x2a3b8
leaq 0xbcbf(%rip), %rax      # 0x3606e
movq %rax, -0x130(%rbp)
jmp 0x2a428
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2a3d1
leaq 0xbcab(%rip), %rax      # 0x36073
movq %rax, -0x138(%rbp)
jmp 0x2a41a
movq -0x8(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x2a3ea
leaq 0xbc97(%rip), %rax      # 0x36078
movq %rax, -0x140(%rbp)
jmp 0x2a40c
movq -0x8(%rbp), %rax
movl (%rax), %edx
leaq 0xbc89(%rip), %rax      # 0x36080
leaq 0xbc7e(%rip), %rcx      # 0x3607c
cmpl $0x4, %edx
cmoveq %rcx, %rax
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x3570
movq -0x150(%rbp), %rsi
movq -0x148(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x3440
jmp 0x2a45f
leaq -0x31(%rbp), %rdi
callq 0x3370
movq -0x8(%rbp), %rdi
addq $0x8, %rdi
leaq -0xc(%rbp), %rsi
callq 0x27780
movb %al, -0x151(%rbp)
jmp 0x2a481
movb -0x151(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x152(%rbp)
jne 0x2a496
jmp 0x2a4bd
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
leaq -0xc(%rbp), %rsi
callq 0x27780
movb %al, -0x153(%rbp)
jmp 0x2a4af
movb -0x153(%rbp), %al
movb %al, -0x152(%rbp)
jmp 0x2a4bd
movb -0x152(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2a4cb
jmp 0x2a4cd
jmp 0x2a517
leaq 0xbbb1(%rip), %rdi      # 0x36085
leaq 0xbab5(%rip), %rsi      # 0x35f90
movl $0x15c, %edx            # imm = 0x15C
leaq 0xbbdc(%rip), %rcx      # 0x360c3
callq 0x3230
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x3370
jmp 0x2a900
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2a8f7
leaq -0x69(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x3570
movq -0x160(%rbp), %rdx
leaq 0xbbba(%rip), %rsi      # 0x360ef
leaq -0x68(%rbp), %rdi
callq 0x3440
jmp 0x2a540
movq -0x8(%rbp), %rsi
addq $0x8, %rsi
leaq -0x68(%rbp), %rdi
callq 0x2cf90
jmp 0x2a553
leaq -0x68(%rbp), %rdi
callq 0x35e8
leaq -0x69(%rbp), %rdi
callq 0x3370
leaq -0x91(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x3570
movq -0x168(%rbp), %rdx
leaq 0xbb69(%rip), %rsi      # 0x360ef
leaq -0x90(%rbp), %rdi
callq 0x3440
jmp 0x2a594
leaq -0x91(%rbp), %rdi
callq 0x3370
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x3570
movq -0x170(%rbp), %rdx
leaq 0xbb32(%rip), %rsi      # 0x360f3
leaq -0xb8(%rbp), %rdi
callq 0x3440
jmp 0x2a5cf
leaq -0xb9(%rbp), %rdi
callq 0x3370
movq -0x8(%rbp), %rdi
addq $0x28, %rdi
leaq -0xc(%rbp), %rsi
callq 0x27780
movb %al, -0x171(%rbp)
jmp 0x2a5f4
movb -0x171(%rbp), %al
testb $0x1, %al
jne 0x2a603
jmp 0x2a6b4
movl -0xc(%rbp), %esi
leaq -0xe0(%rbp), %rdi
callq 0x22950
jmp 0x2a614
leaq -0xb8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x33d0
leaq -0xe0(%rbp), %rdi
callq 0x35e8
jmp 0x2a74a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2a65b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x35e8
leaq -0x69(%rbp), %rdi
callq 0x3370
jmp 0x2a8f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x3370
jmp 0x2a8f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb9(%rbp), %rdi
callq 0x3370
jmp 0x2a8eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2a8df
leaq -0x101(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x3570
movq -0x180(%rbp), %rdx
leaq 0xba1e(%rip), %rsi      # 0x360f3
leaq -0x100(%rbp), %rdi
callq 0x3440
jmp 0x2a6e3
movq -0x8(%rbp), %rsi
addq $0x28, %rsi
leaq -0x100(%rbp), %rdi
callq 0x2cf90
jmp 0x2a6f9
leaq -0x100(%rbp), %rdi
callq 0x35e8
leaq -0x101(%rbp), %rdi
callq 0x3370
jmp 0x2a74a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2a739
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x35e8
leaq -0x101(%rbp), %rdi
callq 0x3370
jmp 0x2a8df
leaq 0x1feef(%rip), %rdi     # 0x4a640
leaq -0x30(%rbp), %rsi
callq 0x32c0
movq %rax, -0x188(%rbp)
jmp 0x2a763
movq -0x188(%rbp), %rdi
leaq 0xb883(%rip), %rsi      # 0x35ff4
callq 0x3300
movq %rax, -0x190(%rbp)
jmp 0x2a77f
movq -0x190(%rbp), %rdi
leaq 0xb883(%rip), %rsi      # 0x36010
callq 0x3300
movq %rax, -0x198(%rbp)
jmp 0x2a79b
movq -0x198(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x32c0
movq %rax, -0x1a0(%rbp)
jmp 0x2a7b7
movq -0x1a0(%rbp), %rdi
leaq 0xbad1(%rip), %rsi      # 0x36296
callq 0x3300
movq %rax, -0x1a8(%rbp)
jmp 0x2a7d3
movq -0x1a8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x32c0
movq %rax, -0x1b0(%rbp)
jmp 0x2a7ef
movq -0x1b0(%rbp), %rdi
callq 0x29270
jmp 0x2a7fd
leaq 0x1fe3c(%rip), %rdi     # 0x4a640
leaq 0xb7aa(%rip), %rsi      # 0x35fb5
callq 0x3300
movq %rax, -0x1b8(%rbp)
jmp 0x2a819
movq -0x1b8(%rbp), %rdi
leaq 0xb7cd(%rip), %rsi      # 0x35ff4
callq 0x3300
movq %rax, -0x1c0(%rbp)
jmp 0x2a835
movq -0x1c0(%rbp), %rdi
leaq 0xb7cd(%rip), %rsi      # 0x36010
callq 0x3300
movq %rax, -0x1c8(%rbp)
jmp 0x2a851
movq -0x8(%rbp), %rsi
addq $0x48, %rsi
leaq -0x128(%rbp), %rdi
callq 0x2d120
jmp 0x2a867
movq -0x1c8(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x32c0
movq %rax, -0x1d0(%rbp)
jmp 0x2a883
movq -0x1d0(%rbp), %rdi
callq 0x29270
jmp 0x2a891
leaq -0x128(%rbp), %rdi
callq 0x35e8
leaq -0xb8(%rbp), %rdi
callq 0x35e8
leaq -0x90(%rbp), %rdi
callq 0x35e8
leaq -0x30(%rbp), %rdi
callq 0x35e8
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x35e8
leaq -0xb8(%rbp), %rdi
callq 0x35e8
leaq -0x90(%rbp), %rdi
callq 0x35e8
leaq -0x30(%rbp), %rdi
callq 0x35e8
movq -0x40(%rbp), %rdi
callq 0x3560
nopl (%rax)