// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl $0x18, %esi
callq 0xe969b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
callq 0x884f4
testl %eax, %eax
je 0x851a9
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeba56
movq %rax, 0x10(%r14)
leaq 0xbfcac(%rip), %rsi     # 0x144ba2
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf037a
movq %rax, 0x8(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf0faf
movq %r14, (%rsp)
movq %rax, (%r14)
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r15
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef0d5
testb %al, %al
je 0x85182
xorl %r12d, %r12d
movq %r15, 0x10(%rsp)
leaq 0x1b(%r12), %rax
movq 0x18(%rbx), %rcx
movb $0x1, %bpl
cmpq 0x18(%rcx), %rax
jg 0x851c2
movq %rbx, %rdi
movq %r12, %rsi
callq 0x884f4
testl %eax, %eax
je 0x851c2
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movq %r12, (%r15)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xe958c
movq %rbx, %rdi
leaq 0xb684a(%rip), %rsi     # 0x13b7e3
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef0d5
movzbl %al, %r15d
movq %rbx, %rdi
leaq 0xa6acc(%rip), %rsi     # 0x12ba96
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
leal -0x19(%r15), %edx
movq %rbx, %rdi
leaq 0xa72dc(%rip), %rsi     # 0x12c2be
xorl %eax, %eax
callq 0xe9226
cmpb $0x19, %r15b
jb 0x851c8
leaq (%r15,%r12), %r13
addq $0x2, %r13
movq 0x18(%rbx), %rdi
leaq 0x7(%r12), %rsi
callq 0xef37e
movq %rax, %r14
movq %rbx, %rdi
leaq 0x99275(%rip), %rsi     # 0x11e28b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %r14, 0x20(%rsp)
leaq (%r14,%r13), %rcx
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %rcx
jg 0x851c8
leaq 0x2(%r15), %r14
movq (%rsp), %rbp
movq (%rbp), %rdi
movq %rcx, 0x18(%rsp)
callq 0xf1a5f
movq 0x18(%rbx), %rdi
movq (%rbp), %rcx
movl $0xf, %edx
movq %r12, %rsi
callq 0xefabc
movq 0x18(%rbx), %rdi
leaq -0x7(%r13), %rsi
movq (%rbp), %rcx
movl $0x4, %edx
callq 0xefabc
movq 0x18(%rbx), %rdi
leaq -0x9(%r13), %rsi
movq (%rbp), %rcx
movl $0x1, %edx
callq 0xefabc
movq (%rbp), %rdi
movl $0x1, %esi
callq 0xf11be
movq 0x18(%rbx), %rdi
leaq 0xf(%r12), %rsi
leaq -0x16(%r15), %rdx
movq (%rbp), %rcx
callq 0xefabc
movq (%rbp), %rdi
movl $0x4d, %esi
callq 0xf11be
movq (%rbp), %rdi
movq 0x10(%rbp), %rcx
movl $0x2, %esi
movq %r15, %rdx
callq 0x87005
movq 0x10(%rsp), %r15
movl %eax, 0x10(%r15)
movq %rbx, %rdi
leaq 0xa12ef(%rip), %rsi     # 0x1263d7
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq (%rbp), %rdi
movzbl 0x10(%r15), %edx
movl $0x1, %esi
callq 0xf148e
movq (%rbp), %rdi
movq %r14, %rsi
callq 0xf152a
movq (%rbp), %rdi
movq 0x8(%rbp), %rcx
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xefabc
movq %rbx, %rdi
leaq 0x95186(%rip), %rsi     # 0x11a2b3
movq %r13, %rdx
movq 0x20(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rcx
movq %r13, %rsi
movq %r14, %rdx
callq 0xefabc
movq 0x18(%rsp), %rax
subq (%r15), %rax
movq %rax, 0x8(%r15)
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq 0x8(%r15), %r12
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef0d5
testb %al, %al
jne 0x84f47
leaq 0xc6035(%rip), %rsi     # 0x14b1be
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq (%rsp), %r14
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xf11be
jmp 0x851dd
leaq 0xa70df(%rip), %rsi     # 0x12c28f
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movb $0x1, %bpl
jmp 0x851dd
movq (%rsp), %r14
jmp 0x851dd
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq (%rsp), %r14
movq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
testq %r14, %r14
je 0x8522f
cmpq $0x0, 0x8(%r14)
je 0x8521c
movq 0x10(%r14), %rdi
callq 0xebe1d
movq 0x8(%r14), %rdi
callq 0xf0b13
testb %bpl, %bpl
je 0x8521c
leaq 0xa708c(%rip), %rsi     # 0x12c29e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq (%r14), %rdi
callq 0xf0b13
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq