// File: /workspace/github_cpp_makefile_star2_O3/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 0x7585
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 0x7597
cmpq $0x1, %rdx
jbe 0x75a7
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 0x750f
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 0x4c94
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x748b
callq 0x3230
movq -0xb0(%rbp), %rdi
cmpq %r13, %rdi
leaq -0x60(%rbp), %r15
je 0x74a0
callq 0x3230
movq -0x70(%rbp), %rdi
cmpq %r15, %rdi
leaq -0x38(%rbp), %r12
je 0x74b2
callq 0x3230
leaq -0x118(%rbp), %rsi
movq %rbx, %rdi
callq 0x8b44
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
leaq -0xc0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x74e5
callq 0x3230
leaq -0xe0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x74fa
callq 0x3230
leaq -0x100(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x750f
callq 0x3230
leaq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0x72dc
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 0x15de1(%rip), %rdi     # 0x1d330
callq 0x8c48
movq -0x118(%rbp), %rdi
cmpq %r14, %rdi
je 0x7565
callq 0x3230
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x7573
callq 0x3230
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdc20(%rip), %rdi      # 0x151ac
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x33d0
leaq 0xdc0e(%rip), %rdi      # 0x151ac
xorl %esi, %esi
xorl %eax, %eax
callq 0x33d0
leaq 0xdbfe(%rip), %rdi      # 0x151ac
movl $0x1, %esi
xorl %eax, %eax
callq 0x33d0
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x7d26
jmp 0x762c
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x75e4
callq 0x3230
jmp 0x75e4
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r13, %rdi
je 0x75fa
callq 0x3230
jmp 0x75fa
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
jne 0x761a
jmp 0x762c
jmp 0x7629
movq %rax, %rbx
movq -0x118(%rbp), %rdi
cmpq %r14, %rdi
je 0x762c
callq 0x3230
jmp 0x762c
jmp 0x7629
jmp 0x7629
jmp 0x7629
jmp 0x7629
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x763e
callq 0x3230
movq %rbx, %rdi
callq 0x3470