// File: /workspace/github_cpp_makefile_star2_O1/johan-bjareholt[P]lua-compiler/src/ir.cc
// Function: convertFuncDef(Statement*, BBlock*)
void convertFuncDef(Statement* in, BBlock *current){
	std::string name = in->expressions.at(0)->name;
    //std::cout << "Defining function " << name << std::endl;
	Statement* args = in->children.at(0);
	Statement* body = in->children.at(1);
	BBlock* bodyBlock = new BBlock();
    BBlock* currblock = bodyBlock;
    // TODO: Fix support for multiple arguments
    if (args->expressions.size() > 0){
        Expression* exp1 = args->expressions.at(0);
        ThreeAd ta (name, 'a', exp1->name, exp1->name);
        bodyBlock->instructions.push_back(ta);
    }
	convertStatement(body, &currblock);

    funcdefs.insert(std::make_pair(name, bodyBlock));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq (%rdi), %rax
cmpq %rax, 0x8(%rdi)
je 0x75bc
movq %rdi, %rbx
movq (%rax), %rax
leaq -0x38(%rbp), %r12
movq %r12, -0x10(%r12)
movq 0x30(%rax), %rsi
movq 0x38(%rax), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x4baa
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rax, %rcx
je 0x75ce
cmpq $0x1, %rdx
jbe 0x75de
movq (%rax), %r15
movq 0x8(%rax), %r14
movl $0x48, %edi
callq 0x3260
movq %rax, %rbx
movq %rax, 0x8(%rax)
movq %rax, (%rax)
addq $0x38, %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
xorl %ecx, %ecx
movq %rcx, 0x20(%rbx)
movq %rax, 0x28(%rbx)
movq %rcx, 0x30(%rbx)
movb $0x0, 0x38(%rbx)
movq %rbx, -0x50(%rbp)
movq (%r15), %rax
cmpq %rax, 0x8(%r15)
je 0x7546
movq (%rax), %r12
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %rdi
callq 0x4baa
leaq -0xa0(%rbp), %r13
movq %r13, -0x10(%r13)
movq 0x30(%r12), %rsi
movq 0x38(%r12), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x4baa
leaq -0x80(%rbp), %r15
movq %r15, -0x10(%r15)
movq 0x30(%r12), %rsi
movq 0x38(%r12), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x4baa
leaq -0x118(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0xb0(%rbp), %rcx
leaq -0x90(%rbp), %r8
movl $0x61, %edx
callq 0x4c90
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x74c2
callq 0x3230
movq -0xb0(%rbp), %rdi
cmpq %r13, %rdi
leaq -0x60(%rbp), %r15
je 0x74d7
callq 0x3230
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
leaq -0x38(%rbp), %r12
je 0x74e9
callq 0x3230
leaq -0x118(%rbp), %rsi
movq %rbx, %rdi
callq 0x8b78
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
leaq -0xc0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x751c
callq 0x3230
leaq -0xe0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7531
callq 0x3230
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7546
callq 0x3230
leaq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0x7313
leaq -0x108(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x118(%rbp), %rdi
callq 0x4baa
leaq -0x118(%rbp), %rsi
movq %rbx, 0x20(%rsi)
leaq 0x17daa(%rip), %rdi     # 0x1f330
callq 0x8c7c
movq -0x118(%rbp), %rdi
cmpq %r14, %rdi
je 0x759c
callq 0x3230
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x75aa
callq 0x3230
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xebe9(%rip), %rdi      # 0x161ac
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x33d0
leaq 0xebd7(%rip), %rdi      # 0x161ac
xorl %esi, %esi
xorl %eax, %eax
callq 0x33d0
leaq 0xebc7(%rip), %rdi      # 0x161ac
movl $0x1, %esi
xorl %eax, %eax
callq 0x33d0
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x7d56
jmp 0x7663
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x761b
callq 0x3230
jmp 0x761b
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r13, %rdi
je 0x7631
callq 0x3230
jmp 0x7631
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
jne 0x7651
jmp 0x7663
jmp 0x7660
movq %rax, %rbx
movq -0x118(%rbp), %rdi
cmpq %r14, %rdi
je 0x7663
callq 0x3230
jmp 0x7663
jmp 0x7660
jmp 0x7660
jmp 0x7660
jmp 0x7660
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x7675
callq 0x3230
movq %rbx, %rdi
callq 0x3470