// File: /workspace/github_cpp_makefile_star2_O1/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 0xddb4(%rip), %rdx      # 0x188fc
leaq -0x88(%rbp), %rdi
movq %rdx, %rsi
callq 0x8e78
leaq -0xa8(%rbp), %rdi
leaq -0x88(%rbp), %rdx
movl $0x3, %esi
callq 0x9233
movq %r12, -0x40(%rbp)
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0xab84
callq 0x3230
movq %rbx, -0x38(%rbp)
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
je 0xab99
callq 0x3230
movl $0x0, 0x14871(%rip)     # 0x1f414
leaq 0x1486e(%rip), %rdi     # 0x1f418
callq 0xd1ba
movq (%r13), %rbx
cmpq %r13, %rbx
je 0xac2a
cmpb $0x61, 0x10(%rbx)
jne 0xac2a
leaq -0x240(%rbp), %r14
leaq -0x250(%rbp), %r15
leaq 0x14845(%rip), %r12     # 0x1f418
movq %r14, -0x250(%rbp)
movq 0x38(%rbx), %rsi
movq 0x40(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x4baa
movl 0x14821(%rip), %eax     # 0x1f414
movl %eax, -0x230(%rbp)
movq %r12, %rdi
movq %r15, %rsi
callq 0xd1f2
movq -0x250(%rbp), %rdi
cmpq %r14, %rdi
je 0xac15
callq 0x3230
addl $0x8, 0x147f8(%rip)     # 0x1f414
movq (%rbx), %rbx
cmpq %r13, %rbx
je 0xac2a
cmpb $0x61, 0x10(%rbx)
je 0xabd3
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 0xa45a
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 0x14710(%rip), %rsi     # 0x1f3a0
movq 0x14711(%rip), %rdx     # 0x1f3a8
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 0xb81d(%rip), %rsi      # 0x164d9
movl $0x1, %edx
movq %rax, %rdi
callq 0x32b0
movq 0x146f0(%rip), %rsi     # 0x1f3c0
movq 0x146f1(%rip), %rdx     # 0x1f3c8
movq %r14, %rdi
callq 0x32b0
movq 0x146ba(%rip), %rsi     # 0x1f3a0
movq 0x146bb(%rip), %rdx     # 0x1f3a8
movq %rbx, %rdi
callq 0x32b0
movq %rax, %r14
leaq 0xb93e(%rip), %rsi      # 0x1663d
movl $0xb, %edx
movq %rax, %rdi
callq 0x32b0
movq 0x146ad(%rip), %rsi     # 0x1f3c0
movq 0x146ae(%rip), %rdx     # 0x1f3c8
movq %r14, %rdi
callq 0x32b0
movq 0x14677(%rip), %rsi     # 0x1f3a0
movq 0x14678(%rip), %rdx     # 0x1f3a8
movq %rbx, %rdi
callq 0x32b0
movq %rax, %r14
leaq 0xb907(%rip), %rsi      # 0x16649
movl $0x11, %edx
movq %rax, %rdi
callq 0x32b0
movq 0x1466a(%rip), %rsi     # 0x1f3c0
movq 0x1466b(%rip), %rdx     # 0x1f3c8
movq %r14, %rdi
callq 0x32b0
movq 0x14634(%rip), %rsi     # 0x1f3a0
movq 0x14635(%rip), %rdx     # 0x1f3a8
movq %rbx, %rdi
callq 0x32b0
movq %rax, %r14
leaq 0xb8d6(%rip), %rsi      # 0x1665b
movl $0x6, %edx
movq %rax, %rdi
callq 0x32b0
movl 0x1467c(%rip), %esi     # 0x1f414
movq %r14, %rdi
callq 0x3450
movq %rax, %r14
leaq 0xb87c(%rip), %rsi      # 0x16626
movl $0x7, %edx
movq %rax, %rdi
callq 0x32b0
movq 0x14602(%rip), %rsi     # 0x1f3c0
movq 0x14603(%rip), %rdx     # 0x1f3c8
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 0xadff
callq 0x3230
movl $0x0, 0x1460b(%rip)     # 0x1f414
leaq 0x14608(%rip), %rdi     # 0x1f418
callq 0xd1ba
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xae2a
callq 0x3230
movq 0x14167(%rip), %rsi     # 0x1ef98
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 0xaeb9
callq 0x3230
jmp 0xaeb9
jmp 0xaeb6
movq %rax, %rbx
jmp 0xaece
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0xae92
callq 0x3230
jmp 0xae92
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
cmpq %r15, %rdi
jne 0xaeaf
jmp 0xaeed
movq %rax, %rbx
movq -0x250(%rbp), %rdi
cmpq %r14, %rdi
je 0xaeed
callq 0x3230
jmp 0xaeed
movq %rax, %rbx
leaq -0xb8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaece
callq 0x3230
movq 0x140c3(%rip), %rsi     # 0x1ef98
leaq -0x250(%rbp), %rdi
callq 0x31c0
leaq -0x1d0(%rbp), %rdi
callq 0x30c0
movq %rbx, %rdi
callq 0x3470