// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0x20, %esi
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc67f0
cmpl $0x0, %eax
jne 0xc1e9a
movq -0x8(%rbp), %rdi
leaq 0xf6211(%rip), %rsi     # 0x1b809f
movb $0x0, %al
callq 0x15bfb0
jmp 0xc1fd5
movq -0x8(%rbp), %rdi
movl $0x21, %esi
callq 0x15eac0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movl $0x30, %esi
callq 0x15eac0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
leaq 0x10eccb(%rip), %rsi    # 0x1d0ba2
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x166c60
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x168020
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movl $0x38, %esi
callq 0x15b780
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x165060
movzbl %al, %eax
cmpl $0x0, %eax
jne 0xc1f5f
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
leaq 0x1152a1(%rip), %rsi    # 0x1d71e1
movb $0x0, %al
callq 0x15b0d0
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0x168380
movl $0x1, -0x24(%rbp)
jmp 0xc1fd3
movq -0x30(%rbp), %rax
addq $0x1b, %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xc1f77
jmp 0xc1fd5
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xc67f0
cmpl $0x0, %eax
jne 0xc1f8b
jmp 0xc1fd5
movq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x19140
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0xc6870
cmpl $0x0, %eax
jne 0xc1fbe
jmp 0xc1fd5
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xc1f18
jmp 0xc1fd5
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15b820
cmpq $0x0, -0x18(%rbp)
je 0xc204e
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xc201b
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1676a0
cmpl $0x0, -0x24(%rbp)
jne 0xc2019
movq -0x8(%rbp), %rdi
leaq 0xf6050(%rip), %rsi     # 0x1b8062
movb $0x0, %al
callq 0x15bfb0
jmp 0xc201b
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x1676a0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x15f2e0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x15f2e0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)