// File: /workspace/github_c_makefile_star2_O0/goodpaul6[P]generic/script.c
// Function: declare_variable
static var_decl_t* declare_variable(script_t* script, const char* name, type_tag_t* tag)
{
	var_decl_t* decl = reference_variable(script, name);
	
	if(!decl)
	{
		decl = emalloc(sizeof(type_tag_t));
		
		decl->parent = g_cur_func;
		decl->tag = tag;
		decl->name = estrdup(name);
		decl->scope = g_scope;
		
		if(g_cur_func)
		{
			decl->index = g_cur_func->locals.length;
			vec_push_back(&g_cur_func->locals, &decl);
			return decl;
		}
	
		// NOTE: g_cur_module_index MUST have the right value rn
		script_module_t* module = vec_get(&script->modules, g_cur_module_index);

		// NOTE: The global index must be unique across modules
		int index = module->globals.length;
		for (int i = 0; i < g_cur_module_index; ++i)
		{
			script_module_t* prev_module = vec_get(&script->modules, i);
			index += prev_module->globals.length;
		}

		decl->index = index;
		vec_push_back(&module->globals, &decl);

		return decl;
	}
	else if (!g_cur_func)
		error_exit_p("Attempted to redeclare global variable '%s'\n", name);

	return decl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x9f10
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x9ed3
movl $0x80, %edi
callq 0x3580
movq %rax, -0x28(%rbp)
movq 0x106e3(%rip), %rcx     # 0x1a4a8
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rdi
callq 0x2500
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movl 0x106ae(%rip), %ecx     # 0x1a4a0
movq -0x28(%rbp), %rax
movl %ecx, 0x18(%rax)
cmpq $0x0, 0x106a7(%rip)     # 0x1a4a8
je 0x9e38
movq 0x1069e(%rip), %rax     # 0x1a4a8
movq 0x30(%rax), %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq 0x1068a(%rip), %rdi     # 0x1a4a8
addq $0x20, %rdi
leaq -0x28(%rbp), %rsi
callq 0x11960
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x9ef9
movq -0x10(%rbp), %rdi
addq $0x2b8, %rdi            # imm = 0x2B8
movslq 0x1064e(%rip), %rsi     # 0x1a498
callq 0x11890
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x2100(%rax), %rax
movl %eax, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl 0x10627(%rip), %eax     # 0x1a498
jge 0x9eab
movq -0x10(%rbp), %rdi
addq $0x2b8, %rdi            # imm = 0x2B8
movslq -0x38(%rbp), %rsi
callq 0x11890
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x2100(%rax), %rcx
movslq -0x34(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x9e68
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x30(%rbp), %rdi
addq $0x20f0, %rdi           # imm = 0x20F0
leaq -0x28(%rbp), %rsi
callq 0x11960
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x9ef9
cmpq $0x0, 0x105cd(%rip)     # 0x1a4a8
jne 0x9eef
movq -0x18(%rbp), %rsi
leaq 0xa44b(%rip), %rdi      # 0x14333
movb $0x0, %al
callq 0xa0e0
jmp 0x9ef1
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)