// File: /workspace/github_c_makefile_star2_O0/goodpaul6[P]generic/script.c
// Function: parse_func
static expr_t* parse_func(script_t* script)
{
	expr_t* exp = create_expr(EXP_FUNC);
	get_next_token();
	
	char* name = estrdup(g_lexeme);
	
	get_next_token();
	
	exp->funcx.decl = declare_function(script, name);
	enter_function(exp->funcx.decl);
	
	if(g_cur_tok != TOK_OPENPAREN) error_exit_p("Expected '(' after func %s\n", name);
	get_next_token();
	
	while(g_cur_tok != TOK_CLOSEPAREN)
	{
		if(g_cur_tok != TOK_IDENT) error_exit_p("Expected identifier but received %s\n", g_token_names[g_cur_tok]);
		char* name = estrdup(g_lexeme);
		
		get_next_token();
		if(g_cur_tok != TOK_COLON) error_exit_p("Expected ':' after '%s' in argument list\n", name);
		get_next_token();
		
		declare_argument(name, parse_type_tag(script));
		free(name);
		
		if(g_cur_tok == TOK_COMMA) get_next_token();
		else if(g_cur_tok != TOK_CLOSEPAREN) error_exit_p("Unexpected token '%s'\n", g_token_names[g_cur_tok]);
	}
	get_next_token();

	finalize_args();
	
	if(g_cur_tok != TOK_COLON) error_exit_p("Expected ':' after ')'\n");
	get_next_token();
	exp->funcx.decl->tag->func.return_type = parse_type_tag(script);
	
	exp->funcx.body = parse_expr(script);
	exit_function();
	
	if(exp->funcx.decl->tag->func.return_type->type != TAG_VOID && !exp->funcx.decl->has_return)
		error_exit_p("Non-void function missing return statement in body\n");
		
	// TODO: Check if the body has a top-level return statement
	// in order to assure that non-void functions ALWAYS return a value
	// (I mean, they'll return null when you don't so idk really)
	
	free(name);

	return exp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl $0x19, %edi
callq 0xa1b0
movq %rax, -0x10(%rbp)
callq 0xd640
leaq 0xc1ca(%rip), %rdi      # 0x1a5c0
callq 0x2500
movq %rax, -0x18(%rbp)
callq 0xd640
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xf180
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0xf2a0
cmpl $0x19, 0xc180(%rip)     # 0x1a5b0
je 0xe444
movq -0x18(%rbp), %rsi
leaq 0x6de4(%rip), %rdi      # 0x15221
movb $0x0, %al
callq 0xa0e0
callq 0xd640
cmpl $0x1a, 0xc160(%rip)     # 0x1a5b0
je 0xe51a
cmpl $0x16, 0xc153(%rip)     # 0x1a5b0
je 0xe47f
movslq 0xc14a(%rip), %rcx      # 0x1a5b0
leaq 0xbdb3(%rip), %rax      # 0x1a220
movq (%rax,%rcx,8), %rsi
leaq 0x6dc5(%rip), %rdi      # 0x1523d
movb $0x0, %al
callq 0xa0e0
leaq 0xc13a(%rip), %rdi      # 0x1a5c0
callq 0x2500
movq %rax, -0x20(%rbp)
callq 0xd640
cmpl $0x1d, 0xc115(%rip)     # 0x1a5b0
je 0xe4af
movq -0x20(%rbp), %rsi
leaq 0x6dba(%rip), %rdi      # 0x15262
movb $0x0, %al
callq 0xa0e0
callq 0xd640
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0xef40
movq -0x28(%rbp), %rdi
movq %rax, %rsi
callq 0xf2c0
movq -0x20(%rbp), %rdi
callq 0x2030
cmpl $0x1f, 0xc0cf(%rip)     # 0x1a5b0
jne 0xe4ea
callq 0xd640
jmp 0xe515
cmpl $0x1a, 0xc0bf(%rip)     # 0x1a5b0
je 0xe513
movslq 0xc0b6(%rip), %rcx      # 0x1a5b0
leaq 0xbd1f(%rip), %rax      # 0x1a220
movq (%rax,%rcx,8), %rsi
leaq 0x6b11(%rip), %rdi      # 0x1501d
movb $0x0, %al
callq 0xa0e0
jmp 0xe515
jmp 0xe449
callq 0xd640
callq 0xf380
cmpl $0x1d, 0xc085(%rip)     # 0x1a5b0
je 0xe53b
leaq 0x6d58(%rip), %rdi      # 0x1528c
movb $0x0, %al
callq 0xa0e0
callq 0xd640
movq -0x8(%rbp), %rdi
callq 0xef40
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rdi
callq 0xd5a0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
callq 0xf400
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq 0x48(%rax), %rax
cmpl $0x0, 0x20(%rax)
je 0xe5a7
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
cmpb $0x0, 0x64(%rax)
jne 0xe5a7
leaq 0x6d04(%rip), %rdi      # 0x152a4
movb $0x0, %al
callq 0xa0e0
movq -0x18(%rbp), %rdi
callq 0x2030
movq -0x10(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)