// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/hlp.c
// Function: do_file_Phrases
static void do_file_Phrases(deark *c, lctx *d, i64 pos1, i64 len)
{
	i64 pos;
	i64 s0, s1, s2;
	i64 phrase_data_pos;
	i64 phrase_data_cmpr_len;
	i64 phrase_data_uncmpr_len = 0;
	i64 phrase_offset_table_pos;
	i64 phrase_offset_table_len;
	UI k;
	int is_MVB_format = 0;
	int is_compressed = 0;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	if(!d->extract_text) goto done;

	de_dbg(c, "Phrases data at %"I64_FMT", len=%"I64_FMT, pos1, len);
	de_dbg_indent(c, 1);
	if(len<6) goto done;

	s0 = de_getu16le(pos1);
	s1 = de_getu16le(pos1+2);
	s2 = de_getu16le(pos1+4);

	if(s0==0x0800 && s1!=0x0100 && s2==0x0100) {
		is_MVB_format = 1;
	}
	else if(s1==0x0100) {
		;
	}
	else {
		de_err(c, "Unknown Phrases format");
		goto done;
	}
	de_dbg(c, "MVB format: %d", is_MVB_format);
	if(is_MVB_format) {
		de_err(c, "Unsupported Phrases format");
		goto done;
	}

	d->num_phrases = (UI)s0;
	de_dbg(c, "num phrases: %u", d->num_phrases);
	pos = pos1+4;

	if(d->ver_minor>16) {
		is_compressed = 1;
	}
	de_dbg(c, "Phrases are lzw-compressed: %d", is_compressed);

	if(is_compressed) {
		phrase_data_uncmpr_len = de_getu32le_p(&pos);
		de_dbg(c, "decompressed len (reported): %"I64_FMT, phrase_data_uncmpr_len);
	}

	// Phrase offsets are measured from the start of the offset table.
	phrase_offset_table_pos = pos;
	phrase_offset_table_len = ((i64)d->num_phrases+1)*2;
	de_dbg(c, "offset table at %"I64_FMT", len=%"I64_FMT, phrase_offset_table_pos,
		phrase_offset_table_len);

	phrase_data_pos = phrase_offset_table_pos + phrase_offset_table_len;
	phrase_data_cmpr_len = pos1+len - phrase_data_pos; // (before any decompression)
	if(phrase_data_cmpr_len<0) goto done;
	if(!is_compressed) {
		phrase_data_uncmpr_len = phrase_data_cmpr_len;
	}

	d->phrase_info = de_mallocarray(c, (i64)d->num_phrases, sizeof(struct phrase_item));
	for(k=0; k<d->num_phrases+1; k++) {
		u32 offs;

		offs = (u32)de_getu16le_p(&pos);
		offs -= (u32)phrase_offset_table_len;

		if(k<d->num_phrases) {
			d->phrase_info[k].pos = offs;
		}
		if(k>=1) {
			d->phrase_info[k-1].len = offs - d->phrase_info[k-1].pos;
		}
	}
	if(c->debug_level>=2) {
		dump_phrase_offset_table(c, d);
	}

	de_dbg(c, "phrase data at %"I64_FMT", len=%"I64_FMT, phrase_data_pos, phrase_data_cmpr_len);

	if(is_compressed) {
		decompress_Phrases(c, d, phrase_data_pos, phrase_data_cmpr_len, phrase_data_uncmpr_len);
	}
	else {
		dbuf_copy(c->infile, phrase_data_pos, phrase_data_cmpr_len, d->phrases_data);
	}

	d->valid_Phrases_file = 1;

done:
	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 $0x0, -0x58(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x7beed
jmp 0x7c230
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x1314fc(%rip), %rsi    # 0x1ad3fc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
cmpq $0x6, -0x20(%rbp)
jge 0x7bf21
jmp 0x7c230
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165280
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
callq 0x165280
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x165280
movq %rax, -0x40(%rbp)
cmpq $0x800, -0x30(%rbp)     # imm = 0x800
jne 0x7bf8f
cmpq $0x100, -0x38(%rbp)     # imm = 0x100
je 0x7bf8f
cmpq $0x100, -0x40(%rbp)     # imm = 0x100
jne 0x7bf8f
movl $0x1, -0x70(%rbp)
jmp 0x7bfb4
cmpq $0x100, -0x38(%rbp)     # imm = 0x100
jne 0x7bf9b
jmp 0x7bfb2
movq -0x8(%rbp), %rdi
leaq 0x131473(%rip), %rsi    # 0x1ad419
movb $0x0, %al
callq 0x15bfb0
jmp 0x7c230
jmp 0x7bfb4
movq -0x8(%rbp), %rdi
movl -0x70(%rbp), %edx
leaq 0x13146e(%rip), %rsi    # 0x1ad430
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x70(%rbp)
je 0x7bfe6
movq -0x8(%rbp), %rdi
leaq 0x131465(%rip), %rsi    # 0x1ad43f
movb $0x0, %al
callq 0x15bfb0
jmp 0x7c230
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xf8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xf8(%rax), %edx
leaq 0x13144f(%rip), %rsi    # 0x1ad45a
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x10, 0x8c(%rax)
jle 0x7c032
movl $0x1, -0x74(%rbp)
movq -0x8(%rbp), %rdi
movl -0x74(%rbp), %edx
leaq 0x13142a(%rip), %rsi    # 0x1ad46a
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x74(%rbp)
je 0x7c078
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x165580
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rdx
leaq 0x131418(%rip), %rsi    # 0x1ad489
movb $0x0, %al
callq 0x15b0d0
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movl 0xf8(%rax), %eax
addq $0x1, %rax
shlq %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rdx
movq -0x68(%rbp), %rcx
leaq 0x131402(%rip), %rsi    # 0x1ad4aa
movb $0x0, %al
callq 0x15b0d0
movq -0x60(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
addq -0x20(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jge 0x7c0d7
jmp 0x7c230
cmpl $0x0, -0x74(%rbp)
jne 0x7c0e5
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xf8(%rax), %eax
movl %eax, %esi
movl $0x8, %edx
callq 0x15c450
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x100(%rax)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0xf8(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0x7c1b7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x7c(%rbp)
movq -0x68(%rbp), %rax
movl %eax, %ecx
movl -0x7c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x7c(%rbp)
movl -0x6c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xf8(%rcx), %eax
jae 0x7c171
movl -0x7c(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x100(%rax), %rax
movl -0x6c(%rbp), %ecx
movl %edx, (%rax,%rcx,8)
cmpl $0x1, -0x6c(%rbp)
jb 0x7c1a7
movl -0x7c(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x100(%rax), %rax
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
subl (%rax,%rcx,8), %edx
movq -0x10(%rbp), %rax
movq 0x100(%rax), %rax
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl %edx, 0x4(%rax,%rcx,8)
jmp 0x7c1a9
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x7c114
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
jl 0x7c1cd
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x7eb50
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
leaq 0x1312e7(%rip), %rsi    # 0x1ad4c7
movb $0x0, %al
callq 0x15b0d0
cmpl $0x0, -0x74(%rbp)
je 0x7c208
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %r8
callq 0x7ebc0
jmp 0x7c228
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0xf0(%rax), %rcx
callq 0x166070
movq -0x10(%rbp), %rax
movb $0x1, 0x5d(%rax)
movq -0x8(%rbp), %rdi
movl -0x78(%rbp), %esi
callq 0x15b5a0
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)