// File: /workspace/github_c_makefile_star2_O0/mikecat[P]x86_interpreter/x86_interpreter.c
// Function: step_memread
static uint32_t step_memread(int* success, uint32_t inst_addr, int segment, uint32_t addr, int size) {
	uint32_t res = 0;
	int i;
	if (UINT32_MAX - segment_offsets[segment] < addr ||
	(size <= 0 || UINT32_MAX - (segment_offsets[segment] + addr) < (uint32_t)(size - 1))) {
		*success = 0;
		return 0;
	}
	for (i = 0; i < size; i++) {
		uint32_t this_addr = segment_offsets[segment] + addr + i;
		uint8_t value;
		if (!memory_access(&value, this_addr, 0, 0)) {
			fprintf(stderr, "failed to read memory %08"PRIx32" at %08"PRIx32"\n\n", this_addr, inst_addr);
			print_regs(stderr);
			*success = 0;
			return 0;
		}
		res |= value << (i * 8);
	}
	if (size < 4) {
		if (res & (UINT32_C(0x80) << ((size - 1) * 8))) {
			res |= UINT32_C(0xffffffff) << (size * 8);
		} else {
			res &= UINT32_C(0xffffffff) >> ((4 - size) * 8);
		}
	}
	*success = 1;
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movslq -0x18(%rbp), %rdx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leaq 0xea10(%rip), %rcx      # 0x15210
subl (%rcx,%rdx,4), %eax
cmpl -0x1c(%rbp), %eax
jb 0x6830
cmpl $0x0, -0x20(%rbp)
jle 0x6830
movslq -0x18(%rbp), %rcx
leaq 0xe9f7(%rip), %rax      # 0x15210
movl (%rax,%rcx,4), %ecx
addl -0x1c(%rbp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subl %ecx, %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x6846
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x6949
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x68e8
movslq -0x18(%rbp), %rcx
leaq 0xe9ac(%rip), %rax      # 0x15210
movl (%rax,%rcx,4), %eax
addl -0x1c(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %esi
leaq -0x2d(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x1450
cmpl $0x0, %eax
jne 0x68c8
movq 0xe764(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
movl -0x2c(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq 0xb2ca(%rip), %rsi      # 0x11b66
movb $0x0, %al
callq 0x10d0
movq 0xe746(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
callq 0x12b0
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x6949
movzbl -0x2d(%rbp), %eax
movl -0x28(%rbp), %ecx
shll $0x3, %ecx
shll %cl, %eax
orl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x684d
cmpl $0x4, -0x20(%rbp)
jge 0x6939
movl -0x24(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
shll $0x3, %ecx
movl $0x80, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x691f
movl -0x20(%rbp), %ecx
shll $0x3, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
orl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x6937
movl $0x4, %ecx
subl -0x20(%rbp), %ecx
shll $0x3, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shrl %cl, %eax
andl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x6939
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)