// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/lha.c
// Function: do_arx_member
static int do_arx_member(deark *c, struct arx_ctx *d, struct arx_member_data *md)
{
	i64 lev0_header_size;
	i64 pos1 = md->member_pos;
	u8 extra_crc_byte;
	int retval = 0;
	int saved_indent_level;

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

	lev0_header_size = (i64)de_getbyte(pos1);
	de_dbg(c, "header size: %d", (int)lev0_header_size);
	if(lev0_header_size<22) goto done;
	md->hdr_endpos = pos1 + 2 + lev0_header_size;

	md->compressed_data_len = de_getu32le(pos1+8);
	de_dbg(c, "compressed size: %"I64_FMT, md->compressed_data_len);

	md->unc_data_len = de_getu32le(pos1+12);
	de_dbg(c, "uncmpr. size: %"I64_FMT, md->unc_data_len);

	if(md->compressed_data_len==0) {
		md->is_uncompressed = 1;
		md->compressed_data_len = md->unc_data_len;
	}

	if(md->hdr_endpos + md->compressed_data_len > c->infile->len) goto done;

	// Just the first byte of the CRC is present, and apparently not even
	// that for non-compressed files.
	extra_crc_byte = de_getbyte(md->hdr_endpos-1);
	de_dbg(c, "crc (reported): 0x??%02x", (UI)extra_crc_byte);

	// Find the correct CRC of the file data.
	arx_recalc_crc(c, d, md);
	de_dbg(c, "crc (calculated): 0x%04x", (UI)md->crc_calc);
	if(!md->is_uncompressed) {
		if((u8)(md->crc_calc & 0xff) != extra_crc_byte) {
			de_warn(c, "CRC mismatch. Conversion to LHA may have failed.");
		}
	}

	// Convert to an LHA header
	dbuf_empty(d->hdr_tmp);

	// Fields through cmpr meth. (We'll patch the checksum, and
	// compression method if necessary, later.)
	dbuf_copy(c->infile, pos1, 7, d->hdr_tmp);

	dbuf_writeu32le(d->hdr_tmp, md->compressed_data_len);
	dbuf_writeu32le(d->hdr_tmp, md->unc_data_len);

	/// This part of the header can be copied as-is.
	dbuf_copy(c->infile, pos1+8+8, lev0_header_size-1-6-8, d->hdr_tmp);

	// CRC
	dbuf_writebyte(d->hdr_tmp, (u8)(md->crc_calc & 0xff));
	dbuf_writebyte(d->hdr_tmp, (u8)((md->crc_calc & 0xff00)>>8));

	if(md->is_uncompressed) {
		dbuf_writebyte_at(d->hdr_tmp, 5, '0'); // lh1 -> lh0
	}

	// Recalculate header checksum
	md->hdr_checksum_calc = lha_calc_checksum(d->hdr_tmp, 2, lev0_header_size,
		d->crco_cksum);
	de_dbg(c, "header checksum (calculated): 0x%02x", (UI)md->hdr_checksum_calc);
	dbuf_writebyte_at(d->hdr_tmp, 1, (u8)md->hdr_checksum_calc);
	dbuf_truncate(d->hdr_tmp, 2+lev0_header_size);

	// Write everything out
	dbuf_copy(d->hdr_tmp, 0, d->hdr_tmp->len, d->lha_outf);
	de_dbg(c, "member data at %"I64_FMT", len=%"I64_FMT, md->hdr_endpos, md->compressed_data_len);
	dbuf_copy(c->infile, md->hdr_endpos, md->compressed_data_len, d->lha_outf);
	md->total_size = 2 + lev0_header_size + md->compressed_data_len;
	retval = 1;

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x100ae0(%rip), %rsi    # 0x1c7392
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xec81e(%rip), %rsi     # 0x1b310e
movb $0x0, %al
callq 0x15b0d0
cmpq $0x16, -0x20(%rbp)
jge 0xc6903
jmp 0xc6c36
movq -0x28(%rbp), %rcx
addq $0x2, %rcx
addq -0x20(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0xe3601(%rip), %rsi     # 0x1a9f4b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0xc, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0xf172b(%rip), %rsi     # 0x1b80af
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xc69b1
movq -0x18(%rbp), %rax
movl $0x1, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
addq 0x18(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xc69d4
jmp 0xc6c36
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
subq $0x1, %rsi
callq 0x165060
movb %al, -0x29(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x29(%rbp), %edx
leaq 0xf16c2(%rip), %rsi     # 0x1b80c1
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xc6c50
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %edx
leaq 0xda65e(%rip), %rsi     # 0x1a1087
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x28(%rax)
jne 0xc6a65
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
andl $0xff, %eax
movzbl %al, %eax
movzbl -0x29(%rbp), %ecx
cmpl %ecx, %eax
je 0xc6a63
movq -0x8(%rbp), %rdi
leaq 0xf167e(%rip), %rsi     # 0x1b80da
movb $0x0, %al
callq 0x15bc10
jmp 0xc6a65
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x169310
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x7, %edx
callq 0x166070
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x168c30
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x168c30
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
addq $0x8, %rsi
addq $0x8, %rsi
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
subq $0x6, %rdx
subq $0x8, %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
callq 0x166070
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
andl $0xff, %eax
movzbl %al, %esi
callq 0x168380
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
andl $0xff00, %eax           # imm = 0xFF00
shrl $0x8, %eax
movzbl %al, %esi
callq 0x168380
movq -0x18(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0xc6b3f
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x5, %esi
movl $0x30, %edx
callq 0x168790
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movl $0x2, %esi
callq 0xc3980
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x30(%rax), %edx
leaq 0xeb2cd(%rip), %rsi     # 0x1b1e44
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x30(%rax), %eax
movl $0x1, %esi
movzbl %al, %edx
callq 0x168790
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x2, %rsi
callq 0x168900
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x166070
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rcx
leaq 0xdf448(%rip), %rsi     # 0x1a6033
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
callq 0x166070
movq -0x20(%rbp), %rcx
addq $0x2, %rcx
movq -0x18(%rbp), %rax
addq 0x18(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x1, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x15b5a0
movl -0x30(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)