// File: /workspace/github_c_makefile_star2_O2/mikecat[P]x86_interpreter/pe_libs.c
// Function: pe_libs_initialize
int pe_libs_initialize(uint32_t work_start, uint32_t argc, uint32_t argv) {
	if (UINT32_MAX - work_start < WORK_SIZE - 1) {
		fprintf(stderr, "no enough space for PE work\n");
		return 0;
	}
	work_origin = work_start;
	dmemory_allocate(work_origin, WORK_SIZE);
	if (argc == 0) { /* ダミーの引数情報を利用 */
		argc_value = 1;
		argv_value = WORK_ARGV0;
	} else { /* 構築された引数情報を利用 */
		argc_value = argc;
		argv_value = argv;
	}
	dmem_write_uint(WORK_ARGV0, WORK_PNAME, 4);
	dmem_write_uint(WORK_ARGV1, 0, 4);
	dmem_write_uint(WORK_ENV0, 0, 4);
	dmemory_write("x\0\0\0", WORK_PNAME, 4);
	dmem_write_uint(WORK_FMODE, 0x00004000, 4); /* O_TEXT */
	dmem_write_uint(WORK_ERRNO, 0, 4);
	dmem_write_uint(WORK_DAYLIGHT, 0, 4);
	dmem_write_uint(WORK_TIMEZONE, -UINT32_C(9) * 60 * 60, 4);
	dmem_write_uint(WORK_TZNAME, WORK_TZNAME0, 4);
	dmem_write_uint(WORK_TZNAME + 4, WORK_TZNAME1, 4);
	dmemory_write("JST\0", WORK_TZNAME0, 4);
	dmemory_write("\0\0\0\0", WORK_TZNAME1, 4);

	if (!dmem_libc_stdio_initialize(WORK_IOB)) return 0;
	if (!dmem_libc_stdlib_initialize(WORK_HEAP_START)) return 0;
	if (!dmem_libc_string_initialize()) return 0;
	if (!dmem_libc_time_initialize(WORK_LIBC_TIME_DATA)) return 0;
	return 1;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
cmpl $0xffffd001, %edi       # imm = 0xFFFFD001
jae 0xa35c
movl %edx, %ebx
movl %esi, %r14d
movl %edi, 0x12bd1(%rip)     # 0x1cdbc
movl $0x3000, %ebp           # imm = 0x3000
movl $0x3000, %esi           # imm = 0x3000
callq 0x5e70
cmpl $0x1, %r14d
movl %r14d, %eax
adcl $0x0, %eax
testl %r14d, %r14d
movl 0x12baf(%rip), %edi     # 0x1cdbc
cmovel %edi, %ebx
movl %eax, 0x12baa(%rip)     # 0x1cdc0
movl %ebx, 0x12ba8(%rip)     # 0x1cdc4
leal 0xc(%rdi), %esi
pushq $0x4
popq %r14
movl %r14d, %edx
callq 0x6110
movl 0x12b8b(%rip), %edi     # 0x1cdbc
addl $0x4, %edi
xorl %ebx, %ebx
xorl %esi, %esi
movl %r14d, %edx
callq 0x6110
movl 0x12b76(%rip), %edi     # 0x1cdbc
addl $0x8, %edi
xorl %esi, %esi
movl %r14d, %edx
callq 0x6110
movl 0x12b63(%rip), %esi     # 0x1cdbc
addl $0xc, %esi
leaq 0x3a7c(%rip), %rdi      # 0xdcdf
movl %r14d, %edx
callq 0x5d3e
movl 0x12b4b(%rip), %edi     # 0x1cdbc
addl $0x10, %edi
movl $0x4000, %esi           # imm = 0x4000
movl %r14d, %edx
callq 0x6110
movl 0x12b35(%rip), %edi     # 0x1cdbc
addl $0x14, %edi
xorl %esi, %esi
movl %r14d, %edx
callq 0x6110
movl 0x12b22(%rip), %edi     # 0x1cdbc
addl $0x18, %edi
xorl %esi, %esi
movl %r14d, %edx
callq 0x6110
movl 0x12b0f(%rip), %edi     # 0x1cdbc
addl $0x18, %edi
movl $0xffff8170, %esi       # imm = 0xFFFF8170
movl %r14d, %edx
callq 0x6110
movl 0x12af9(%rip), %esi     # 0x1cdbc
leal 0x1c(%rsi), %edi
addl $0x20, %esi
movl %r14d, %edx
callq 0x6110
movl 0x12ae5(%rip), %esi     # 0x1cdbc
leal 0x20(%rsi), %edi
addl $0x24, %esi
movl %r14d, %edx
callq 0x6110
movl 0x12ad1(%rip), %esi     # 0x1cdbc
addl $0x20, %esi
leaq 0x39ef(%rip), %rdi      # 0xdce4
movl %r14d, %edx
callq 0x5d3e
movl 0x12ab9(%rip), %esi     # 0x1cdbc
addl $0x24, %esi
leaq 0x39dc(%rip), %rdi      # 0xdce9
movl %r14d, %edx
callq 0x5d3e
movl $0x1000, %edi           # imm = 0x1000
addl 0x12a9c(%rip), %edi     # 0x1cdbc
callq 0x6380
testl %eax, %eax
je 0xa37a
addl 0x12a8d(%rip), %ebp     # 0x1cdbc
movl %ebp, %edi
callq 0x79b0
testl %eax, %eax
je 0xa37a
callq 0x7dd8
testl %eax, %eax
je 0xa37a
movl $0x2000, %edi           # imm = 0x2000
addl 0x12a6e(%rip), %edi     # 0x1cdbc
callq 0x82ec
xorl %ebx, %ebx
testl %eax, %eax
setne %bl
jmp 0xa37a
movq 0x7c95(%rip), %rax      # 0x11ff8
movq (%rax), %rcx
leaq 0x30f1(%rip), %rdi      # 0xd45e
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x1190
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
popq %r14
popq %rbp
retq