// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x20
popq %rsi
callq 0xdecaf
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
callq 0x82edd
testl %eax, %eax
je 0x801c8
pushq $0x21
popq %rsi
movq %rbx, %rdi
callq 0xe0ae9
movq %rax, 0x10(%r14)
pushq $0x30
popq %rsi
movq %rbx, %rdi
callq 0xe0ae9
movq %rax, 0x18(%r14)
leaq 0xb7e02(%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 %rax, (%r14)
pushq $0x38
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r15
addq $0x8, %rax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3eb4
testb %al, %al
je 0x801ef
leaq 0x1b(%r13), %rax
movq 0x18(%rbx), %rcx
movb $0x1, %r12b
cmpq 0x18(%rcx), %rax
jg 0x80211
movq %rbx, %rdi
movq %r13, %rsi
callq 0x82edd
testl %eax, %eax
je 0x80211
movq 0x8(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq %r13, (%r15)
movq %rbx, %rdi
leaq 0x4(%rsp), %rsi
callq 0xdebae
movq %rbx, %rdi
leaq 0xae99b(%rip), %rsi     # 0x12e86d
movq %r13, %rdx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3eb4
movzbl %al, %ebp
movq %rbx, %rdi
leaq 0x9a826(%rip), %rsi     # 0x11a726
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
cmpb $0x16, %bpl
jb 0x801e1
leaq 0x2(,%r13), %rax
addq %rbp, %rax
movq %rax, 0x10(%r15)
movq 0x18(%rbx), %rdi
leaq 0x8(%r13), %rsi
callq 0xe409f
movq %rax, 0x18(%r15)
movq %rbx, %rdi
leaq 0x9138a(%rip), %rsi     # 0x1112c7
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
leaq 0xc(%r13), %rsi
callq 0xe409f
movq %rax, 0x20(%r15)
movq %rbx, %rdi
leaq 0x9f401(%rip), %rsi     # 0x11f363
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r15), %rax
testq %rax, %rax
jne 0x7ff85
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 0x801e1
decq %rsi
callq 0xe3eb4
movl %eax, %r12d
movzbl %al, %edx
movq %rbx, %rdi
leaq 0x9f3c3(%rip), %rsi     # 0x11f375
xorl %eax, %eax
callq 0xde896
movq 0x10(%r14), %rdi
callq 0xe0e44
cmpl $0x0, 0x28(%r15)
je 0x7ffe3
movq 0x10(%r14), %rdi
movq 0x18(%rbx), %rsi
movq 0x10(%r15), %rdx
movq 0x18(%r15), %rcx
callq 0xe0f33
jmp 0x80070
movq 0x20(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe6277
movb %r12b, 0x3(%rsp)
movq %rax, %r12
movq 0x10(%r14), %rdx
movq %rax, %rdi
leaq 0x662ba(%rip), %rsi     # 0xe62c1
callq 0xe629a
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x48(%rsp), %rcx
callq 0xee7ee
movq 0x18(%rbx), %rax
movq %rax, 0x28(%rsp)
movups 0x10(%r15), %xmm0
movups %xmm0, 0x30(%rsp)
movq %r12, 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 0xfa3ca
movq %r12, %rdi
movb 0x3(%rsp), %r12b
callq 0xe5591
movq 0x10(%r14), %rdi
callq 0xe0e95
movl %eax, 0x2c(%r15)
movq %rbx, %rdi
leaq 0x881d0(%rip), %rsi     # 0x108257
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
cmpl $0x0, 0x28(%r15)
jne 0x800ae
cmpb 0x2c(%r15), %r12b
je 0x800ae
movq %rbx, %rdi
leaq 0x9f2e7(%rip), %rsi     # 0x11f38e
xorl %eax, %eax
callq 0xdf05a
movq (%r14), %rdi
callq 0xe62cf
movq 0x18(%rbx), %rdi
movq (%r14), %rcx
movq %r13, %rsi
pushq $0x7
popq %rdx
callq 0xe45f4
movq (%r14), %rdi
movq 0x18(%r15), %rsi
callq 0xe5f7f
movq (%r14), %rdi
movq 0x20(%r15), %rsi
callq 0xe5f7f
movq 0x18(%rbx), %rdi
leaq 0x10(%r13), %rsi
leaq -0xf(%rbp), %rdx
movq (%r14), %rcx
callq 0xe45f4
movq (%r14), %rdi
movzbl 0x2c(%r15), %esi
callq 0xe5bc5
movq (%r14), %rdi
movzbl 0x2d(%r15), %esi
callq 0xe5bc5
cmpl $0x0, 0x28(%r15)
je 0x80123
movq (%r14), %rdi
pushq $0x5
popq %rsi
pushq $0x30
popq %rdx
callq 0xe5e13
leaq 0x2(%rbp), %r12
movq (%r14), %rdi
movq 0x18(%r14), %rcx
pushq $0x2
popq %rsi
movq %rbp, %rdx
callq 0x81a34
movl %eax, 0x30(%r15)
movq %rbx, %rdi
leaq 0x992c0(%rip), %rsi     # 0x119407
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq (%r14), %rdi
movzbl 0x30(%r15), %edx
pushq $0x1
popq %rsi
callq 0xe5e13
movq (%r14), %rdi
movq %r12, %rsi
callq 0xe5eb2
movq (%r14), %rdi
movq 0x8(%r14), %rcx
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xe45f4
movq 0x10(%r15), %rdx
movq 0x18(%r15), %rcx
movq %rbx, %rdi
leaq 0x8d154(%rip), %rsi     # 0x10d2e3
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
movq 0x8(%r14), %rcx
callq 0xe45f4
addq 0x18(%r15), %r12
movq %r12, 0x8(%r15)
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq 0x8(%r15), %r13
jmp 0x7fe69
leaq 0x9f184(%rip), %rsi     # 0x11f353
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movb $0x1, %r12b
jmp 0x80211
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
jmp 0x80211
leaq 0xbe0ef(%rip), %rsi     # 0x13e2e5
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xe5bc5
movq %rbx, %rdi
movq %r15, %rsi
callq 0xded32
testq %r14, %r14
je 0x8026a
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x80245
callq 0xe5591
testb %r12b, %r12b
je 0x80245
leaq 0x9f0db(%rip), %rsi     # 0x11f316
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
movq (%r14), %rdi
callq 0xe5591
movq 0x10(%r14), %rdi
callq 0xe0e8d
movq 0x18(%r14), %rdi
callq 0xe0e8d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq