// File: /workspace/github_c_makefile_star2_O3/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
movl $0x18, %esi
callq 0xe8b2b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
callq 0x87def
testl %eax, %eax
je 0x84b04
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeb499
movq %rax, 0x10(%r14)
leaq 0xc083c(%rip), %rsi     # 0x145082
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xefda1
movq %rax, 0x8(%r14)
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf09c5
movq %r14, 0x8(%rsp)
movq %rax, (%r14)
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r15
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeead3
testb %al, %al
je 0x84adc
movq %r15, %rax
addq $0x8, %rax
movq %rax, 0x20(%rsp)
xorl %r12d, %r12d
movq %r15, 0x18(%rsp)
leaq 0x1b(%r12), %rax
movq 0x18(%rbx), %rcx
movb $0x1, %bpl
cmpq 0x18(%rcx), %rax
jg 0x84b29
movq %rbx, %rdi
movq %r12, %rsi
callq 0x87def
testl %eax, %eax
je 0x84b29
movq 0x20(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %r12, (%r15)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe8a1c
movq %rbx, %rdi
leaq 0xb726b(%rip), %rsi     # 0x13bb5d
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeead3
movzbl %al, %r15d
movq %rbx, %rdi
leaq 0xa745b(%rip), %rsi     # 0x12bd7e
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
leal -0x19(%r15), %edx
movq %rbx, %rdi
leaq 0xa7c6b(%rip), %rsi     # 0x12c5a6
xorl %eax, %eax
callq 0xe8617
cmpb $0x19, %r15b
jb 0x84b30
leaq (%r15,%r12), %r13
addq $0x2, %r13
movq 0x18(%rbx), %rdi
leaq 0x7(%r12), %rsi
callq 0xeed61
movq %rax, %r14
movq %rbx, %rdi
leaq 0x99a2c(%rip), %rsi     # 0x11e39b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq %r14, 0x30(%rsp)
leaq (%r14,%r13), %rcx
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %rcx
jg 0x84b30
leaq 0x2(%r15), %r14
movq 0x8(%rsp), %rbp
movq (%rbp), %rdi
movq %rcx, 0x28(%rsp)
callq 0xf145f
movq 0x18(%rbx), %rdi
movq (%rbp), %rcx
movl $0xf, %edx
movq %r12, %rsi
callq 0xef481
movq 0x18(%rbx), %rdi
leaq -0x7(%r13), %rsi
movq (%rbp), %rcx
movl $0x4, %edx
callq 0xef481
movq 0x18(%rbx), %rdi
leaq -0x9(%r13), %rsi
movq (%rbp), %rcx
movl $0x1, %edx
callq 0xef481
movq (%rbp), %rdi
movl $0x1, %esi
callq 0xf0bd6
movq 0x18(%rbx), %rdi
leaq 0xf(%r12), %rsi
leaq -0x16(%r15), %rdx
movq (%rbp), %rcx
callq 0xef481
movq (%rbp), %rdi
movl $0x4d, %esi
callq 0xf0bd6
movq (%rbp), %rdi
movq 0x10(%rbp), %rcx
movl $0x2, %esi
movq %r15, %rdx
callq 0x8694b
movq 0x18(%rsp), %r15
movl %eax, 0x10(%r15)
movq %rbx, %rdi
leaq 0xa1bc5(%rip), %rsi     # 0x126607
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq (%rbp), %rdi
movzbl 0x10(%r15), %edx
movl $0x1, %esi
callq 0xf0e8b
movq (%rbp), %rdi
movq %r14, %rsi
callq 0xf0f27
movq (%rbp), %rdi
movq 0x8(%rbp), %rcx
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xef481
movq %rbx, %rdi
leaq 0x9594c(%rip), %rsi     # 0x11a3d3
movq %r13, %rdx
movq 0x30(%rsp), %r14
movq %r14, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rcx
movq %r13, %rsi
movq %r14, %rdx
callq 0xef481
movq 0x28(%rsp), %rax
subq (%r15), %rax
movq %rax, 0x8(%r15)
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq 0x8(%r15), %r12
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeead3
testb %al, %al
jne 0x848a4
leaq 0xc6cd2(%rip), %rsi     # 0x14b7b5
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%rsp), %r14
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xf0bd6
jmp 0x84b46
leaq 0xa7a6c(%rip), %rsi     # 0x12c577
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe8be2
movb $0x1, %bpl
testq %r14, %r14
jne 0x84b51
jmp 0x84b93
movq 0x8(%rsp), %r14
jmp 0x84b46
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq 0x8(%rsp), %r14
movq 0x18(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe8be2
cmpq $0x0, 0x8(%r14)
je 0x84b80
movq 0x10(%r14), %rdi
callq 0xeb858
movq 0x8(%r14), %rdi
callq 0xf052b
testb %bpl, %bpl
je 0x84b80
leaq 0xa7a10(%rip), %rsi     # 0x12c586
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq (%r14), %rdi
callq 0xf052b
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq