// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq 0x5cd2e(%rip), %rsi     # 0x1d6610
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jle 0x1798fc
jmp 0x179a36
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq $0x0, -0x30(%rbp)
cmpq $0x10000, -0x30(%rbp)   # imm = 0x10000
jge 0x179a1a
movq -0x28(%rbp), %rax
cmpq -0x18(%rbp), %rax
jl 0x17992f
jmp 0x179a36
movq -0x48(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x50(%rbp), %rax
movl %eax, %ecx
leaq 0x5cce2(%rip), %rsi     # 0x1d6639
movb $0x0, %al
callq 0x15b350
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0x1799f9
movq -0x28(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x179991
cmpl $0xffff, -0x34(%rbp)    # imm = 0xFFFF
jl 0x179996
jmp 0x179a36
movq -0x48(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x60(%rbp), %rax
movl %eax, %ecx
leaq 0x5cc8e(%rip), %rsi     # 0x1d664c
movb $0x0, %al
callq 0x15b350
movq -0x20(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x168a10
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x168a10
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x179974
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x30(%rbp), %rax
addq $0x1000, %rax           # imm = 0x1000
movq %rax, -0x30(%rbp)
jmp 0x179912
movl $0x1, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
leaq 0x41360(%rip), %rsi     # 0x1bad8f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x15b5a0
movl -0x38(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)