// File: /workspace/github_c_makefile_star2_O0/goodpaul6[P]generic/script.c
// Function: parse_struct
static expr_t* parse_struct(script_t* script)
{
	expr_t* exp = create_expr(EXP_STRUCT_DECL);
	char is_union = g_cur_tok == TOK_UNION;
	
	get_next_token();
	// if(g_cur_tok != TOK_IDENT) error_exit_p("Expected identifier after 'struct' but received '%s'\n", g_token_names[g_cur_tok]);
	// type_tag_t* tag = define_struct_type(g_lexeme, is_union);
	
	if(g_cur_tok != TOK_IDENT) error_exit_p("Expected identifier after '%s'\n", is_union ? "union" : "struct");
	type_tag_t* tag = define_struct_type(script, g_lexeme, is_union);
	
	get_next_token();
	
	if(g_cur_tok != TOK_OPENCURLY) error_exit_p("Expected '{' after struct %s but received '%s'\n", tag->ds.name, g_token_names[g_cur_tok]);
	get_next_token();
	
	while(g_cur_tok != TOK_CLOSECURLY)
	{
		if(g_cur_tok == TOK_USING)
		{
			get_next_token();
			if(g_cur_tok != TOK_IDENT) error_exit_p("Expected identifier after 'using' but received '%s'\n", g_token_names[g_cur_tok]);
			
			type_tag_t* used_type = get_type_tag_from_name(script, g_lexeme);
			vec_push_back(&tag->ds.using, &used_type);
			
			get_next_token();
			continue;
		}
		
		char is_static = 0;
		
		if(g_cur_tok == TOK_STATIC)
		{
			is_static = 1;
			get_next_token();
		}
	
		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)
		{
			if(g_cur_tok != TOK_OPENPAREN) error_exit_p("Expected ':' or '(' but received '%s'\n", g_token_names[g_cur_tok]);
			get_next_token();
			
			size_t length = strlen(tag->ds.name) + strlen(name) + 2;
			char* buf = emalloc(length + 1);
			sprintf(buf, "%s_%s", tag->ds.name, name); 
			buf[length - 1] = '\0';
			
			func_decl_t* decl = declare_function(script, buf);
			enter_function(decl);
			
			if(!is_static)
				declare_argument("self", tag);
			
			// NOTE: Copied from parse_func
			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();
			decl->tag->func.return_type = parse_type_tag(script);
		
			free(buf);
			exit_function();
		}
		else
		{
			get_next_token();
		
			type_tag_member_t member;
			member.index = is_union ? 0 : tag->ds.members.length;
			member.name = name;
			member.type = parse_type_tag(script);
			member.default_value = NULL;
			
			if(is_union)
				tag->ds.size = 1;
			else
				tag->ds.size += 1;
			
			// NOTE: user is setting a default value for this shit
			if(g_cur_tok == TOK_ASSIGN)
			{
				get_next_token();
				member.default_value = parse_expr(script);
			}
		
			vec_push_back(&tag->ds.members, &member);
		}
	}
	get_next_token();
	
	exp->struct_tag = tag;
	
	return exp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl $0x1, %edi
