// File: martinda3[P]Compiler/src/TCparser.cpp
// Function: toyc::TCparser::Definition()
ASdefinition* TCparser::Definition()
	{
		// Definition --> Type ID ( FunctionDefinition | SEMICOLON )
		enteringDEBUG("Definition");
        int loc;
		AStype* operand2 = NULL;
		ASdefinition* operand3[MAX_STATEMENTS];
		int operand4 = 0;
		int* num = new int;
		*num = 0;
		ASstatement* operand5 = NULL;
		operand2 = Type();
        if (buff->getTokenType() == ID)
        {
            loc = symTable->find(buff->getLexeme());
            if (loc == -1) loc = symTable->add(new TCsymbol(buff->getLexeme(),NO_TYPE));
            else if (loc > -1)
            {
                reportSEMANTIC_ERROR(scanner,"Cannot redeclare a function");
                exit(EXIT_FAILURE);
            }
        }
		accept(ID);
		if (buff->getTokenType() == SEMICOLON)
		{
			operand5 = new ASstatement();
            symTable->getSym(loc)->setType(VAR);
            symTable->getSym(loc)->setOffset(_nextOffset);
            symTable->getSym(loc)->getNextOffset();
		}
		else if (buff->getTokenType() == LPAREN)
		{
			operand5 = FunctionDefinition(operand3, num);
			operand4 = *num;
            symTable->getSym(loc)->setType(FUNC);
		}
		exitingDEBUG("Definition");
		return new ASfuncDef(operand2, operand3, operand4, operand5);
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1110, %rsp           # imm = 0x1110
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10b0(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x10a8(%rbp)
callq 0x95c0
movq -0x10a8(%rbp), %rdx
leaq 0x2544c(%rip), %rsi     # 0x331b4
leaq -0x28(%rbp), %rdi
callq 0x13550
jmp 0xdd73
leaq -0x28(%rbp), %rdi
callq 0xd790
jmp 0xdd7e
leaq -0x28(%rbp), %rdi
callq 0x9658
leaq -0x29(%rbp), %rdi
callq 0x93b0
movq $0x0, -0x48(%rbp)
movl $0x0, -0xff4(%rbp)
movl $0x4, %edi
callq 0x9350
movq -0x10b0(%rbp), %rdi
movq %rax, -0x1000(%rbp)
movq -0x1000(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x1008(%rbp)
callq 0xe280
movq %rax, %rcx
movq -0x10b0(%rbp), %rax
movq %rcx, -0x48(%rbp)
movq 0x8(%rax), %rdi
callq 0x1be60
cmpl $0x18, %eax
jne 0xe04c
movq -0x10b0(%rbp), %rax
leaq 0x3785b(%rip), %rcx     # 0x45660
movq (%rcx), %rcx
movq %rcx, -0x10c8(%rbp)
movq 0x8(%rax), %rsi
leaq -0x1028(%rbp), %rdi
movq %rdi, -0x10c0(%rbp)
callq 0x1be70
movq -0x10c8(%rbp), %rdi
movq -0x10c0(%rbp), %rsi
callq 0x31840
movl %eax, -0x10b4(%rbp)
jmp 0xde41
movl -0x10b4(%rbp), %eax
movl %eax, -0x40(%rbp)
leaq -0x1028(%rbp), %rdi
callq 0x9658
cmpl $-0x1, -0x40(%rbp)
jne 0xdf90
leaq 0x377f9(%rip), %rax     # 0x45660
movq (%rax), %rax
movq %rax, -0x10d8(%rbp)
movl $0x48, %edi
callq 0x9350
movq %rax, %rcx
movq -0x10b0(%rbp), %rax
movq %rcx, -0x10d0(%rbp)
movb $0x1, -0x1049(%rbp)
movq 0x8(%rax), %rsi
leaq -0x1048(%rbp), %rdi
callq 0x1be70
jmp 0xdea5
movq -0x10d0(%rbp), %rdi
leaq -0x1048(%rbp), %rsi
movl $0x3, %edx
callq 0x1fe10
jmp 0xdebf
movq -0x10d0(%rbp), %rsi
movq -0x10d8(%rbp), %rdi
movb $0x0, -0x1049(%rbp)
callq 0x317c0
movl %eax, -0x10dc(%rbp)
jmp 0xdee1
movl -0x10dc(%rbp), %eax
movl %eax, -0x40(%rbp)
leaq -0x1048(%rbp), %rdi
callq 0x9658
jmp 0xe04a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xdf1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x9658
leaq -0x29(%rbp), %rdi
callq 0x93b0
jmp 0xe274
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1028(%rbp), %rdi
callq 0x9658
jmp 0xe274
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xdf6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1048(%rbp), %rdi
callq 0x9658
testb $0x1, -0x1049(%rbp)
jne 0xdf7a
jmp 0xdf8b
movq -0x10d0(%rbp), %rdi
movl $0x48, %esi
callq 0x9360
jmp 0xe274
cmpl $-0x1, -0x40(%rbp)
jle 0xe048
movq -0x10b0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10f0(%rbp)
leaq -0x1071(%rbp), %rdi
movq %rdi, -0x10e8(%rbp)
callq 0x95c0
movq -0x10e8(%rbp), %rdx
leaq 0x251b0(%rip), %rsi     # 0x3317c
leaq -0x1070(%rbp), %rdi
callq 0x13550
jmp 0xdfda
movq -0x10f0(%rbp), %rdi
leaq -0x1070(%rbp), %rsi
callq 0x1b380
jmp 0xdfef
leaq -0x1070(%rbp), %rdi
callq 0x9658
leaq -0x1071(%rbp), %rdi
callq 0x93b0
movl $0x1, %edi
callq 0x9410
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xe037
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1070(%rbp), %rdi
callq 0x9658
leaq -0x1071(%rbp), %rdi
callq 0x93b0
jmp 0xe274
jmp 0xe04a
jmp 0xe04c
movq -0x10b0(%rbp), %rdi
movl $0x18, %esi
callq 0xe670
movq -0x10b0(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1be60
cmpl $0x27, %eax
jne 0xe122
movl $0x10, %edi
callq 0x9350
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x10f8(%rbp)
callq 0x1ed40
jmp 0xe094
movq -0x10f8(%rbp), %rax
movq %rax, -0x1008(%rbp)
leaq 0x375b7(%rip), %rax     # 0x45660
movq (%rax), %rdi
movl -0x40(%rbp), %esi
callq 0x31930
movq %rax, %rdi
xorl %esi, %esi
callq 0x1ff10
leaq 0x3759b(%rip), %rax     # 0x45660
movq (%rax), %rdi
movl -0x40(%rbp), %esi
callq 0x31930
movq %rax, %rdi
leaq 0x37272(%rip), %rax     # 0x4534c
movl (%rax), %esi
callq 0x1ffd0
leaq 0x37578(%rip), %rax     # 0x45660
movq (%rax), %rdi
movl -0x40(%rbp), %esi
callq 0x31930
movq %rax, %rdi
callq 0x1fff0
jmp 0xe188
movq -0x10f8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x10, %esi
callq 0x9360
jmp 0xe274
movq -0x10b0(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1be60
cmpl $0x1e, %eax
jne 0xe186
movq -0x10b0(%rbp), %rdi
leaq -0xff0(%rbp), %rsi
movq -0x1000(%rbp), %rdx
callq 0xe780
movq %rax, -0x1008(%rbp)
movq -0x1000(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xff4(%rbp)
leaq 0x374f2(%rip), %rax     # 0x45660
movq (%rax), %rdi
movl -0x40(%rbp), %esi
callq 0x31930
movq %rax, %rdi
movl $0x1, %esi
callq 0x1ff10
jmp 0xe188
leaq -0x1099(%rbp), %rdi
movq %rdi, -0x1100(%rbp)
callq 0x95c0
movq -0x1100(%rbp), %rdx
leaq 0x2500b(%rip), %rsi     # 0x331b4
leaq -0x1098(%rbp), %rdi
callq 0x13550
jmp 0xe1b7
leaq -0x1098(%rbp), %rdi
callq 0xda50
jmp 0xe1c5
leaq -0x1098(%rbp), %rdi
callq 0x9658
leaq -0x1099(%rbp), %rdi
callq 0x93b0
movl $0xfc8, %edi            # imm = 0xFC8
callq 0x9350
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x1108(%rbp)
movq -0x48(%rbp), %rsi
movl -0xff4(%rbp), %ecx
movq -0x1008(%rbp), %r8
leaq -0xff0(%rbp), %rdx
callq 0x13a40
jmp 0xe213
movq -0x1108(%rbp), %rax
addq $0x1110, %rsp           # imm = 0x1110
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0xe249
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x1098(%rbp), %rdi
callq 0x9658
leaq -0x1099(%rbp), %rdi
callq 0x93b0
jmp 0xe274
movq -0x1108(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0xfc8, %esi            # imm = 0xFC8
callq 0x9360
movq -0x38(%rbp), %rdi
callq 0x95b0
nopl (%rax)