// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/zip.c
// Function: zc_scan_and_read_to_membuf
static void zc_scan_and_read_to_membuf(deark *c, struct zipcombine_ctx *d)
{
	int v;
	struct zip_wcd_ctx *wcdctx = NULL;

	de_dbg(c, "[reading and scanning files]");
	de_dbg_indent(c, 1);

	wcdctx = de_malloc(c, sizeof(struct zip_wcd_ctx));
	wcdctx->userdata = (void*)d;
	wcdctx->multisegment_mode = 1;
	wcdctx->cbfn = wcd_callback_for_cdpadding;
	wcdctx->max_entries = d->eocd.cdir_num_entries_total;

	// TODO?: For convenience, we read all the segments into memory.
	// It wouldn't be too hard to avoid doing that, and only read the
	// central dir. (The most inconvenient issue might be where we
	// validate that the local dir signatures are present.)

	d->f = dbuf_create_membuf(c, 1048576, 0);

	for(v=0; v<d->num_segments; v++) {
		dbuf *tmpf;
		i64 newsize;

		tmpf = de_mp_acquire_dbuf(c, v);
		if(!tmpf) {
			d->errflag = 1;
			goto done;
		}

		d->segments[v].file_size = zc_get_real_seg_size(c, d, wcdctx, tmpf, v);
		if(d->errflag) goto done;

		d->segments[v].starting_offset = d->f->len;
		de_dbg(c, "segment %d: [at %"I64_FMT"] size=%"I64_FMT, v,
			d->segments[v].starting_offset, d->segments[v].file_size);

		newsize = tmpf->len + d->segments[v].file_size;
		if((newsize > ZC_MAX_COMBINED_SIZE || newsize > DE_MAX_MALLOC)) {
			d->errflag = 1;
			d->need_errmsg = 1;
			goto done;
		}
		dbuf_copy(tmpf, 0, d->segments[v].file_size, d->f);
		de_mp_release_dbuf(c, v, &tmpf);
	}

done:
	de_free(c, wcdctx);
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x86d0f(%rip), %rsi     # 0x1cefb2
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movl $0x68, %esi
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movb $0x1, 0x15(%rax)
movq -0x20(%rbp), %rax
leaq 0x417(%rip), %rcx       # 0x148700
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movl $0x100000, %esi         # imm = 0x100000
xorl %edx, %edx
callq 0x168020
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x78(%rax)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x148498
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x15f890
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x148351
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
jmp 0x14849a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x14(%rbp), %r8d
callq 0x148760
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x14(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0x148394
jmp 0x14849a
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x14(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x14(%rbp), %rsi
shlq $0x4, %rsi
addq %rsi, %rax
movq (%rax), %r8
leaq 0x86bd4(%rip), %rsi     # 0x1cefcf
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x80(%rcx), %rcx
movslq -0x14(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
addq (%rcx), %rax
movq %rax, -0x30(%rbp)
cmpq $0xbebc200, -0x30(%rbp) # imm = 0xBEBC200
jg 0x14843b
cmpq $0x1dcd6500, -0x30(%rbp) # imm = 0x1DCD6500
jle 0x14844c
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x1(%rax)
jmp 0x14849a
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x14(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x166070
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x28(%rbp), %rdx
callq 0x15f970
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x14831e
jmp 0x14849a
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)