// File: /workspace/github_cpp_makefile_star2_O3/johan-bjareholt[P]lua-compiler/src/convert.cc
// Function: outFunctionBlock(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, BBlock&, std::ostream&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
void outFunctionBlock(std::string funcname, BBlock& block, std::ostream& ss, std::set<std::string>& outputSymbols, std::set<std::string>& inputSymbols){
    //std::cout << "Translating function " << funcname << std::endl;
    addVar(funcname, VT_FUNCTION, "");
    
    varoffset = 0;
    localVars.clear();
    
    for(auto iter = block.instructions.begin(); iter->op=='a' && iter!=block.instructions.end(); iter++){
        ThreeAd& arg = *iter;
        localVars.insert(std::make_pair(arg.lhs, varoffset));
        varoffset+=8;
    }
    std::stringstream bodyss;
    std::string retlabel = outBlock(block, bodyss, outputSymbols, inputSymbols, false, true);
    
    ss << std::endl;
    ss << pre_in << funcname << ":" << post_in;
    
    // Push bp
    ss << pre_in << "pushq %%rbp" << post_in;
    // Set new bp
    ss << pre_in << "movq %%rsp, %%rbp" << post_in;
    // Allocate local var space
    ss << pre_in << "subq $" << varoffset << ", %%rsp" << post_in;

    // Insert body
    ss << bodyss.str();
    
    varoffset = 0;
    localVars.clear();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %r8, %r12
movq %rcx, -0x48(%rbp)
movq %rdx, %rbx
movq %rsi, %r13
leaq -0x98(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%rdi), %rsi
movq %rdi, -0x30(%rbp)
movq 0x8(%rdi), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %rdi
callq 0x4baa
leaq -0x78(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0xcdd8(%rip), %rdx      # 0x178dc
leaq -0x88(%rbp), %rdi
movq %rdx, %rsi
callq 0x8e3a
leaq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rdx
movl $0x3, %esi
callq 0x91f7
movq %r12, -0x40(%rbp)
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0xab40
callq 0x3230
movq %rbx, -0x38(%rbp)
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xab55
callq 0x3230
movl $0x0, 0x128b5(%rip)     # 0x1d414
leaq 0x128b2(%rip), %rdi     # 0x1d418
callq 0xd168
movq (%r13), %rbx
cmpq %r13, %rbx
je 0xabe6
cmpb $0x61, 0x10(%rbx)
jne 0xabe6
leaq -0x240(%rbp), %r14
leaq -0x250(%rbp), %r15
leaq 0x12889(%rip), %r12     # 0x1d418
movq %r14, -0x250(%rbp)
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x4baa
movl 0x12865(%rip), %eax     # 0x1d414
movl %eax, -0x230(%rbp)
movq %r12, %rdi
movq %r15, %rsi
callq 0xd1a0
movq -0x250(%rbp), %rdi
cmpq %r14, %rdi
je 0xabd1
callq 0x3230
addl $0x8, 0x1283c(%rip)     # 0x1d414
movq (%rbx), %rbx
cmpq %r13, %rbx
je 0xabe6
cmpb $0x61, 0x10(%rbx)
je 0xab8f
leaq -0x250(%rbp), %rdi
callq 0x31a0
leaq -0x240(%rbp), %rdx
movl $0x1, (%rsp)
leaq -0xc8(%rbp), %rdi
movq %r13, %rsi
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
xorl %r9d, %r9d
callq 0xa416
movq -0x38(%rbp), %rbx
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3180
movq 0x12754(%rip), %rsi     # 0x1d3a0
movq 0x12755(%rip), %rdx     # 0x1d3a8
movq %rbx, %rdi
callq 0x32b0
movq -0x30(%rbp), %rcx
movq (%rcx), %rsi
movq 0x8(%rcx), %rdx
movq %rax, %rdi
callq 0x32b0
movq %rax, %r14
leaq 0xa861(%rip), %rsi      # 0x154d9
movl $0x1, %edx
movq %rax, %rdi
callq 0x32b0
movq 0x12734(%rip), %rsi     # 0x1d3c0
movq 0x12735(%rip), %rdx     # 0x1d3c8
movq %r14, %rdi
callq 0x32b0
movq 0x126fe(%rip), %rsi     # 0x1d3a0
movq 0x126ff(%rip), %rdx     # 0x1d3a8
movq %rbx, %rdi
callq 0x32b0
movq %rax, %r14
leaq 0xa982(%rip), %rsi      # 0x1563d
movl $0xb, %edx
movq %rax, %rdi
callq 0x32b0
movq 0x126f1(%rip), %rsi     # 0x1d3c0
movq 0x126f2(%rip), %rdx     # 0x1d3c8
movq %r14, %rdi
callq 0x32b0
movq 0x126bb(%rip), %rsi     # 0x1d3a0
movq 0x126bc(%rip), %rdx     # 0x1d3a8
movq %rbx, %rdi
callq 0x32b0
movq %rax, %r14
leaq 0xa94b(%rip), %rsi      # 0x15649
movl $0x11, %edx
movq %rax, %rdi
callq 0x32b0
movq 0x126ae(%rip), %rsi     # 0x1d3c0
movq 0x126af(%rip), %rdx     # 0x1d3c8
movq %r14, %rdi
callq 0x32b0
movq 0x12678(%rip), %rsi     # 0x1d3a0
movq 0x12679(%rip), %rdx     # 0x1d3a8
movq %rbx, %rdi
callq 0x32b0
movq %rax, %r14
leaq 0xa91a(%rip), %rsi      # 0x1565b
movl $0x6, %edx
movq %rax, %rdi
callq 0x32b0
movl 0x126c0(%rip), %esi     # 0x1d414
movq %r14, %rdi
callq 0x3450
movq %rax, %r14
leaq 0xa8c0(%rip), %rsi      # 0x15626
movl $0x7, %edx
movq %rax, %rdi
callq 0x32b0
movq 0x12646(%rip), %rsi     # 0x1d3c0
movq 0x12647(%rip), %rdx     # 0x1d3c8
movq %r14, %rdi
callq 0x32b0
leaq -0x238(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x3400
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %rbx, %rdi
callq 0x32b0
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xadbb
callq 0x3230
movl $0x0, 0x1264f(%rip)     # 0x1d414
leaq 0x1264c(%rip), %rdi     # 0x1d418
callq 0xd168
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xade6
callq 0x3230
movq 0x121ab(%rip), %rsi     # 0x1cf98
leaq -0x250(%rbp), %rdi
callq 0x31c0
leaq -0x1d0(%rbp), %rdi
callq 0x30c0
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x58(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xae75
callq 0x3230
jmp 0xae75
jmp 0xae72
movq %rax, %rbx
jmp 0xae8a
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0xae4e
callq 0x3230
jmp 0xae4e
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
jne 0xae6b
jmp 0xaea9
movq %rax, %rbx
movq -0x250(%rbp), %rdi
cmpq %r14, %rdi
je 0xaea9
callq 0x3230
jmp 0xaea9
movq %rax, %rbx
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xae8a
callq 0x3230
movq 0x12107(%rip), %rsi     # 0x1cf98
leaq -0x250(%rbp), %rdi
callq 0x31c0
leaq -0x1d0(%rbp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x3470