// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/src/fmtutil-lzh.c
// Function: fmtutil_distilled_codectype1
void fmtutil_distilled_codectype1(deark *c, struct de_dfilter_in_params *dcmpri,
	struct de_dfilter_out_params *dcmpro, struct de_dfilter_results *dres,
	void *codec_private_params)
{
	struct lzh_ctx *cctx = NULL;
	char pos_descr[32];

	cctx = de_malloc(c, sizeof(struct lzh_ctx));
	cctx->modname = "distilled";
	cctx->c = c;
	cctx->dcmpri = dcmpri;
	cctx->dcmpro = dcmpro;
	cctx->dres = dres;

	cctx->bitrd.bbll.is_lsb = 1;
	cctx->bitrd.f = dcmpri->f;
	cctx->bitrd.curpos = dcmpri->pos;
	cctx->bitrd.endpos = dcmpri->pos + dcmpri->len;

	cctx->ringbuf = de_lz77buffer_create(cctx->c, 8192);
	cctx->ringbuf->userdata = (void*)cctx;
	cctx->ringbuf->writebyte_cb = lzh_lz77buf_writebytecb;
	de_lz77buffer_clear(cctx->ringbuf, 0x20);

	distilled_read_nodetable(c, cctx);
	if(cctx->err_flag) goto done;

	distilled_make_offsets_tree(c, cctx);

	de_bitreader_describe_curpos(&cctx->bitrd, pos_descr, sizeof(pos_descr));
	de_dbg2(c, "cmpr data codes at %s", pos_descr);
	de_dbg_indent(c, 1);
	distilled_main(c, cctx);
	de_dbg_indent(c, -1);

	de_bitreader_skip_to_byte_boundary(&cctx->bitrd);
	cctx->dres->bytes_consumed = cctx->bitrd.curpos - cctx->dcmpri->pos;
	if(cctx->dres->bytes_consumed<0) {
		cctx->dres->bytes_consumed = 0;
	}
	cctx->dres->bytes_consumed_valid = 1;

done:
	if(cctx) {
		if(cctx->err_flag) {
			de_dfilter_set_generic_error(c, dres, cctx->modname);
		}
		destroy_lzh_ctx(cctx);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
movl $0xd0, %esi
callq 0xe8b2b
movq %rax, %r14
leaq 0x13ca2(%rip), %rax     # 0x114a58
movq %rax, 0x20(%r14)
movq %r15, (%r14)
movq %r12, 0x8(%r14)
movq %rbx, 0x10(%r14)
movq %r13, 0x8(%rsp)
movq %r13, 0x18(%r14)
leaq 0x38(%r14), %rbx
movb $0x1, 0x58(%r14)
movq (%r12), %rax
movq %rax, 0x38(%r14)
movq 0x8(%r12), %rax
movq %rax, 0x40(%r14)
addq 0x10(%r12), %rax
movq %rax, 0x48(%r14)
movq %r15, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0xfad8f
movq %rax, 0x70(%r14)
movq %r14, (%rax)
leaq 0x421(%rip), %rcx       # 0x10122d
movq %rcx, 0x8(%rax)
movq %rax, %rdi
movl $0x20, %esi
callq 0xfadfe
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0xe8a1c
movl $0xa30, %esi            # imm = 0xA30
movq %r15, %rdi
callq 0xe8b2b
movq %rax, %r13
movq %r15, (%rax)
leaq 0x4aa87(%rip), %rsi     # 0x14b8cb
movq %r15, %rdi
xorl %eax, %eax
callq 0xe87e4
movq %r15, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %rbx, %rdi
movl $0x10, %esi
callq 0xf1bed
movl %eax, 0x8(%r13)
leaq 0x4aa65(%rip), %rsi     # 0x14b8d8
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe87e4
movl 0x8(%r13), %ebp
leal -0x2(%rbp), %eax
cmpl $0x273, %eax            # imm = 0x273
setb %al
testb $0x1, %bpl
sete %cl
testb %cl, %al
je 0x100ed4
movq %rbx, %r12
movq %rbx, %rdi
movl $0x8, %esi
callq 0xf1bed
movq %rax, %rbx
leaq 0x4aa34(%rip), %rsi     # 0x14b8e7
movq %r15, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xe87e4
leal -0xd(%rbx), %eax
cmpl $-0xd, %eax
ja 0x100ee1
movl $0x1, 0x30(%r14)
jmp 0x100fa7
movl $0x1, 0x30(%r14)
jmp 0x100faa
shrl %ebp
incq %rbp
movq %rbp, (%rsp)
leaq 0x4aa03(%rip), %rsi     # 0x14b8f4
movq %r15, %rdi
xorl %eax, %eax
callq 0xe87e4
movq %r15, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpl $0x0, 0x8(%r13)
je 0x100f42
xorl %ebp, %ebp
movq %r12, %rdi
movl %ebx, %esi
callq 0xf1bed
movw %ax, 0x1a(%r13,%rbp,4)
movq %r15, %rdi
leaq 0x4a9de(%rip), %rsi     # 0x14b909
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xe87e4
incq %rbp
movl 0x8(%r13), %eax
cmpq %rax, %rbp
jb 0x100f11
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
leaq 0x4a9b4(%rip), %rsi     # 0x14b917
movq %r15, %rdi
xorl %eax, %eax
callq 0xe889f
movq %r15, %rdi
movl $0x1, %esi
callq 0xe8a15
movq %r15, %rdi
movq (%rsp), %rdx
movq %rdx, %rsi
callq 0x104d0e
movq %rax, 0x98(%r14)
movq %rax, 0x10(%r13)
movl 0x8(%r13), %esi
addl $-0x2, %esi
movq %r13, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1021fb
movq %r12, %rbx
movq %r15, %rdi
movq %r13, %rsi
callq 0xe8be2
movl 0x10(%rsp), %esi
movq %r15, %rdi
callq 0xe8a25
cmpl $0x0, 0x30(%r14)
jne 0x101205
movq %rbx, (%rsp)
movl $0x40, %esi
movl $0x40, %edx
movq %r15, %rdi
callq 0x104d0e
movq %rax, 0xa0(%r14)
leaq 0x4a947(%rip), %rsi     # 0x14b937
movq %r15, %rdi
xorl %eax, %eax
callq 0xe889f
movq %r15, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0x4aab2(%rip), %rbp     # 0x14bac0
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x101049
movl $0x4, %r12d
cmpq $0x4, %rbx
jb 0x10104f
movl $0x5, %r12d
cmpq $0xc, %rbx
jb 0x10104f
movl $0x6, %r12d
cmpq $0x18, %rbx
jb 0x10104f
cmpq $0x30, %rbx
movl $0x8, %r12d
sbbl $0x0, %r12d
jmp 0x10104f
movl $0x3, %r12d
movzbl (%rbx,%rbp), %r13d
cmpl $0x2, (%r15)
jle 0x101085
movl $0x48, %esi
leaq 0x10(%rsp), %rdi
movq %r13, %rdx
movl %r12d, %ecx
callq 0xe9d03
movq %r15, %rdi
leaq 0x1d3eb(%rip), %rsi     # 0x11e464
movq %rax, %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0xe889f
movq 0xa0(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
movq %r13, %rdx
movl %r12d, %ecx
movl %ebx, %r8d
callq 0x1044c1
incq %rbx
cmpq $0x40, %rbx
jne 0x101010
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
leaq 0x10(%rsp), %rbx
movl $0x20, %edx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0xf1cf3
leaq 0x1d114(%rip), %rsi     # 0x11e1ec
xorl %r13d, %r13d
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xe87e4
movq %r15, %rdi
movl $0x1, %esi
callq 0xe8a15
cmpb $0x0, 0x50(%r14)
jne 0x1011c7
movq 0x10(%r14), %rax
cmpb $0x0, 0x8(%rax)
je 0x101123
movq 0x28(%r14), %rcx
cmpq 0x10(%rax), %rcx
jl 0x101123
testl %r13d, %r13d
movl $0x1, %r13d
jne 0x1011c7
movq 0x98(%r14), %rsi
movq %r14, %rdi
callq 0x101e47
movl %eax, %ebx
cmpl $0xff, %eax
ja 0x101149
movq 0x70(%r14), %rdi
movzbl %bl, %esi
callq 0xfae4e
jmp 0x1010f5
cmpl $0x100, %ebx            # imm = 0x100
je 0x1011c7
addl $0xffffff02, %ebx       # imm = 0xFFFFFF02
movq 0xa0(%r14), %rsi
movq %r14, %rdi
callq 0x101e47
movl %eax, %ebp
movq 0x28(%r14), %rax
addq $0x3c, %rax
movl $0x7, %r12d
leal 0x5(%r12), %ecx
movl $0x1, %edx
shlq %cl, %rdx
cmpq %rdx, %rax
jge 0x10119d
leal -0x1(%r12), %ecx
addl $0x4, %r12d
cmpl $0x5, %r12d
movl %ecx, %r12d
ja 0x101176
xorl %r12d, %r12d
movq (%rsp), %rdi
movl %r12d, %esi
callq 0xf1bed
movl %r12d, %ecx
shll %cl, %ebp
orl %eax, %ebp
movq 0x70(%r14), %rdi
notl %ebp
addl 0x10(%rdi), %ebp
movl %ebp, %esi
movl %ebx, %edx
callq 0xfae7b
jmp 0x1010f5
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq (%rsp), %rdi
callq 0xf1c84
movq 0x40(%r14), %rax
movq 0x8(%r14), %rcx
movq 0x18(%r14), %rdx
subq 0x8(%rcx), %rax
xorl %ecx, %ecx
testq %rax, %rax
cmovgq %rax, %rcx
movq %rcx, 0x8(%rdx)
movb $0x1, 0x4(%rdx)
cmpl $0x0, 0x30(%r14)
je 0x101216
movq 0x20(%r14), %rdx
movq %r15, %rdi
movq 0x8(%rsp), %rsi
callq 0xfa311
movq %r14, %rdi
callq 0xff6fb
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq