// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %rcx, %r13
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
movl $0xd0, %esi
callq 0xe969b
movq %rax, %r14
leaq 0x13451(%rip), %rax     # 0x11497d
movq %rax, 0x20(%r14)
movq %r15, (%r14)
movq %r12, 0x8(%r14)
movq %rbx, 0x10(%r14)
movq %r13, 0x18(%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 0xfb2c3
movq %rax, 0x70(%r14)
movq %r14, (%rax)
leaq 0x438(%rip), %rcx       # 0x1019ba
movq %rcx, 0x8(%rax)
movq %rax, %rdi
movl $0x20, %esi
callq 0xfb332
leaq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0xe958c
movl $0xa30, %esi            # imm = 0xA30
movq %r15, %rdi
callq 0xe969b
movq %rax, %r13
movq %r15, (%rax)
leaq 0x49d1a(%rip), %rsi     # 0x14b2d4
movq %r15, %rdi
xorl %eax, %eax
callq 0xe93cf
movq %r15, %rdi
movl $0x1, %esi
callq 0xe9585
movq %rbx, %rdi
movl $0x10, %esi
callq 0xf2271
movl %eax, 0x8(%r13)
leaq 0x49cf8(%rip), %rsi     # 0x14b2e1
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe93cf
movl 0x8(%r13), %r12d
leal -0x2(%r12), %eax
cmpl $0x273, %eax            # imm = 0x273
setb %al
testb $0x1, %r12b
sete %cl
testb %cl, %al
movq %rbx, (%rsp)
je 0x101640
movq %rbx, %rdi
movl $0x8, %esi
callq 0xf2271
movq %rax, %rbx
leaq 0x49cc4(%rip), %rsi     # 0x14b2f0
movq %r15, %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0xe93cf
leal -0xd(%rbx), %eax
cmpl $-0xd, %eax
ja 0x10164d
movl $0x1, 0x30(%r14)
jmp 0x10171a
shrl %r12d
incq %r12
movq %r12, 0x8(%rsp)
leaq 0x49c9e(%rip), %rsi     # 0x14b2fd
movq %r15, %rdi
xorl %eax, %eax
callq 0xe93cf
movq %r15, %rdi
movl $0x1, %esi
callq 0xe9585
cmpl $0x0, 0x8(%r13)
movq (%rsp), %r12
je 0x1016b4
xorl %ebp, %ebp
movq %r12, %rdi
movl %ebx, %esi
callq 0xf2271
movw %ax, 0x1a(%r13,%rbp,4)
movq %r15, %rdi
leaq 0x49c75(%rip), %rsi     # 0x14b312
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0xe93cf
incq %rbp
movl 0x8(%r13), %eax
cmpq %rax, %rbp
jb 0x101683
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
leaq 0x49c4b(%rip), %rsi     # 0x14b320
movq %r15, %rdi
xorl %eax, %eax
callq 0xe9461
movq %r15, %rdi
movl $0x1, %esi
callq 0xe9585
movq %r15, %rdi
movq 0x8(%rsp), %rdx
movq %rdx, %rsi
callq 0x105165
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 0x102aec
movq %r15, %rdi
movq %r13, %rsi
callq 0xe9752
movl 0x20(%rsp), %esi
movq %r15, %rdi
callq 0xe9595
cmpl $0x0, 0x30(%r14)
jne 0x10198b
movl $0x40, %esi
movl $0x40, %edx
movq %r15, %rdi
callq 0x105165
leaq 0xa0(%r14), %rcx
movq %rcx, 0x8(%rsp)
movq %rax, 0xa0(%r14)
leaq 0x49bd8(%rip), %rsi     # 0x14b340
movq %r15, %rdi
xorl %eax, %eax
callq 0xe9461
movq %r15, %rdi
movl $0x1, %esi
callq 0xe9585
leaq 0x49d4a(%rip), %r13     # 0x14b4d0
xorl %r12d, %r12d
testq %r12, %r12
je 0x1017bd
movl $0x4, %ebp
cmpq $0x4, %r12
jb 0x1017c2
movl $0x5, %ebp
cmpq $0xc, %r12
jb 0x1017c2
movl $0x6, %ebp
cmpq $0x18, %r12
jb 0x1017c2
cmpq $0x30, %r12
movl $0x8, %ebp
sbbl $0x0, %ebp
jmp 0x1017c2
movl $0x3, %ebp
movzbl (%r12,%r13), %ebx
cmpl $0x3, (%r15)
jl 0x1017f8
movl $0x48, %esi
leaq 0x20(%rsp), %rdi
movq %rbx, %rdx
movl %ebp, %ecx
callq 0xea85a
movq %r15, %rdi
leaq 0x1cb69(%rip), %rsi     # 0x11e354
movq %rax, %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0xe9461
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
movq %rbx, %rdx
movl %ebp, %ecx
movl %r12d, %r8d
callq 0x104901
incq %r12
cmpq $0x40, %r12
jne 0x101789
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
leaq 0x20(%rsp), %rbx
movl $0x20, %edx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0xf2360
leaq 0x1c891(%rip), %rsi     # 0x11e0dc
xorl %r13d, %r13d
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0xe93cf
movq %r15, %rdi
movl $0x1, %esi
callq 0xe9585
movq %r14, %r12
addq $0x98, %r12
movq %r12, 0x10(%rsp)
cmpb $0x0, 0x50(%r14)
je 0x101889
xorl %eax, %eax
testb %al, %al
jne 0x101877
jmp 0x101954
movq 0x10(%r14), %rax
cmpb $0x0, 0x8(%rax)
je 0x1018b2
movq 0x28(%r14), %rcx
cmpq 0x10(%rax), %rcx
jl 0x1018b2
testl %r13d, %r13d
je 0x1018ac
xorl %eax, %eax
movl $0x1, %r13d
jmp 0x101880
movl $0x1, %r13d
movq %r14, %rdi
movq %r12, %rsi
callq 0x1026f6
movl %eax, %ebx
cmpl $0xff, %eax
ja 0x1018d6
movq 0x70(%r14), %rdi
movzbl %bl, %esi
callq 0xfb382
movb $0x1, %al
jmp 0x101880
cmpl $0x100, %ebx            # imm = 0x100
je 0x10187e
addl $0xffffff02, %ebx       # imm = 0xFFFFFF02
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x1026f6
movl %eax, %r12d
movq 0x28(%r14), %rax
addq $0x3c, %rax
movl $0x7, %ebp
leal 0x5(%rbp), %ecx
movl $0x1, %edx
shlq %cl, %rdx
cmpq %rdx, %rax
jge 0x101920
leal -0x1(%rbp), %ecx
addl $0x4, %ebp
cmpl $0x5, %ebp
movl %ecx, %ebp
ja 0x101901
xorl %ebp, %ebp
movq (%rsp), %rdi
movl %ebp, %esi
callq 0xf2271
movl %ebp, %ecx
shll %cl, %r12d
orl %eax, %r12d
movq 0x70(%r14), %rdi
notl %r12d
addl 0x10(%rdi), %r12d
movl %r12d, %esi
movl %ebx, %edx
callq 0xfb3af
movb $0x1, %al
movq 0x10(%rsp), %r12
jmp 0x101880
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq (%rsp), %rdi
callq 0xf22f1
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 0x1019a3
movq 0x20(%r14), %rdx
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0xfa815
movq %r14, %rdi
callq 0xffe9f
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq