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

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

	if(!looks_like_arx_member(c, 0)) {
		de_err(c, "Not an ARX file");
		goto done;
	}

	d->crco = de_crcobj_create(c, DE_CRCOBJ_CRC16_ARC);
	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 arx_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_arx_member(c, pos)) goto done;

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
movl $0x20, %esi
callq 0xe8b2b
movq %rax, %r14
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0x87e82
testl %eax, %eax
je 0x85034
movq %rbx, %rdi
movl $0x21, %esi
callq 0xeb499
movq %rax, 0x10(%r14)
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeb499
movq %rax, 0x18(%r14)
leaq 0xc0427(%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 %rax, (%r14)
movl $0x38, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r15
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xeead3
testb %al, %al
je 0x85010
movq %r15, %rax
addq $0x8, %rax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
leaq 0x1b(%r12), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x85070
movq %r12, %rsi
callq 0x87e82
testl %eax, %eax
je 0x85070
movq 0x8(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq %r12, (%r15)
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0xe8a1c
movq %rbx, %rdi
leaq 0xb6e5e(%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, %ebp
movq %rbx, %rdi
leaq 0xa2c37(%rip), %rsi     # 0x127966
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
cmpb $0x16, %bpl
jb 0x85064
leaq (%r12,%rbp), %rax
addq $0x2, %rax
movq %rax, 0x10(%r15)
movq 0x18(%rbx), %rdi
leaq 0x8(%r12), %rsi
callq 0xeed61
movq %rax, 0x18(%r15)
movq %rbx, %rdi
leaq 0x99631(%rip), %rsi     # 0x11e39b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0xc(%r12), %rsi
callq 0xeed61
movq %rax, 0x20(%r15)
movq %rbx, %rdi
leaq 0xa7843(%rip), %rsi     # 0x12c5d3
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r15), %rax
testq %rax, %rax
jne 0x84db3
movl $0x1, 0x28(%r15)
movq 0x20(%r15), %rax
movq %rax, 0x18(%r15)
movq 0x10(%r15), %rsi
addq %rsi, %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x85064
decq %rsi
callq 0xeead3
movl %eax, %r13d
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xa7805(%rip), %rsi     # 0x12c5e5
xorl %eax, %eax
callq 0xe8617
movq 0x10(%r14), %rdi
callq 0xeb7fe
cmpl $0x0, 0x28(%r15)
je 0x84e11
movq 0x10(%r14), %rdi
movq 0x18(%rbx), %rsi
movq 0x10(%r15), %rdx
movq 0x18(%r15), %rcx
callq 0xeb944
jmp 0x84e9e
movq 0x20(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf13d3
movb %r13b, 0x3(%rsp)
movq %rax, %r13
movq 0x10(%r14), %rdx
movq %rax, %rdi
leaq 0x6c61c(%rip), %rsi     # 0xf1451
callq 0xf1412
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x48(%rsp), %rcx
callq 0xfa1dc
movq 0x18(%rbx), %rax
movq %rax, 0x28(%rsp)
movups 0x10(%r15), %xmm0
movups %xmm0, 0x30(%rsp)
movq %r13, 0x10(%rsp)
movq 0x20(%r15), %rax
movq %rax, 0x20(%rsp)
movb $0x1, 0x18(%rsp)
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x48(%rsp), %rcx
xorl %r8d, %r8d
callq 0x106c60
movq %r13, %rdi
movb 0x3(%rsp), %r13b
callq 0xf052b
movq 0x10(%r14), %rdi
callq 0xeb865
movl %eax, 0x2c(%r15)
movq %rbx, %rdi
leaq 0x9042e(%rip), %rsi     # 0x1152e3
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
cmpl $0x0, 0x28(%r15)
jne 0x84edc
cmpb 0x2c(%r15), %r13b
je 0x84edc
movq %rbx, %rdi
leaq 0xa7729(%rip), %rsi     # 0x12c5fe
xorl %eax, %eax
callq 0xe8faa
movq (%r14), %rdi
callq 0xf145f
movq 0x18(%rbx), %rdi
movq (%r14), %rcx
movl $0x7, %edx
movq %r12, %rsi
callq 0xef481
movq (%r14), %rdi
movq 0x18(%r15), %rsi
callq 0xf1042
movq (%r14), %rdi
movq 0x20(%r15), %rsi
callq 0xf1042
movq 0x18(%rbx), %rdi
leaq 0x10(%r12), %rsi
leaq -0xf(%rbp), %rdx
movq (%r14), %rcx
callq 0xef481
movq (%r14), %rdi
movzbl 0x2c(%r15), %esi
callq 0xf0bd6
movq (%r14), %rdi
movzbl 0x2d(%r15), %esi
callq 0xf0bd6
cmpl $0x0, 0x28(%r15)
je 0x84f58
movq (%r14), %rdi
movl $0x5, %esi
movl $0x30, %edx
callq 0xf0e8b
leaq 0x2(%rbp), %r13
movq (%r14), %rdi
movq 0x18(%r14), %rcx
movl $0x2, %esi
movq %rbp, %rdx
callq 0x8694b
movl %eax, 0x30(%r15)
movq %rbx, %rdi
leaq 0xa1689(%rip), %rsi     # 0x126607
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq (%r14), %rdi
movzbl 0x30(%r15), %edx
movl $0x1, %esi
callq 0xf0e8b
movq (%r14), %rdi
movq %r13, %rsi
callq 0xf0f27
movq (%r14), %rdi
movq 0x8(%r14), %rcx
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xef481
movq 0x10(%r15), %rdx
movq 0x18(%r15), %rcx
movq %rbx, %rdi
leaq 0x9540b(%rip), %rsi     # 0x11a3d3
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
movq 0x8(%r14), %rcx
callq 0xef481
addq 0x18(%r15), %r13
movq %r13, 0x8(%r15)
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq 0x8(%r15), %r12
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeead3
testb %al, %al
jne 0x84caf
leaq 0xc679e(%rip), %rsi     # 0x14b7b5
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xf0bd6
movb $0x1, %bpl
jmp 0x85072
leaq 0xa7588(%rip), %rsi     # 0x12c5c3
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe8be2
testq %r14, %r14
je 0x850c6
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x850a1
callq 0xf052b
jmp 0x85090
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe8be2
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x850a1
callq 0xf052b
testb %bpl, %bpl
jne 0x850a1
leaq 0xa74ef(%rip), %rsi     # 0x12c586
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
movq (%r14), %rdi
callq 0xf052b
movq 0x10(%r14), %rdi
callq 0xeb858
movq 0x18(%r14), %rdi
callq 0xeb858
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq