// File: /workspace/github_c_makefile_star2_O0/goodpaul6[P]generic/script.c
// Function: apply_import_directive
static void apply_import_directive(script_t* script, const char* filename)
{
	script_module_t* module = (script_module_t*)vec_get(&script->modules, g_cur_module_index);
	char* dir = estrdup(module->local_path);
	char* sep = strrchr(dir, '/');
	if (sep)
		*(sep + 1) = 0;
	else
		*dir = 0;

	size_t dirlen = strlen(dir);
	size_t namelen = strlen(filename);
	char* path = emalloc(dirlen + namelen + 1);
	strcpy(path, dir);
	strcpy(path + dirlen, filename);

	FILE* file = fopen(path, "rb");
	if(file)
	{
		fseek(file, 0, SEEK_END);
		size_t length = ftell(file);
		fseek(file, 0, SEEK_SET);
		
		char* code = emalloc(length + 1);
		fread(code, 1, length, file);
		code[length] = '\0';
		
		int module_index = add_module(script, path, NULL, code);
		
		script_module_t* current_module = vec_get(&script->modules, g_cur_module_index);
		vec_push_back(&current_module->referenced_modules, &module_index);

		free(code);
		fclose(file);
	}
	else
		fprintf(stderr, "Unable to open file '%s' for importing\n", filename);

	free(path);
	free(dir);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x2b8, %rdi            # imm = 0x2B8
movslq 0xb6f6(%rip), %rsi      # 0x1a498
callq 0x11890
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x2500
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl $0x2f, %esi
callq 0x20e0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xeddf
movq -0x28(%rbp), %rax
movb $0x0, 0x1(%rax)
jmp 0xede6
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rdi
callq 0x20a0
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20a0
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
addq -0x38(%rbp), %rdi
addq $0x1, %rdi
callq 0x3580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x2050
movq -0x40(%rbp), %rdi
addq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2050
movq -0x40(%rbp), %rdi
leaq 0x49d8(%rip), %rsi      # 0x13816
callq 0x21d0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xef07
movq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x21a0
movq -0x48(%rbp), %rdi
callq 0x2160
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x21a0
movq -0x50(%rbp), %rdi
addq $0x1, %rdi
callq 0x3580
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
movl $0x1, %esi
callq 0x2070
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x58(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x3ca0
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rdi
addq $0x2b8, %rdi            # imm = 0x2B8
movslq 0xb5bb(%rip), %rsi      # 0x1a498
callq 0x11890
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x11960
movq -0x58(%rbp), %rdi
callq 0x2030
movq -0x48(%rbp), %rdi
callq 0x2090
jmp 0xef23
movq 0xb0ea(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x6177(%rip), %rsi      # 0x15093
movb $0x0, %al
callq 0x2150
movq -0x40(%rbp), %rdi
callq 0x2030
movq -0x20(%rbp), %rdi
callq 0x2030
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)