// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/hlp.c
// Function: do_leaf_page
static void do_leaf_page(deark *c, lctx *d, i64 pos1, i64 *pnext_page)
{
	i64 n;
	i64 pos = pos1;
	i64 foundpos;
	i64 num_entries;
	i64 file_offset;
	i64 k;
	struct de_stringreaderdata *fn_srd = NULL;
	enum hlp_filetype file_type;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	n = de_getu16le_p(&pos); // "Unused"
	de_dbg(c, "free bytes at end of this page: %d", (int)n);

	num_entries = de_geti16le_p(&pos);
	de_dbg(c, "NEntries: %d", (int)num_entries);

	n = de_geti16le_p(&pos);
	de_dbg(c, "PreviousPage: %d", (int)n);

	n = de_geti16le_p(&pos);
	de_dbg(c, "NextPage: %d", (int)n);
	if(pnext_page) *pnext_page = n;

	for(k=0; k<num_entries; k++) {
		int pass_for_this_file;

		de_dbg(c, "entry[%d]", (int)k);
		de_dbg_indent(c, 1);

		if(!dbuf_search_byte(c->infile, 0x00, pos, 260, &foundpos)) {
			de_err(c, "Malformed leaf page at %"I64_FMT, pos1);
			goto done;
		}

		if(fn_srd) {
			de_destroy_stringreaderdata(c, fn_srd);
		}
		fn_srd = dbuf_read_string(c->infile, pos, foundpos-pos, foundpos-pos, 0, d->input_encoding);
		de_dbg(c, "FileName: \"%s\"", ucstring_getpsz_d(fn_srd->str));
		pos = foundpos + 1;

		file_offset = de_geti32le_p(&pos);
		de_dbg(c, "FileOffset: %"I64_FMT, file_offset);

		file_type = filename_to_filetype(c, d, fn_srd->sz);

		switch(file_type) {
		case FILETYPE_SYSTEM:
			d->found_system_file = 1;
			d->offset_of_system_file = file_offset;
			pass_for_this_file = 1;
			break;
		case FILETYPE_TOPIC:
			d->found_TOPIC_file = 1;
			d->offset_of_TOPIC = file_offset;
			pass_for_this_file = 1;
			break;
		case FILETYPE_PHRASES:
			d->found_Phrases_file = 1;
			d->offset_of_Phrases = file_offset;
			pass_for_this_file = 1;
			break;
		case FILETYPE_PHRINDEX:
			d->found_PhrIndex_file = 1;
			d->offset_of_PhrIndex = file_offset;
			pass_for_this_file = 1;
			break;
		case FILETYPE_PHRIMAGE:
			d->found_PhrImage_file = 1;
			d->offset_of_PhrImage = file_offset;
			pass_for_this_file = 1;
			break;
		default:
			pass_for_this_file = 2;
		}

		if(d->pass==2 && d->extract_raw_streams) {
			do_file(c, d, file_offset, file_type, 1, fn_srd);
		}
		else if(d->pass==2 && pass_for_this_file==2) {
			do_file(c, d, file_offset, file_type, 0, fn_srd);
		}

		de_dbg_indent(c, -1);
	}

done:
	de_destroy_stringreaderdata(c, fn_srd);
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x13019f(%rip), %rsi    # 0x1acf9d
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl %eax, %edx
leaq 0x130195(%rip), %rsi    # 0x1acfc0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x130134(%rip), %rsi    # 0x1acf8c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1653f0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x130148(%rip), %rsi    # 0x1acfcd
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x20(%rbp)
je 0x7ce9e
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0x7d124
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %edx
leaq 0x130115(%rip), %rsi    # 0x1acfda
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rdx
xorl %esi, %esi
movl $0x104, %ecx            # imm = 0x104
leaq -0x38(%rbp), %r8
callq 0x1667a0
cmpl $0x0, %eax
jne 0x7cf16
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x1300da(%rip), %rsi    # 0x1acfe4
movb $0x0, %al
callq 0x15bfb0
jmp 0x7d126
cmpq $0x0, -0x58(%rbp)
je 0x7cf2a
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x166830
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rcx
subq %rsi, %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r9d
xorl %r8d, %r8d
movl %r8d, -0x78(%rbp)
movq %rcx, %rdx
callq 0x1664c0
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x80(%rbp), %rdi
movq %rax, %rdx
movl -0x78(%rbp), %eax
leaq 0x130082(%rip), %rsi    # 0x1acfff
movb %al, -0x71(%rbp)
callq 0x15b0d0
movq -0x38(%rbp), %rax
incq %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165670
movq %rax, %rcx
movb -0x71(%rbp), %al
movq %rcx, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rdx
leaq 0x130054(%rip), %rsi    # 0x1ad00e
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x7d350
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x70(%rbp)
subl $0x5, %eax
ja 0x7d094
movq -0x70(%rbp), %rax
leaq 0x12fb9d(%rip), %rcx    # 0x1acb94
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movb $0x1, 0x58(%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movl $0x1, -0x64(%rbp)
jmp 0x7d09b
movq -0x10(%rbp), %rax
movb $0x1, 0x5c(%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x80(%rax)
movl $0x1, -0x64(%rbp)
jmp 0x7d09b
movq -0x10(%rbp), %rax
movb $0x1, 0x59(%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movl $0x1, -0x64(%rbp)
jmp 0x7d09b
movq -0x10(%rbp), %rax
movb $0x1, 0x5a(%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movl $0x1, -0x64(%rbp)
jmp 0x7d09b
movq -0x10(%rbp), %rax
movb $0x1, 0x5b(%rax)
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x78(%rax)
movl $0x1, -0x64(%rbp)
jmp 0x7d09b
movl $0x2, -0x64(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0xa4(%rax)
jne 0x7d0d5
movq -0x10(%rbp), %rax
movzbl 0xc(%rax), %eax
cmpl $0x0, %eax
je 0x7d0d5
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
movl -0x5c(%rbp), %ecx
movq -0x58(%rbp), %r9
movl $0x1, %r8d
callq 0x7b630
jmp 0x7d105
movq -0x10(%rbp), %rax
cmpl $0x2, 0xa4(%rax)
jne 0x7d103
cmpl $0x2, -0x64(%rbp)
jne 0x7d103
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
movl -0x5c(%rbp), %ecx
movq -0x58(%rbp), %r9
xorl %r8d, %r8d
callq 0x7b630
jmp 0x7d105
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x7cea6
jmp 0x7d126
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x166830
movq -0x8(%rbp), %rdi
movl -0x60(%rbp), %esi
callq 0x15b5a0
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)