// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/hlp.c
// Function: do_file
static void do_file(deark *c, lctx *d, i64 pos1, enum hlp_filetype file_fmt, int force_extract,
	struct de_stringreaderdata *fn)
{
	i64 reserved_space;
	i64 used_space;
	i64 pos = pos1;
	UI fileflags;

	de_dbg(c, "file at %"I64_FMT", type=%s", pos1, file_type_to_type_name(file_fmt));
	de_dbg_indent(c, 1);

	// FILEHEADER
	reserved_space = de_getu32le_p(&pos);
	de_dbg(c, "ReservedSpace: %"I64_FMT, reserved_space);

	used_space = de_getu32le_p(&pos);
	de_dbg(c, "UsedSpace: %"I64_FMT, used_space);

	fileflags = (UI)de_getbyte_p(&pos);
	de_dbg(c, "FileFlags: 0x%02x", fileflags);

	if(used_space==0) goto done;
	if(pos+used_space > c->infile->len) {
		de_err(c, "Object at %"I64_FMT" (len %"I64_FMT") goes beyond end of file",
			pos, used_space);
		goto done;
	}

	if(force_extract) {
		do_extract_raw_file(c, d, pos, used_space, fn);
		goto done;
	}

	switch(file_fmt) {
	case FILETYPE_INTERNALDIR:
		do_file_INTERNALDIR(c, d, pos, used_space);
		break;
	case FILETYPE_TOPIC:
		do_file_TOPIC(c, d, pos, used_space);
		break;
	case FILETYPE_PHRASES:
		do_file_Phrases(c, d, pos, used_space);
		break;
	case FILETYPE_PHRINDEX:
		do_file_PhrIndex(c, d, pos, used_space);
		break;
	case FILETYPE_PHRIMAGE:
		do_file_PhrImage(c, d, pos, used_space);
		break;
	case FILETYPE_SYSTEM:
		do_file_SYSTEM(c, d, pos, used_space);
		break;
	case FILETYPE_SHG:
		d->has_shg = 1;
		do_file_SHG(c, d, pos, used_space);
		break;
	case FILETYPE_EXTRACTABLE:
		do_extract_raw_file(c, d, pos, used_space, fn);
		break;
	default: ;
	}

done:
	de_dbg_indent(c, -1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, 0x8(%rsp)
movl %r8d, %ebp
movl %ecx, %r13d
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x10(%rsp), %r14
movq %rdx, (%r14)
movslq %ecx, %rax
leaq 0xca140(%rip), %rsi     # 0x120f8c
movslq -0x4(%rsi,%rax,4), %rcx
addq %rsi, %rcx
leaq 0xca230(%rip), %rsi     # 0x12108b
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef3a0
leaq 0xca21e(%rip), %rsi     # 0x1210a0
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef3a0
movq %rax, %r12
leaq 0xca20e(%rip), %rsi     # 0x1210b3
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xef14d
movzbl %al, %edx
leaq 0xca1fa(%rip), %rsi     # 0x1210c2
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
testq %r12, %r12
je 0x56f19
movq 0x10(%rsp), %rdx
movq %r12, %rax
addq %rdx, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x56f02
leaq 0xca1e1(%rip), %rsi     # 0x1210d4
movq %rbx, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0xe9df7
jmp 0x56f19
testl %ebp, %ebp
je 0x56f35
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
movq 0x8(%rsp), %r8
callq 0x56fd0
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addl $-0x2, %r13d
cmpl $0x7, %r13d
ja 0x56f19
leaq 0xc9ff6(%rip), %rax     # 0x120f3c
movslq (%rax,%r13,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x57061
jmp 0x56f19
movl $0x1, 0xa8(%r15)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x58e4c
jmp 0x56f19
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x5897a
jmp 0x56f19
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x579f7
jmp 0x56f19
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x588db
jmp 0x56f19
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x58397
jmp 0x56f19
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rcx
callq 0x58668
jmp 0x56f19