// File: /workspace/github_c_makefile_star2_O1/goodpaul6[P]generic/script.c
// Function: reference_variable
static var_decl_t* reference_variable(script_t* script, const char* name)
{
	if(g_cur_func)
	{
		for(int scope = g_scope; scope >= 0; --scope)
		{
			for(int i = 0; i < g_cur_func->locals.length; ++i)
			{
				var_decl_t* decl = vec_get_value(&g_cur_func->locals, i, var_decl_t*);
				if(decl->scope == scope && strcmp(decl->name, name) == 0) return decl;
			}
		}
		
		for(int i = 0; i < g_cur_func->args.length; ++i)
		{
			var_decl_t* decl = vec_get_value(&g_cur_func->args, i, var_decl_t*);
			if(strcmp(decl->name, name) == 0) return decl;
		}
	}

	for (int module_index = 0; module_index < script->modules.length; ++module_index)
	{
		script_module_t* module = vec_get(&script->modules, module_index);
		for (int i = 0; i < module->globals.length; ++i)
		{
			var_decl_t* decl = vec_get_value(&module->globals, i, var_decl_t*);
			if (strcmp(decl->name, name) == 0) return decl;
		}
	}
	
	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, -0x30(%rbp)
cmpq $0x0, 0xdb59(%rip)      # 0x16248
movq %rdi, -0x40(%rbp)
je 0x880b
movl 0xdb40(%rip), %r12d     # 0x16240
movl %r12d, %ebx
shrl $0x1f, %ebx
testl %r12d, %r12d
js 0x8780
movq 0xdb36(%rip), %rdi      # 0x16248
cmpq $0x0, 0x30(%rdi)
setne %r13b
je 0x876a
xorl %r14d, %r14d
addq $0x20, %rdi
movq %r14, %rsi
callq 0xdf24
movq (%rax), %r15
cmpl %r12d, 0x18(%r15)
jne 0x8746
movq 0x10(%r15), %rdi
movq -0x30(%rbp), %rsi
callq 0x2150
testl %eax, %eax
je 0x8762
movb $0x1, %al
testb %al, %al
je 0x876a
incq %r14
movq 0xdaf2(%rip), %rdi      # 0x16248
cmpq %r14, 0x30(%rdi)
seta %r13b
ja 0x8720
jmp 0x876a
xorl %eax, %eax
movq %r15, -0x38(%rbp)
jmp 0x8748
testb $0x1, %r13b
jne 0x8780
leal -0x1(%r12), %eax
testl %r12d, %r12d
setle %bl
movl %eax, %r12d
jg 0x870b
testb $0x1, %bl
je 0x88c9
movq 0xdab8(%rip), %rdi      # 0x16248
cmpq $0x0, 0x50(%rdi)
setne %bl
movq -0x38(%rbp), %r12
je 0x87fe
addq $0x40, %rdi
xorl %esi, %esi
callq 0xdf24
movq (%rax), %r14
movq 0x10(%r14), %rdi
movq -0x30(%rbp), %rsi
callq 0x2150
testl %eax, %eax
cmoveq %r14, %r12
je 0x87fe
movl $0x1, %r14d
movq 0xda7a(%rip), %rdi      # 0x16248
cmpq %r14, 0x50(%rdi)
seta %bl
jbe 0x87fe
addq $0x40, %rdi
movq %r14, %rsi
callq 0xdf24
movq (%rax), %r15
movq 0x10(%r15), %rdi
movq -0x30(%rbp), %rsi
callq 0x2150
incq %r14
testl %eax, %eax
cmoveq %r15, %r12
jne 0x87c7
testb %bl, %bl
movq -0x40(%rbp), %rdi
je 0x880b
jmp 0x88cd
cmpq $0x0, 0x2c8(%rdi)
je 0x88c4
leaq 0x2b8(%rdi), %rax
movq %rax, -0x48(%rbp)
xorl %esi, %esi
movq -0x48(%rbp), %rdi
movq %rsi, -0x50(%rbp)
callq 0xdf24
cmpq $0x0, 0x2100(%rax)
setne %r13b
je 0x88a7
movq %rax, %r14
leaq 0x20f0(%rax), %rdi
movq %rdi, -0x38(%rbp)
xorl %esi, %esi
callq 0xdf24
movq (%rax), %rbx
movq 0x10(%rbx), %rdi
movq -0x30(%rbp), %rsi
callq 0x2150
testl %eax, %eax
cmoveq %rbx, %r12
je 0x88a7
movl $0x1, %ebx
cmpq %rbx, 0x2100(%r14)
seta %r13b
jbe 0x88a7
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
callq 0xdf24
movq (%rax), %r15
movq 0x10(%r15), %rdi
movq -0x30(%rbp), %rsi
callq 0x2150
incq %rbx
testl %eax, %eax
cmoveq %r15, %r12
jne 0x8873
testb %r13b, %r13b
jne 0x88cd
movq -0x50(%rbp), %rsi
incq %rsi
movq -0x40(%rbp), %rax
cmpq %rsi, 0x2c8(%rax)
ja 0x8826
xorl %r12d, %r12d
jmp 0x88cd
movq -0x38(%rbp), %r12
movq %r12, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq