// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/clp.c
// Function: do_read_index
static int do_read_index(deark *c, lctx *d)
{
	int retval = 0;
	i64 i;

	// d->num_items is untrusted, but can be no more than 64K.
	d->index_array = de_mallocarray(c, d->num_items, sizeof(struct index_item));

	de_dbg(c, "[scanning index]");
	for(i=0; i<d->num_items; i++) {
		struct index_item *ii;
		i64 pos;

		ii = &d->index_array[i];
		pos = d->index_pos + i*d->index_item_len;

		if(d->sig==0xc350) {
			ii->clpfmt = (UI)de_getu16le_p(&pos);
		}
		else {
			ii->clpfmt = (UI)de_getu32le_p(&pos);
		}
		ii->dlen = de_getu32le_p(&pos);
		ii->dpos = de_getu32le_p(&pos);

		if(ii->clpfmt==0) ii->dlen = 0;

		if(ii->dlen>0) {
			// Sanity check. I don't know if the data segments have to be in order and
			// non-overlapping, but for now I'm assuming they do.
			if((ii->dpos < d->next_avail_dpos) || (ii->dpos+ii->dlen > c->infile->len)) {
				de_err(c, "item %u: Bad data segment position", (UI)i);
				goto done;
			}
			d->next_avail_dpos = ii->dpos+ii->dlen;
		}
	}
	retval = 1;
done:
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movl $0x18, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
leaq 0x125d92(%rip), %rsi    # 0x1aed25
movb $0x0, %al
callq 0x15b0d0
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jge 0x890f4
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x10(%rbp), %rdx
imulq 0x20(%rdx), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0xc350, (%rax)         # imm = 0xC350
jne 0x8900c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x89026
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x89074
movq -0x28(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jle 0x890e1
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jl 0x890af
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x28(%rbp), %rcx
addq 0x10(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x890c9
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0x125c76(%rip), %rsi    # 0x1aed36
movb $0x0, %al
callq 0x15bfb0
jmp 0x890fb
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x28(%rbp), %rax
addq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0x890e3
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x88fa2
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)