callq 0xa1b0
movq %rax, -0x10(%rbp)
cmpl $0x7, 0xbc5c(%rip)      # 0x1a5b0
sete %al
andb $0x1, %al
movzbl %al, %eax
movb %al, -0x11(%rbp)
callq 0xd640
cmpl $0x16, 0xbc45(%rip)     # 0x1a5b0
je 0xe994
movsbl -0x11(%rbp), %ecx
leaq 0x6378(%rip), %rsi      # 0x14cf0
leaq 0x6378(%rip), %rax      # 0x14cf7
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x6ae3(%rip), %rdi      # 0x15470
movb $0x0, %al
callq 0xa0e0
movq -0x8(%rbp), %rdi
leaq 0xbc21(%rip), %rsi      # 0x1a5c0
movsbl -0x11(%rbp), %edx
callq 0xf6f0
movq %rax, -0x20(%rbp)
callq 0xd640
cmpl $0x1b, 0xbbf8(%rip)     # 0x1a5b0
je 0xe9e2
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rsi
movslq 0xbbe7(%rip), %rcx      # 0x1a5b0
leaq 0xb850(%rip), %rax      # 0x1a220
movq (%rax,%rcx,8), %rdx
leaq 0x6ab5(%rip), %rdi      # 0x15490
movb $0x0, %al
callq 0xa0e0
callq 0xd640
cmpl $0x1c, 0xbbc2(%rip)     # 0x1a5b0
je 0xed57
cmpl $0x2, 0xbbb5(%rip)      # 0x1a5b0
jne 0xea5b
callq 0xd640
cmpl $0x16, 0xbba7(%rip)     # 0x1a5b0
je 0xea2b
movslq 0xbb9e(%rip), %rcx      # 0x1a5b0
leaq 0xb807(%rip), %rax      # 0x1a220
movq (%rax,%rcx,8), %rsi
leaq 0x6a9c(%rip), %rdi      # 0x154c0
movb $0x0, %al
callq 0xa0e0
movq -0x8(%rbp), %rdi
leaq 0xbb8a(%rip), %rsi      # 0x1a5c0
callq 0xa7d0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
addq $0x28, %rdi
addq $0x18, %rdi
leaq -0x28(%rbp), %rsi
callq 0x11960
callq 0xd640
jmp 0xe9e7
movb $0x0, -0x29(%rbp)
cmpl $0x3, 0xbb4a(%rip)      # 0x1a5b0
jne 0xea71
movb $0x1, -0x29(%rbp)
callq 0xd640
cmpl $0x16, 0xbb38(%rip)     # 0x1a5b0
je 0xea9a
movslq 0xbb2f(%rip), %rcx      # 0x1a5b0
leaq 0xb798(%rip), %rax      # 0x1a220
movq (%rax,%rcx,8), %rsi
leaq 0x6a62(%rip), %rdi      # 0x154f5
movb $0x0, %al
callq 0xa0e0
leaq 0xbb1f(%rip), %rdi      # 0x1a5c0
callq 0x2500
movq %rax, -0x38(%rbp)
callq 0xd640
cmpl $0x1d, 0xbafa(%rip)     # 0x1a5b0
je 0xecaf
cmpl $0x19, 0xbaed(%rip)     # 0x1a5b0
je 0xeae5
movslq 0xbae4(%rip), %rcx      # 0x1a5b0
leaq 0xb74d(%rip), %rax      # 0x1a220
movq (%rax,%rcx,8), %rsi
leaq 0x6a3e(%rip), %rdi      # 0x1551c
movb $0x0, %al
callq 0xa0e0
callq 0xd640
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x20a0
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rdi
callq 0x20a0
movq %rax, %rcx
movq -0x80(%rbp), %rax
addq %rcx, %rax
addq $0x2, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
addq $0x1, %rdi
callq 0x3580
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdx
movq -0x38(%rbp), %rcx
leaq 0x6a05(%rip), %rsi      # 0x15543
movb $0x0, %al
callq 0x2200
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xf180
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0xf2a0
cmpb $0x0, -0x29(%rbp)
jne 0xeb85
movq -0x20(%rbp), %rsi
leaq 0x69c9(%rip), %rdi      # 0x15549
callq 0xf2c0
jmp 0xeb87
cmpl $0x1a, 0xba22(%rip)     # 0x1a5b0
je 0xec5e
cmpl $0x16, 0xba15(%rip)     # 0x1a5b0
je 0xebbd
movslq 0xba0c(%rip), %rcx      # 0x1a5b0
leaq 0xb675(%rip), %rax      # 0x1a220
movq (%rax,%rcx,8), %rsi
leaq 0x6687(%rip), %rdi      # 0x1523d
movb $0x0, %al
callq 0xa0e0
leaq 0xb9fc(%rip), %rdi      # 0x1a5c0
callq 0x2500
movq %rax, -0x58(%rbp)
callq 0xd640
cmpl $0x1d, 0xb9d7(%rip)     # 0x1a5b0
je 0xebed
movq -0x58(%rbp), %rsi
leaq 0x667c(%rip), %rdi      # 0x15262
movb $0x0, %al
callq 0xa0e0
callq 0xd640
movq -0x58(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rdi
callq 0xef40
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0xf2c0
movq -0x58(%rbp), %rdi
callq 0x2030
cmpl $0x1f, 0xb98b(%rip)     # 0x1a5b0
jne 0xec2e
callq 0xd640
jmp 0xec59
cmpl $0x1a, 0xb97b(%rip)     # 0x1a5b0
je 0xec57
movslq 0xb972(%rip), %rcx      # 0x1a5b0
leaq 0xb5db(%rip), %rax      # 0x1a220
movq (%rax,%rcx,8), %rsi
leaq 0x63cd(%rip), %rdi      # 0x1501d
movb $0x0, %al
callq 0xa0e0
jmp 0xec59
jmp 0xeb87
callq 0xd640
callq 0xf380
cmpl $0x1d, 0xb941(%rip)     # 0x1a5b0
je 0xec7f
leaq 0x6614(%rip), %rdi      # 0x1528c
movb $0x0, %al
callq 0xa0e0
callq 0xd640
movq -0x8(%rbp), %rdi
callq 0xef40
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x48(%rax)
movq -0x48(%rbp), %rdi
callq 0x2030
callq 0xf400
jmp 0xed52
callq 0xd640
movsbl -0x11(%rbp), %eax
cmpl $0x0, %eax
je 0xecc8
xorl %eax, %eax
movq %rax, -0x90(%rbp)
jmp 0xecd7
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl %eax, -0x70(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
callq 0xef40
movq %rax, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
cmpb $0x0, -0x11(%rbp)
je 0xed12
movq -0x20(%rbp), %rax
movq $0x1, 0x38(%rax)
jmp 0xed22
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x38(%rax)
cmpl $0x24, 0xb887(%rip)     # 0x1a5b0
jne 0xed3d
callq 0xd640
movq -0x8(%rbp), %rdi
callq 0xd5a0
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rdi
addq $0x28, %rdi
addq $0x38, %rdi
leaq -0x78(%rbp), %rsi
callq 0x11960
jmp 0xe9e7
callq 0xd640
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)