// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %rsi
leaq -0xa8(%rbp), %rdi
movq %rsi, -0x30(%rbp)
callq 0x32f0
leaq 0x931e(%rip), %rsi      # 0x12316
leaq -0x88(%rbp), %rdi
leaq -0x250(%rbp), %rdx
callq 0x30d0
movq %r12, -0x40(%rbp)
movq %r15, -0x48(%rbp)
movq %r14, -0x38(%rbp)
leaq -0xa8(%rbp), %rdi
pushq $0x3
popq %rsi
leaq -0x88(%rbp), %rdx
callq 0x8184
leaq -0x88(%rbp), %rdi
callq 0x3448
leaq -0xa8(%rbp), %rdi
callq 0x3448
andl $0x0, 0x13388(%rip)     # 0x1c3d4
leaq 0x13385(%rip), %r15     # 0x1c3d8
movq %r15, %rdi
callq 0xad82
leaq 0x13372(%rip), %r12     # 0x1c3d4
leaq -0x250(%rbp), %r14
movq %rbx, %r13
movq (%r13), %r13
cmpq %rbx, %r13
je 0x90a7
cmpb $0x61, 0x10(%r13)
jne 0x90a7
leaq 0x38(%r13), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0xaa3a
movq %r15, %rdi
movq %r14, %rsi
callq 0xadba
movq %r14, %rdi
callq 0x3448
addl $0x8, 0x1332f(%rip)     # 0x1c3d4
jmp 0x906c
leaq -0x250(%rbp), %rdi
callq 0x3180
leaq -0x240(%rbp), %rdx
movl $0x1, (%rsp)
leaq -0xc8(%rbp), %rdi
movq %rbx, %rsi
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
xorl %r9d, %r9d
callq 0x8b42
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x3100
leaq 0x13272(%rip), %rsi     # 0x1c360
movq %rbx, %rdi
callq 0x31d0
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x31d0
leaq 0x93b5(%rip), %rsi      # 0x124be
movq %rax, %rdi
callq 0x31f0
leaq 0x13268(%rip), %rsi     # 0x1c380
movq %rax, %rdi
callq 0x31d0
leaq 0x13239(%rip), %rsi     # 0x1c360
movq %rbx, %rdi
callq 0x31d0
leaq 0x94ec(%rip), %rsi      # 0x12622
movq %rax, %rdi
callq 0x31f0
leaq 0x1323b(%rip), %rsi     # 0x1c380
movq %rax, %rdi
callq 0x31d0
leaq 0x1320c(%rip), %rsi     # 0x1c360
movq %rbx, %rdi
callq 0x31d0
leaq 0x94cb(%rip), %rsi      # 0x1262e
movq %rax, %rdi
callq 0x31f0
leaq 0x1320e(%rip), %rsi     # 0x1c380
movq %rax, %rdi
callq 0x31d0
leaq 0x131df(%rip), %rsi     # 0x1c360
movq %rbx, %rdi
callq 0x31d0
leaq 0x94b0(%rip), %rsi      # 0x12640
movq %rax, %rdi
callq 0x31f0
movl 0x13236(%rip), %esi     # 0x1c3d4
movq %rax, %rdi
callq 0x33d0
leaq 0x945e(%rip), %rsi      # 0x1260b
movq %rax, %rdi
callq 0x31f0
leaq 0x131c4(%rip), %rsi     # 0x1c380
movq %rax, %rdi
callq 0x31d0
leaq -0x238(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x3380
leaq -0x68(%rbp), %rsi
movq %rbx, %rdi
callq 0x31d0
leaq -0x68(%rbp), %rdi
callq 0x3448
andl $0x0, 0x131e4(%rip)     # 0x1c3d4
leaq 0x131e1(%rip), %rdi     # 0x1c3d8
callq 0xad82
leaq -0xc8(%rbp), %rdi
callq 0x3448
leaq -0x250(%rbp), %rdi
callq 0x3190
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3448
jmp 0x925b
jmp 0x9258
movq %rax, %rbx
jmp 0x9267
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x3448
jmp 0x924f
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
jmp 0x927f
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
callq 0x3448
leaq -0x250(%rbp), %rdi
callq 0x3190
jmp 0x9284
movq %rax, %rbx
leaq -0x250(%rbp), %rdi
callq 0x3448
movq %rbx, %rdi
callq 0x33f0