// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/pklite.c
// Function: do_read_reloc_table_long
static void do_read_reloc_table_long(deark *c, lctx *d, i64 pos1, i64 len)
{
	i64 reloc_count = 0;
	i64 pos = pos1;
	i64 seg = 0;
	i64 endpos = pos1+len;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "reading 'long%s' reloc table at %"I64_FMT,
		(d->scramble_method==2?"/reversed":""), pos1);
	de_dbg_indent(c, 1);
	while(1) {
		UI i;
		UI count;
		i64 offs;

		if(pos+2 > endpos) {
			d->errflag = 1;
			goto done;
		}

		count = (UI)de_getu16le_p(&pos);
		if(count==0xffff) {
			de_dbg2(c, "end-of-data");
			break; // normal completion
		}
		de_dbg2(c, "count: %u", count);

		if(seg > 0xffff) {
			d->errflag = 1;
			goto done;
		}
		de_dbg2(c, "seg: 0x%04x", (UI)seg);

		if(reloc_count+count > MAX_RELOCS) {
			d->errflag = 1;
			goto done;
		}
		if(pos+(i64)count*2 > endpos) {
			d->errflag = 1;
			goto done;
		}

		de_dbg_indent(c, 1);
		for(i=0; i<count; i++) {
			if(d->scramble_method==2) {
				offs = de_getu16be_p(&pos);
			}
			else {
				offs = de_getu16le_p(&pos);
			}
			de_dbg2(c, "offs: 0x%04x", (UI)offs);
			dbuf_writeu16le(d->guest_reloc_table, offs);
			dbuf_writeu16le(d->guest_reloc_table, seg);
			reloc_count++;
		}
		de_dbg_indent(c, -1);
		seg += 0x0fff;
	}

	d->reloc_tbl_endpos = pos;
	de_dbg(c, "cmpr reloc table ends at %"I64_FMT", entries=%d", d->reloc_tbl_endpos,
		(int)reloc_count);

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// 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 $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movzbl 0x4a(%rax), %ecx
leaq 0xba754(%rip), %rdx     # 0x1d0bd0
leaq 0xae037(%rip), %rax     # 0x1c44ba
cmpl $0x2, %ecx
cmoveq %rax, %rdx
movq -0x18(%rbp), %rcx
leaq 0xae001(%rip), %rsi     # 0x1c4496
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x30(%rbp), %rax
addq $0x2, %rax
cmpq -0x40(%rbp), %rax
jle 0x1164c4
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x11667f
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x4c(%rbp)
cmpl $0xffff, -0x4c(%rbp)    # imm = 0xFFFF
jne 0x1164f8
movq -0x8(%rbp), %rdi
leaq 0xadfd8(%rip), %rsi     # 0x1c44c4
movb $0x0, %al
callq 0x15b350
jmp 0x11664d
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %edx
leaq 0xa7649(%rip), %rsi     # 0x1bdb4f
movb $0x0, %al
callq 0x15b350
cmpq $0xffff, -0x38(%rbp)    # imm = 0xFFFF
jle 0x116523
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x11667f
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0xadf9c(%rip), %rsi     # 0x1c44d0
movb $0x0, %al
callq 0x15b350
movq -0x28(%rbp), %rax
movl -0x4c(%rbp), %ecx
addq %rcx, %rax
cmpq $0xffff, %rax           # imm = 0xFFFF
jle 0x116559
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x11667f
movq -0x30(%rbp), %rax
movl -0x4c(%rbp), %ecx
shlq %rcx
addq %rcx, %rax
cmpq -0x40(%rbp), %rax
jle 0x116578
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x11667f
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x11662c
movq -0x10(%rbp), %rax
movzbl 0x4a(%rax), %eax
cmpl $0x2, %eax
jne 0x1165bd
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165210
movq %rax, -0x58(%rbp)
jmp 0x1165d2
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rax
movl %eax, %edx
leaq 0xadef9(%rip), %rsi     # 0x1c44dc
movb $0x0, %al
callq 0x15b350
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdi
movq -0x58(%rbp), %rsi
callq 0x168a10
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x168a10
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x11658d
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x38(%rbp), %rax
addq $0xfff, %rax            # imm = 0xFFF
movq %rax, -0x38(%rbp)
jmp 0x1164aa
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rdx
movq -0x28(%rbp), %rax
movl %eax, %ecx
leaq 0xade71(%rip), %rsi     # 0x1c44e9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x15b5a0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)