// File: /workspace/github_cpp_makefile_star2_O2/RuiDGPires[P]CrimLang/src/semantic_analiser.cpp
// Function: sc_Tracker::func_declaration(crl::Node*)
void _sc_Tracker::func_declaration(crl::Node *node){
	this->func_returns = false;
	Context::Item item;
	item.type = Context::Item::Type::FUNC;
	item.subtype = ((crl::Leaf *)node->get_child(0))->token.str;
	item.name = ((crl::Leaf *)node->get_child(1))->token.str;
	ASSERT(item.name != "_start", "_start is a reserved name");

	// Parse once to add to the args to the declaration
	int i;
	for (i = 2; node->get_child(i)->type == crl::Node::Type::ARG; i++){
		crl::Node *arg = node->get_child(i);
		std::string var_type = ((crl::Leaf *) arg->get_child(0))->token.str;

		item.args.push_back(std::pair<std::string, bool>(var_type, arg->annotation == "mut"));
	}

	node->argc = i - 2; // Store the number of arguments

	this->add(item);

	this->enter();
	// Add args to the function context
	i = 2;
	for (; node->get_child(i)->type == crl::Node::Type::ARG; i++){
		crl::Node *arg = node->get_child(i);
		Context::Item arg_item;
		arg_item.type = Context::Item::Type::VAR;
		arg_item.subtype = ((crl::Leaf *) arg->get_child(0))->token.str;
		arg_item.name = ((crl::Leaf *) arg->get_child(1))->token.str;
		arg_item._mutable = arg->annotation == "mut";
		this->add(arg_item);
	}
	this->block(node->get_child(i), item.subtype);
	
	ASSERT(func_returns, "Functions must return on all possible paths");
	this->leave();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
xorl %eax, %eax
movq %rdi, -0x30(%rbp)
movb %al, 0x10(%rdi)
leaq -0x158(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movq %rsi, %r14
movb %al, (%rcx)
leaq -0x138(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %al, (%rcx)
movb %al, 0x10(%rcx)
andl $0x0, 0x14(%rcx)
movb %al, 0x18(%rcx)
andq $0x0, 0x30(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rcx)
movl $0x1, -0x38(%rcx)
movq (%rsi), %rax
movq %rsi, %rdi
xorl %esi, %esi
callq *0x18(%rax)
leaq -0x148(%rbp), %rdi
addq $0x58, %rax
movq %rax, %rsi
callq 0x3160
movq (%r14), %rax
pushq $0x1
popq %rsi
movq %r14, %rdi
callq *0x18(%rax)
leaq -0x168(%rbp), %rbx
addq $0x58, %rax
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3160
leaq 0x5ff2(%rip), %rsi      # 0x158e6
movq %rbx, %rdi
callq 0x3c1f
testb %al, %al
je 0xfb5c
xorl %r12d, %r12d
leaq -0x190(%rbp), %r15
leaq -0xa0(%rbp), %r13
leal 0x2(%r12), %ebx
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
callq *0x18(%rax)
cmpl $0x12, 0x8(%rax)
jne 0xf99d
movq (%r14), %rax
movq %r14, %rdi
movl %ebx, %esi
callq *0x18(%rax)
movq %rax, %rbx
movq (%rax), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x18(%rax)
addq $0x58, %rax
movq %r15, %rdi
movq %rax, %rsi
callq 0x32f0
addq $0x30, %rbx
movq %rbx, %rdi
leaq 0x5aef(%rip), %rsi      # 0x15450
callq 0x410a
movl %eax, %ebx
movq %r13, %rdi
movq %r15, %rsi
callq 0x32f0
movb %bl, -0x80(%rbp)
leaq -0x118(%rbp), %rdi
movq %r13, %rsi
callq 0x12f22
movq %r13, %rdi
callq 0x3110
movq %r15, %rdi
callq 0x3110
incl %r12d
jmp 0xf915
movl %r12d, 0x50(%r14)
leaq -0x200(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x4444
leaq -0x200(%rbp), %rsi
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0xf562
leaq -0x200(%rbp), %rdi
callq 0x44c8
movq %rbx, %rdi
callq 0xf4f8
pushq $0x2
popq %r12
xorl %r13d, %r13d
leaq -0x270(%rbp), %rbx
movq (%r14), %rax
movq %r14, %rdi
movl %r12d, %esi
callq *0x18(%rax)
cmpl $0x12, 0x8(%rax)
movq (%r14), %rax
movq 0x18(%rax), %rax
jne 0xfaef
movq %r14, %rdi
movl %r12d, %esi
callq *%rax
movq %rax, %r15
leaq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
andq $0x0, -0x90(%rbp)
movb %r13b, -0x88(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
andq $0x0, -0x70(%rbp)
movb %r13b, -0x68(%rbp)
movb %r13b, -0x58(%rbp)
andl $0x0, -0x54(%rbp)
movb %r13b, -0x50(%rbp)
leaq -0x98(%rbp), %rax
andq $0x0, 0x60(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rax)
movl $0x3, -0xa0(%rbp)
movq (%r15), %rax
movq %r15, %rdi
xorl %esi, %esi
callq *0x18(%rax)
addq $0x58, %rax
leaq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x3160
movq (%r15), %rax
movq %r15, %rdi
pushq $0x1
popq %rsi
callq *0x18(%rax)
addq $0x58, %rax
leaq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x3160
addq $0x30, %r15
movq %r15, %rdi
leaq 0x59a0(%rip), %rsi      # 0x15450
callq 0x410a
movb %al, -0x50(%rbp)
movq %rbx, %rdi
leaq -0xa0(%rbp), %rsi
callq 0x4444
movq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0xf562
movq %rbx, %rdi
callq 0x44c8
leaq -0xa0(%rbp), %rdi
callq 0x44c8
incl %r12d
jmp 0xf9e9
movq %r14, %rdi
movl %r12d, %esi
callq *%rax
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x32f0
leaq -0xc0(%rbp), %rdx
movq -0x30(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xfcb8
leaq -0xc0(%rbp), %rdi
callq 0x3110
cmpb $0x0, 0x10(%r14)
je 0xfbb3
movq %r14, %rdi
callq 0xf538
leaq -0x170(%rbp), %rdi
callq 0x44c8
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x50
popq %rdi
callq 0x3140
movq %rax, %r14
leaq 0x5d7f(%rip), %rsi      # 0x158ed
leaq -0x100(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x3be4
movb $0x1, %r15b
pushq $-0x1
popq %rdx
leaq -0x100(%rbp), %rcx
movq %r14, %rdi
movl %edx, %esi
callq 0x4e88
xorl %r15d, %r15d
leaq 0xe1ee(%rip), %rsi      # 0x1dd90
leaq -0xac71(%rip), %rdx     # 0x4f38
movq %r14, %rdi
callq 0x33f0
jmp 0xfc08
pushq $0x50
popq %rdi
callq 0x3140
movq %rax, %r14
leaq 0x5d42(%rip), %rsi      # 0x15907
leaq -0xe0(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x3be4
movb $0x1, %r15b
pushq $-0x1
popq %rdx
leaq -0xe0(%rbp), %rcx
movq %r14, %rdi
movl %edx, %esi
callq 0x4e88
xorl %r15d, %r15d
leaq 0xe197(%rip), %rsi      # 0x1dd90
leaq -0xacc8(%rip), %rdx     # 0x4f38
movq %r14, %rdi
callq 0x33f0
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
jmp 0xfc20
jmp 0xfc2c
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x3110
testb %r15b, %r15b
jne 0xfc2f
jmp 0xfca4
movq %rax, %rbx
movq %r14, %rdi
callq 0x31b0
jmp 0xfca4
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
jmp 0xfc83
movq %rax, %rbx
leaq -0x200(%rbp), %rdi
jmp 0xfc9f
jmp 0xfc90
jmp 0xfc90
jmp 0xfc90
movq %rax, %rbx
leaq -0x270(%rbp), %rdi
callq 0x44c8
jmp 0xfc98
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x3110
jmp 0xfc7c
movq %rax, %rbx
leaq -0x190(%rbp), %rdi
callq 0x3110
jmp 0xfca4
jmp 0xfc90
jmp 0xfc90
jmp 0xfc90
movq %rax, %rbx
jmp 0xfca4
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x44c8
leaq -0x170(%rbp), %rdi
callq 0x44c8
movq %rbx, %rdi
callq 0x3410