// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/lha.c
// Function: do_car_member
static int do_car_member(deark *c, struct car_ctx *d, struct car_member_data *md)
{
	i64 lev1_base_header_size;
	i64 fnlen;
	i64 hdr_endpos;
	i64 compressed_data_len;
	i64 pos1 = md->member_pos;
	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);

	// Figure out where everything is...
	lev1_base_header_size = (i64)de_getbyte(pos1);
	de_dbg(c, "base header size: %d", (int)lev1_base_header_size);
	hdr_endpos = pos1 + 2 + lev1_base_header_size;
	fnlen = lev1_base_header_size - 25;
	de_dbg(c, "implied filename len: %d", (int)fnlen);
	if(fnlen<0) goto done;

	compressed_data_len = de_getu32le(pos1 + 7);
	de_dbg(c, "compressed size: %"I64_FMT, compressed_data_len);
	if(hdr_endpos + compressed_data_len > c->infile->len) goto done;

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

	// Fields through uncmpr_size are the same (we'll patch the checksum later)
	dbuf_copy(c->infile, pos1, 15, d->hdr_tmp);

	dbuf_copy(c->infile, hdr_endpos-7, 4, d->hdr_tmp); // timestamp

	// attribute (low byte)
	dbuf_copy(c->infile, hdr_endpos-9, 1, d->hdr_tmp);
	dbuf_writebyte(d->hdr_tmp, 0x01); // level identifier

	// Fields starting with filename length, through crc
	dbuf_copy(c->infile, pos1+15, 1+fnlen+2, d->hdr_tmp);

	dbuf_writebyte(d->hdr_tmp, 77); // OS ID = 'M' = MS-DOS

	// Recalculate checksum
	md->hdr_checksum_calc = lha_calc_checksum(d->hdr_tmp, 2, lev1_base_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+lev1_base_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, hdr_endpos, compressed_data_len);
	dbuf_copy(c->infile, hdr_endpos, compressed_data_len, d->lha_outf);
	md->total_size = (hdr_endpos-md->member_pos) + compressed_data_len;
	retval = 1;

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0x100e30(%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 -0x40(%rbp), %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0xf12ba(%rip), %rsi     # 0x1b785a
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
addq $0x2, %rax
addq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
subq $0x19, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0xf1aae(%rip), %rsi     # 0x1b8082
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x28(%rbp)
jge 0xc65e7
jmp 0xc67cc
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
addq $0x7, %rsi
callq 0x165540
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0xe393c(%rip), %rsi     # 0x1a9f4b
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
addq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xc6631
jmp 0xc67cc
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x169310
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0xf, %edx
callq 0x166070
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
subq $0x7, %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x4, %edx
callq 0x166070
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
subq $0x9, %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %edx
callq 0x166070
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x1, %esi
callq 0x168380
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
addq $0xf, %rsi
movq -0x28(%rbp), %rdx
addq $0x1, %rdx
addq $0x2, %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
callq 0x166070
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl $0x4d, %esi
callq 0x168380
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movl $0x2, %esi
callq 0xc3980
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edx
leaq 0xeb726(%rip), %rsi     # 0x1b1e44
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%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 -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq 0xdf8a9(%rip), %rsi     # 0x1a6033
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
callq 0x166070
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
subq (%rax), %rcx
addq -0x38(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x1, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x15b5a0
movl -0x44(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)