// File: /workspace/github_cpp_makefile_star2_O2/SunriseFox[P]very-simple-c-compiler/./src/asm.cpp
// Function: generateASM()
void generateASM() {
    of.open("out.S");

    of << "\t.file\t\"" << "temp.c" << "\"\n";

    putLine(".text");

    TreeNode* temp = root;

    while (temp) {
        storeVar(temp);
        temp = temp -> sibling;
    }

    vector<pair<Symbol*, string>> constStr;

    for (const auto& i : varDeclare) {
        if (i.first->type != Symbol::VALUE_STRING) {
            int size = symbolSize(i.first);
            of << "\t.comm\t" << i.second << "," << size << "," << size << "\n";
        } else if (i.second.substr(0, 4) == ".str") {
            constStr.push_back(i);
        }
        cerr << i.first->value << " " << i.second << endl;
    }

    if(constStr.size() != 0) {
        of << "\t.section\t.rodata\n";
    }

    for (const auto& i : constStr) {
        of << i.second << ":\n";
        of << "\t.string\t\"" << i.first->value << "\"\n";
    }

    putLine(".text");

    handleCodeBlock(root);

    of << "\t.ident\t\"Vampire very-simple-c-compiler\"\n";
    of << "\t.section\t.note.GNU-stack,\"\",@progbits\n";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq 0xc434(%rip), %rbx      # 0x12268
leaq 0x5669(%rip), %rsi      # 0xb4a4
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x3040
leaq 0x565d(%rip), %rsi      # 0xb4aa
movq %rbx, %rdi
callq 0x31d0
leaq 0x5657(%rip), %rsi      # 0xb4b3
movq %rax, %rdi
callq 0x31d0
leaq 0x56a4(%rip), %rsi      # 0xb50f
movq %rax, %rdi
callq 0x31d0
leaq 0x5640(%rip), %rsi      # 0xb4ba
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x615c
leaq 0x30(%rsp), %rdi
callq 0x40fa
leaq 0x30(%rsp), %rdi
callq 0x30f0
leaq 0xc67c(%rip), %rbx      # 0x12520
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x5eba
movq %rbx, %rdi
callq 0x3ee8
addq $0x20, %rbx
jmp 0x5ea4
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0xc37f(%rip), %r15      # 0x12250
leaq 0x30(%rsp), %r12
leaq 0x57c3(%rip), %r14      # 0xb6a0
leaq 0x55e4(%rip), %r13      # 0xb4c8
leaq 0xc355(%rip), %rax      # 0x12240
cmpq %rax, %r15
je 0x5ffc
leaq 0x20(%r15), %rbp
movq 0x20(%r15), %rax
cmpl $0x4, (%rax)
jne 0x5f57
leaq 0x28(%r15), %rsi
movq %r12, %rdi
xorl %edx, %edx
pushq $0x4
popq %rcx
callq 0x3200
movq %r12, %rdi
leaq 0x53ca(%rip), %rsi      # 0xb2e6
callq 0x62e9
movl %eax, %ebx
movq %r12, %rdi
callq 0x30f0
testb %bl, %bl
je 0x5fb9
movq %r12, %rdi
movq %rbp, %rsi
callq 0x6316
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x6950
leaq 0x38(%rsp), %rdi
callq 0x30f0
jmp 0x5fb9
movq %rbp, %rdi
callq 0x412c
movl %eax, %ebx
leaq 0xc300(%rip), %rdi      # 0x12268
leaq 0x5551(%rip), %rsi      # 0xb4c0
callq 0x31d0
leaq 0x28(%r15), %rsi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x31d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x3370
movq %rax, %rdi
movq %r13, %rsi
callq 0x31d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x3370
movq %rax, %rdi
leaq 0x555c(%rip), %rsi      # 0xb510
callq 0x31d0
movq (%rbp), %rsi
addq $0x8, %rsi
movq 0xc028(%rip), %rdi      # 0x11ff0
callq 0x31c0
movq %rax, %rdi
movq %r14, %rsi
callq 0x31d0
leaq 0x28(%r15), %rsi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
callq 0x3100
movq %r15, %rdi
callq 0x3150
movq %rax, %r15
jmp 0x5ee4
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rbp
cmpq %rbx, %rbp
je 0x6028
leaq 0xc256(%rip), %rdi      # 0x12268
leaq 0x54b1(%rip), %rsi      # 0xb4ca
callq 0x31d0
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rbp
leaq 0xc239(%rip), %r14      # 0x12268
leaq 0x5382(%rip), %r15      # 0xb3b8
leaq 0x54a0(%rip), %r12      # 0xb4dd
leaq 0x54cb(%rip), %r13      # 0xb50f
cmpq %rbp, %rbx
je 0x608f
addq $0x8, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x31c0
movq %rax, %rdi
movq %r15, %rsi
callq 0x31d0
movq %r14, %rdi
movq %r12, %rsi
callq 0x31d0
movq -0x8(%rbx), %rsi
addq $0x8, %rsi
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
movq %r13, %rsi
callq 0x31d0
addq $0x20, %rbx
jmp 0x6044
leaq 0x5424(%rip), %rsi      # 0xb4ba
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x615c
leaq 0x30(%rsp), %rdi
callq 0x40fa
leaq 0x30(%rsp), %rdi
callq 0x30f0
leaq 0xc460(%rip), %rax      # 0x12520
movq (%rax), %rdi
callq 0x4144
leaq 0xc199(%rip), %rdi      # 0x12268
leaq 0x5412(%rip), %rsi      # 0xb4e8
callq 0x31d0
leaq 0xc186(%rip), %rdi      # 0x12268
leaq 0x5429(%rip), %rsi      # 0xb512
callq 0x31d0
leaq 0x10(%rsp), %rdi
callq 0x632a
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x6131
jmp 0x6140
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x30f0
jmp 0x614d
movq %rax, %rbx
jmp 0x614d
jmp 0x6140
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x30f0
jmp 0x6143
jmp 0x6140
jmp 0x6140
jmp 0x6140
jmp 0x6140
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x632a
movq %rbx, %rdi
callq 0x3390
nop