// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/src/fmtutil-cmpr.c
// Function: fmtutil_decompress_exepack_reloc_tbl
int fmtutil_decompress_exepack_reloc_tbl(deark *c, i64 pos1, i64 endpos, dbuf *outf)
{
	i64 pos = pos1;
	i64 seg = 0;
	int reloc_count = 0;
	int retval = 0;
	int saved_indent_level;
	dbuf *inf = c->infile;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "compressed reloc table: pos=%"I64_FMT", end=%"I64_FMT, pos1, endpos);
	if(endpos > inf->len) goto done;
	de_dbg_indent(c, 1);

	for(seg=0; seg<0x10000; seg+=0x1000) {
		i64 count;
		i64 i;

		if(pos>=endpos) {
			goto done;
		}
		count = dbuf_getu16le_p(inf, &pos);
		de_dbg2(c, "seg %04x count: %u", (UI)seg, (UI)count);

		de_dbg_indent(c, 1);
		for(i=0; i<count; i++) {
			i64 offs;

			if(pos>=endpos || reloc_count>=65535) goto done;
			offs = dbuf_getu16le_p(inf, &pos);
			de_dbg2(c, "reloc: %04x:%04x", (UI)seg, (UI)offs);
			dbuf_writeu16le(outf, offs);
			dbuf_writeu16le(outf, seg);
			reloc_count++;
		}
		de_dbg_indent(c, -1);
	}

	retval = 1;
	de_dbg(c, "reloc count: %d", (int)reloc_count);

done:
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x30(%rsp)
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, 0x8(%rsp)
movq 0x18(%rdi), %r15
leaq 0x1c(%rsp), %rsi
callq 0xe958c
leaq 0x4e748(%rip), %rsi     # 0x14a5e4
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0xe9226
movq %r14, 0x20(%rsp)
movq %r15, 0x28(%rsp)
cmpq %r14, 0x18(%r15)
jl 0xfc028
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq $0x0, (%rsp)
xorl %r15d, %r15d
movq 0x20(%rsp), %rbp
movq %rbx, 0x10(%rsp)
movl $0x2, %r14d
cmpq %rbp, 0x8(%rsp)
jge 0xfbfe4
movq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef1ed
movq %rax, %r12
movq %rbx, %rdi
leaq 0x4e6fc(%rip), %rsi     # 0x14a60d
movq (%rsp), %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe93cf
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
testq %r12, %r12
movl %r15d, %ecx
jle 0xfbfc2
cmpq %rbp, 0x8(%rsp)
setl %al
cmpl $0xffff, %ecx           # imm = 0xFFFF
setl %r15b
andb %al, %r15b
movl $0x2, %r14d
cmpb $0x1, %r15b
jne 0xfbfb4
movq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl %ecx, 0x18(%rsp)
callq 0xef1ed
movq %rax, %rbx
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
leaq 0x4e6a2(%rip), %rsi     # 0x14a620
movq (%rsp), %r13
movl %r13d, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0xe93cf
movq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xf1598
movq %rbp, %rdi
movq 0x20(%rsp), %rbp
movq %r13, %rsi
callq 0xf1598
movl 0x18(%rsp), %ecx
incl %ecx
testb %r15b, %r15b
je 0xfbfdc
decq %r12
jne 0xfbf38
movl %ecx, %r15d
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
xorl %r14d, %r14d
jmp 0xfbfe4
movl %ecx, %r15d
movq 0x10(%rsp), %rbx
testl %r14d, %r14d
jne 0xfc020
movq (%rsp), %rcx
leaq 0x1000(%rcx), %rax
cmpq $0xf000, %rcx           # imm = 0xF000
movq %rax, (%rsp)
jb 0xfbee4
leaq 0x32fbc(%rip), %rsi     # 0x12efc8
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movl $0x1, %ebp
jmp 0xfc028
cmpl $0x2, %r14d
jne 0xfc045
xorl %ebp, %ebp
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfc034