// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/lha.c
// Function: do_read_ar001_member
static int do_read_ar001_member(deark *c, lctx *d, struct member_data *md)
{
	int saved_indent_level;
	int retval = 0;
	i64 pos1 = md->member_pos;
	i64 pos = pos1;
	i64 basic_hdr_size;
	i64 fnlen;
	i64 first_ext_hdr_size;
	UI cmpr_method;
	u8 cmpr_meth_raw[5];

	de_dbg_indent_save(c, &saved_indent_level);
	de_dbg(c, "member at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	md->hlev = 0; // (hack)
	basic_hdr_size = de_getu16le_p(&pos);
	if(basic_hdr_size==0) {
		de_dbg(c, "end of archive");
		goto done;
	}
	de_dbg(c, "basic header size: %u", (UI)basic_hdr_size);
	if(basic_hdr_size<18) goto done;
	fnlen = basic_hdr_size-18;

	cmpr_method = (UI)de_getu16le_p(&pos);

	de_zeromem(cmpr_meth_raw, 5);
	switch(cmpr_method) {
	case 0: de_memcpy(cmpr_meth_raw, (const void*)"-lh0-", 5); break; // (hack)
	case 1: de_memcpy(cmpr_meth_raw, (const void*)"-lh4-", 5); break; // ...
	}
	md->cmi = de_malloc(c, sizeof(struct cmpr_meth_info));
	get_cmpr_meth_info(cmpr_meth_raw, BASEFMT_LHA, md->cmi);
	de_dbg(c, "cmpr method: %u (%s)", cmpr_method, md->cmi->descr);

	pos += 1; // file type

	// timestamp: This is the time the file was added to the archive, not its
	// last-modified timestamp, so it's not very useful.
	pos += 5;

	md->compressed_data_len = de_getu32le_p(&pos);
	de_dbg(c, "compressed size: %"I64_FMT, md->compressed_data_len);

	md->orig_size = de_getu32le_p(&pos);
	de_dbg(c, "original size: %"I64_FMT, md->orig_size);

	md->crc_reported = (u32)de_getu16le_p(&pos);
	de_dbg(c, "crc16 (reported): 0x%04x", (UI)md->crc_reported);

	read_filename_hlev0(c, d, md, pos, fnlen);
	pos += fnlen;
	make_fullfilename(c, d, md);

	md->hdr_crc_reported = (UI)de_getu16le_p(&pos);
	de_dbg(c, "basic header crc (reported): 0x%04x", (UI)md->hdr_crc_reported);

	do_check_ar001_header_crc(c, d, md, basic_hdr_size);

	first_ext_hdr_size = de_getu16le_p(&pos);
	de_dbg(c, "first ext header size: %"I64_FMT, first_ext_hdr_size);
	if(first_ext_hdr_size) {
		// The ar001 software never uses this feature, so I'm not going to try to
		// support it.
		de_err(c, "Files with extended headers aren't supported");
		goto done;
	}

	md->total_size = pos + md->compressed_data_len - pos1;
	retval = 1;

	md->compressed_data_pos = pos;

	de_dbg(c, "member data at %"I64_FMT", len=%"I64_FMT,
		md->compressed_data_pos, md->compressed_data_len);

	if(!md->cmi->decompressor) {
		de_err(c, "%s: Unsupported compression method: %u",
			ucstring_getpsz_d(md->fullfilename), cmpr_method);
		goto done;
	}

	de_dbg_indent(c, 1);
	do_extract_file(c, d, md);

done:
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x100597(%rip), %rsi    # 0x1c7392
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xc6e4a
movq -0x8(%rbp), %rdi
leaq 0xdd2da(%rip), %rsi     # 0x1a4118
movb $0x0, %al
callq 0x15b0d0
jmp 0xc714a
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0xf12b6(%rip), %rsi     # 0x1b8111
movb $0x0, %al
callq 0x15b0d0
cmpq $0x12, -0x38(%rbp)
jge 0xc6e6e
jmp 0xc714a
movq -0x38(%rbp), %rax
addq $-0x12, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x4c(%rbp)
movb $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x58(%rbp)
testl %eax, %eax
je 0xc6eaf
jmp 0xc6ea5
movl -0x58(%rbp), %eax
subl $0x1, %eax
je 0xc6ec3
jmp 0xc6ed5
movl 0xf1272(%rip), %eax     # 0x1b8127
movl %eax, -0x54(%rbp)
movb 0xf126d(%rip), %al      # 0x1b812b
movb %al, -0x50(%rbp)
jmp 0xc6ed5
movl 0xf1264(%rip), %eax     # 0x1b812d
movl %eax, -0x54(%rbp)
movb 0xf125f(%rip), %al      # 0x1b8131
movb %al, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movl $0x70, %esi
callq 0x15b780
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
leaq -0x54(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
xorl %esi, %esi
callq 0xc39d0
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1b, %rcx
leaq 0xed265(%rip), %rsi     # 0x1b4180
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rdx
leaq 0xe2fe2(%rip), %rsi     # 0x1a9f4b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0xdcf6a(%rip), %rsi     # 0x1a3f09
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x4c(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x4c(%rax), %edx
leaq 0xe5306(%rip), %rsi     # 0x1ac2d8
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %r8
callq 0xc4000
movq -0x40(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xc4790
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x38(%rax), %edx
leaq 0xf10f8(%rip), %rsi     # 0x1b8133
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x38(%rbp), %rcx
callq 0xc7160
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rdx
leaq 0xf10dc(%rip), %rsi     # 0x1b8157
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x48(%rbp)
je 0xc70a0
movq -0x8(%rbp), %rdi
leaq 0xf10de(%rip), %rsi     # 0x1b8172
movb $0x0, %al
callq 0x15bfb0
jmp 0xc714a
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x60(%rax), %rcx
subq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x1, -0x20(%rbp)
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rcx
leaq 0xdef4d(%rip), %rsi     # 0x1a6033
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x8(%rax)
jne 0xc712b
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rdi
callq 0x172650
movq -0x60(%rbp), %rdi
movq %rax, %rdx
movl -0x4c(%rbp), %ecx
leaq 0xf107d(%rip), %rsi     # 0x1b819f
movb $0x0, %al
callq 0x15bfb0
jmp 0xc714a
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xc48c0
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x15b5a0
movl -0x20(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop