// File: /workspace/github_c_makefile_star2_O1/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 0xe969b
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
callq 0x88587
testl %eax, %eax
je 0x856d9
movq %rbx, %rdi
movl $0x21, %esi
callq 0xeba56
movq %rax, 0x10(%r14)
movq %rbx, %rdi
movl $0x30, %esi
callq 0xeba56
movq %rax, 0x18(%r14)
leaq 0xbf8ac(%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 %rax, (%r14)
movl $0x38, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r15
movq 0x18(%rbx), %rdi
xorl %esi, %esi
callq 0xef0d5
testb %al, %al
je 0x856b5
xorl %r12d, %r12d
leaq 0x1b(%r12), %rax
movq 0x18(%rbx), %rcx
movb $0x1, %r13b
cmpq 0x18(%rcx), %rax
jg 0x856fe
movq %rbx, %rdi
movq %r12, %rsi
callq 0x88587
testl %eax, %eax
je 0x856fe
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movups %xmm0, 0x20(%r15)
movups %xmm0, 0x10(%r15)
movq $0x0, 0x30(%r15)
movq %r12, (%r15)
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq 0xe958c
movq %rbx, %rdi
leaq 0xb6449(%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, %ebp
movq %rbx, %rdi
leaq 0xa236c(%rip), %rsi     # 0x127736
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
cmpb $0x16, %bpl
jb 0x856f2
leaq (%r12,%rbp), %rax
addq $0x2, %rax
movq %rax, 0x10(%r15)
movq 0x18(%rbx), %rdi
leaq 0x8(%r12), %rsi
callq 0xef37e
movq %rax, 0x18(%r15)
movq %rbx, %rdi
leaq 0x98e86(%rip), %rsi     # 0x11e28b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0xc(%r12), %rsi
callq 0xef37e
movq %rax, 0x20(%r15)
movq %rbx, %rdi
leaq 0xa6ec0(%rip), %rsi     # 0x12c2eb
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpq $0x0, 0x18(%r15)
jne 0x8544c
movl $0x1, 0x28(%r15)
movq 0x20(%r15), %rax
movq %rax, 0x18(%r15)
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rax
addq %rsi, %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x856f2
decq %rsi
callq 0xef0d5
movl %eax, %r13d
movzbl %al, %edx
movq %rbx, %rdi
leaq 0xa6e80(%rip), %rsi     # 0x12c2fd
xorl %eax, %eax
callq 0xe9226
movq 0x10(%r14), %rdi
callq 0xebdc3
cmpl $0x0, 0x28(%r15)
je 0x854ae
movq 0x10(%r14), %rdi
movq 0x18(%rbx), %rsi
movq 0x10(%r15), %rdx
movq 0x18(%r15), %rcx
callq 0xebf09
jmp 0x85543
movq 0x20(%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xf19d3
movb %r13b, 0xb(%rsp)
movq %rax, %r13
movq 0x10(%r14), %rdx
movq %rax, %rdi
leaq 0x6c57f(%rip), %rsi     # 0xf1a51
callq 0xf1a12
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x48(%rsp), %rcx
callq 0xfa6e0
movq 0x18(%rbx), %rax
movq %rax, 0x28(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x30(%rsp)
movq 0x18(%r15), %rax
movq %rax, 0x38(%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 0x107127
movq %r13, %rdi
movb 0xb(%rsp), %r13b
callq 0xf0b13
movq 0x10(%r14), %rdi
callq 0xebe2a
movl %eax, 0x2c(%r15)
movq %rbx, %rdi
leaq 0x8fcd9(%rip), %rsi     # 0x115233
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
cmpl $0x0, 0x28(%r15)
jne 0x85581
cmpb 0x2c(%r15), %r13b
je 0x85581
movq %rbx, %rdi
leaq 0xa6d9c(%rip), %rsi     # 0x12c316
xorl %eax, %eax
callq 0xe9b27
movq (%r14), %rdi
callq 0xf1a5f
movq 0x18(%rbx), %rdi
movq (%r14), %rcx
movl $0x7, %edx
movq %r12, %rsi
callq 0xefabc
movq (%r14), %rdi
movq 0x18(%r15), %rsi
callq 0xf1645
movq (%r14), %rdi
movq 0x20(%r15), %rsi
callq 0xf1645
movq 0x18(%rbx), %rdi
leaq 0x10(%r12), %rsi
leaq -0xf(%rbp), %rdx
movq (%r14), %rcx
callq 0xefabc
movq (%r14), %rdi
movzbl 0x2c(%r15), %esi
callq 0xf11be
movq (%r14), %rdi
movzbl 0x2d(%r15), %esi
callq 0xf11be
cmpl $0x0, 0x28(%r15)
je 0x855fd
movq (%r14), %rdi
movl $0x5, %esi
movl $0x30, %edx
callq 0xf148e
leaq 0x2(%rbp), %r13
movq (%r14), %rdi
movq 0x18(%r14), %rcx
movl $0x2, %esi
movq %rbp, %rdx
callq 0x87005
movl %eax, 0x30(%r15)
movq %rbx, %rdi
leaq 0xa0db4(%rip), %rsi     # 0x1263d7
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq (%r14), %rdi
movzbl 0x30(%r15), %edx
movl $0x1, %esi
callq 0xf148e
movq (%r14), %rdi
movq %r13, %rsi
callq 0xf152a
movq (%r14), %rdi
movq 0x8(%r14), %rcx
movq 0x18(%rdi), %rdx
xorl %esi, %esi
callq 0xefabc
movq 0x10(%r15), %rdx
movq 0x18(%r15), %rcx
movq %rbx, %rdi
leaq 0x94c46(%rip), %rsi     # 0x11a2b3
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
movq 0x8(%r14), %rcx
callq 0xefabc
addq 0x18(%r15), %r13
movq %r13, 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 0x8533e
leaq 0xc5b02(%rip), %rsi     # 0x14b1be
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x8(%r14), %rdi
xorl %esi, %esi
callq 0xf11be
jmp 0x856fe
leaq 0xa6bfb(%rip), %rsi     # 0x12c2db
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movb $0x1, %r13b
jmp 0x856fe
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe9752
testq %r14, %r14
je 0x85757
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x85732
callq 0xf0b13
testb %r13b, %r13b
je 0x85732
leaq 0xa6b76(%rip), %rsi     # 0x12c29e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
movq (%r14), %rdi
callq 0xf0b13
movq 0x10(%r14), %rdi
callq 0xebe1d
movq 0x18(%r14), %rdi
callq 0xebe1d
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq