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

	de_dbg_indent_save(c, &saved_indent_level);
	if(d->num_paths > 255) {
		// Number of paths can't be >255 in the known versions of the format,
		// because paths are indexed by a 1-byte int.
		d->num_paths = 255;
	}

	if(d->num_paths <= 0) {
		d->paths_segment_len = 0;
		d->paths_segment_len_known = 1;
		retval = 1;
		goto done;
	}

	d->paths = de_mallocarray(c, d->num_paths, sizeof(de_ucstring*));
	for(i=0; i<d->num_paths; i++) {
		d->paths[i] = ucstring_create(c);
	}

	de_dbg(c, "paths at %"I64_FMT, d->paths_segment_pos);
	de_dbg_indent(c, 1);

	pos = d->paths_segment_pos;
	for(i=0; i<d->num_paths; i++) {
		int ret;
		i64 foundpos = 0;
		i64 path_len;

		if(pos >= c->infile->len) goto done;
		ret = dbuf_search_byte(c->infile, 0x00, pos, c->infile->len-pos, &foundpos);
		if(!ret) goto done;
		path_len = foundpos - pos;
		if(path_len > 260) goto done;
		dbuf_read_to_ucstring(c->infile, pos, path_len, d->paths[i], 0, d->da->input_encoding);
		de_dbg(c, "path #%d: \"%s\"", (int)(i+1), ucstring_getpsz_d(d->paths[i]));
		de_arch_fixup_path(d->paths[i], 0x1);
		pos = foundpos + 1;
	}
	d->paths_segment_len = pos - d->paths_segment_pos;
	d->paths_segment_len_known = 1;
	retval = 1;
done:
	if(!retval) {
		de_warn(c, "Could not read path table");
	}
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rax
cmpq $0xff, 0x18(%rax)
jle 0x8755e
movq -0x10(%rbp), %rax
movq $0xff, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jg 0x8758c
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x28(%rax)
movl $0x1, -0x24(%rbp)
jmp 0x8777a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movl $0x8, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x875ed
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x875b5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
leaq 0x1274a7(%rip), %rsi    # 0x1aeaa7
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0x87754
movq $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jl 0x8765a
jmp 0x8777a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rcx
subq -0x18(%rbp), %rcx
xorl %esi, %esi
leaq -0x38(%rbp), %r8
callq 0x1667a0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x8768f
jmp 0x8777a
movq -0x38(%rbp), %rax
subq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x104, -0x40(%rbp)     # imm = 0x104
jle 0x876aa
jmp 0x8777a
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x18(%rax), %r9d
xorl %r8d, %r8d
callq 0x1669f0
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x172650
movq -0x50(%rbp), %rdi
movl -0x44(%rbp), %edx
movq %rax, %rcx
leaq 0x12739e(%rip), %rsi    # 0x1aeab4
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl $0x1, %esi
callq 0x17c2b0
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x87629
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
subq 0x30(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x28(%rax)
movl $0x1, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x87792
movq -0x8(%rbp), %rdi
leaq 0x127338(%rip), %rsi    # 0x1aeac3
movb $0x0, %al
callq 0x15bc10
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x15b5a0
movl -0x24(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)