// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rdi, %rbx
pushq $0x18
popq %rsi
callq 0xdecaf
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
callq 0x82e4e
testl %eax, %eax
je 0x7fcc1
pushq $0x30
popq %rsi
movq %rbx, %rdi
callq 0xe0ae9
movq %rax, 0x10(%r14)
leaq 0xb81e1(%rip), %rsi     # 0x137c32
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xe4e62
movq %rax, 0x8(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe59cd
movq %r14, 0x8(%rsp)
movq %rax, (%r14)
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r15
addq $0x8, %rax
movq %rax, 0x20(%rsp)
xorl %r12d, %r12d
movq %r15, 0x18(%rsp)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3eb4
testb %al, %al
je 0x7fcf9
leaq 0x1b(%r12), %rax
movq 0x18(%rbx), %rcx
movb $0x1, %bpl
cmpq 0x18(%rcx), %rax
jg 0x7fcda
movq %rbx, %rdi
movq %r12, %rsi
callq 0x82e4e
testl %eax, %eax
je 0x7fcda
movq 0x20(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %r12, (%r15)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xdebae
movq %rbx, %rdi
leaq 0xaed77(%rip), %rsi     # 0x12e86d
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3eb4
movzbl %al, %r15d
movq %rbx, %rdi
leaq 0x9efe9(%rip), %rsi     # 0x11eb0e
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
leal -0x19(%r15), %edx
movq %rbx, %rdi
leaq 0x9f7f9(%rip), %rsi     # 0x11f336
xorl %eax, %eax
callq 0xde896
cmpb $0x19, %r15b
jb 0x7fce1
leaq (%r15,%r12), %r13
addq $0x2, %r13
movq 0x18(%rbx), %rdi
leaq 0x7(%r12), %rsi
callq 0xe409f
movq %rax, %r14
movq %rbx, %rdi
leaq 0x91756(%rip), %rsi     # 0x1112c7
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq %r14, 0x30(%rsp)
leaq (%r14,%r13), %rcx
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %rcx
jg 0x7fce1
leaq 0x2(%r15), %r14
movq 0x8(%rsp), %rbp
movq (%rbp), %rdi
movq %rcx, 0x28(%rsp)
callq 0xe62cf
movq 0x18(%rbx), %rdi
movq (%rbp), %rcx
movq %r12, %rsi
pushq $0xf
popq %rdx
callq 0xe45f4
movq 0x18(%rbx), %rdi
leaq -0x7(%r13), %rsi
movq (%rbp), %rcx
pushq $0x4
popq %rdx
callq 0xe45f4
movq 0x18(%rbx), %rdi
leaq -0x9(%r13), %rsi
movq (%rbp), %rcx
pushq $0x1
popq %rdx
callq 0xe45f4
movq (%rbp), %rdi
pushq $0x1
popq %rsi
callq 0xe5bc5
movq 0x18(%rbx), %rdi
leaq 0xf(%r12), %rsi
leaq -0x16(%r15), %rdx
movq (%rbp), %rcx
callq 0xe45f4
movq (%rbp), %rdi
pushq $0x4d
popq %rsi
callq 0xe5bc5
movq (%rbp), %rdi
movq 0x10(%rbp), %rcx
pushq $0x2
popq %rsi
movq %r15, %rdx
callq 0x81a34
movq 0x18(%rsp), %r15
movl %eax, 0x10(%r15)
movq %rbx, %rdi
leaq 0x997cf(%rip), %rsi     # 0x119407
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq (%rbp), %rdi
movzbl 0x10(%r15), %edx
pushq $0x1
popq %rsi
callq 0xe5e13
movq (%rbp), %rdi
movq %r14, %rsi
callq 0xe5eb2
movq (%rbp), %rdi
movq 0x8(%rbp), %rcx
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xe45f4
movq %rbx, %rdi
leaq 0x8d668(%rip), %rsi     # 0x10d2e3
movq %r13, %rdx
movq 0x30(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rcx
movq %r13, %rsi
movq %r14, %rdx
callq 0xe45f4
movq 0x28(%rsp), %rax
subq (%r15), %rax
movq %rax, 0x8(%r15)
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq 0x8(%r15), %r12
jmp 0x7fa94
leaq 0x9f63f(%rip), %rsi     # 0x11f307
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movb $0x1, %bpl
jmp 0x7fd1f
movq 0x8(%rsp), %r14
jmp 0x7fd1f
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %r15
jmp 0x7fd1f
leaq 0xbe5e5(%rip), %rsi     # 0x13e2e5
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x8(%rsp), %r14
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xe5bc5
movq %rbx, %rdi
movq %r15, %rsi
callq 0xded32
testq %r14, %r14
je 0x7fd71
cmpq $0x0, 0x8(%r14)
je 0x7fd5e
movq 0x10(%r14), %rdi
callq 0xe0e8d
movq 0x8(%r14), %rdi
callq 0xe5591
testb %bpl, %bpl
je 0x7fd5e
leaq 0x9f5c2(%rip), %rsi     # 0x11f316
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq (%r14), %rdi
callq 0xe5591
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq