// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/lha.c
// Function: de_run_car_lha
static void de_run_car_lha(deark *c, de_module_params *mparams)
{
	struct car_ctx *d = NULL;
	struct car_member_data *md = NULL;
	int ok = 0;
	i64 pos = 0;

	d = de_malloc(c, sizeof(struct car_ctx));

	if(!looks_like_car_member(c, 0)) {
		de_err(c, "Not a CAR file");
		goto done;
	}

	d->crco_cksum = de_crcobj_create(c, DE_CRCOBJ_SUM_BYTES);
	d->lha_outf = dbuf_create_output_file(c, "lzh", NULL, 0);
	d->hdr_tmp = dbuf_create_membuf(c, 0, 0);

	md = de_malloc(c, sizeof(struct car_member_data));
	while(1) {
		if(de_getbyte(pos)==0) {
			de_dbg(c, "trailer at %"I64_FMT, pos);
			dbuf_writebyte(d->lha_outf, 0);
			ok = 1;
			break;
		}
		if(pos+27 > c->infile->len) goto done;
		if(!looks_like_car_member(c, pos)) goto done;

		de_zeromem(md, sizeof(struct car_member_data));
		md->member_pos = pos;
		if(!do_car_member(c, d, md)) goto done;
		pos += md->total_size;
	}

done:
	de_free(c, md);
	if(d) {
		if(d->lha_outf) {
			de_crcobj_destroy(d->crco_cksum);
			dbuf_close(d->lha_outf);
			if(!ok) {
				de_err(c, "Conversion to LHA format failed");
			}
		}
		dbuf_close(d->hdr_tmp);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0x18, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc6450
cmpl $0x0, %eax
jne 0xc1bea
movq -0x8(%rbp), %rdi
leaq 0xf6475(%rip), %rsi     # 0x1b8053
movb $0x0, %al
callq 0x15bfb0
jmp 0xc1d0c
movq -0x8(%rbp), %rdi
movl $0x30, %esi
callq 0x15eac0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
leaq 0x10ef94(%rip), %rsi    # 0x1d0ba2
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x166c60
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x168020
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movl $0x18, %esi
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x165060
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xc1c96
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x11556a(%rip), %rsi    # 0x1d71e1
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0x168380
movl $0x1, -0x24(%rbp)
jmp 0xc1d0a
movq -0x30(%rbp), %rax
addq $0x1b, %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xc1cae
jmp 0xc1d0c
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xc6450
cmpl $0x0, %eax
jne 0xc1cc2
jmp 0xc1d0c
movq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x19140
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xc6520
cmpl $0x0, %eax
jne 0xc1cf5
jmp 0xc1d0c
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xc1c4f
jmp 0xc1d0c
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
cmpq $0x0, -0x18(%rbp)
je 0xc1d78
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xc1d5f
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x15f2e0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1676a0
cmpl $0x0, -0x24(%rbp)
jne 0xc1d5d
movq -0x8(%rbp), %rdi
leaq 0xf630c(%rip), %rsi     # 0x1b8062
movb $0x0, %al
callq 0x15bfb0
jmp 0xc1d5f
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x30, %rsp
popq %rbp
retq
nop