// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/fli.c
// Function: do_chunk
static int do_chunk(deark *c, lctx *d, struct chunk_info_type *parent_ci,
	i64 pos1, i64 bytes_avail, int level, i64 *pbytes_consumed)
{
	i64 pos = pos1;
	int saved_indent_level;
	int retval = 0;
	struct chunk_info_type *ci = NULL;
	enum mapped_chunktype_enum parent_mct;

	de_dbg_indent_save(c, &saved_indent_level);
	if(bytes_avail<6) goto done;
	parent_mct = parent_ci ? parent_ci->mct : MCT_NONE;

	ci = de_malloc(c, sizeof(struct chunk_info_type));
	ci->parent = parent_ci;
	ci->level = level;
	ci->pos = pos1;

	// Inherit the image context.
	if(parent_ci) {
		ci->ictx = parent_ci->ictx;
	}

	de_dbg(c, "chunk at %"I64_FMT, ci->pos);
	de_dbg_indent(c, 1);

	ci->len = de_getu32le_p(&pos);
	de_dbg(c, "chunk len: %"I64_FMT, ci->len);
	if(ci->len==0 && level==0) {
		ci->len = c->infile->len;
	}
	if(ci->len==0) {
		goto done;
	}
	if(ci->len<6) {
		de_err(c, "Bad chunk header at %"I64_FMT, ci->pos);
		goto done;
	}
	if(ci->len > bytes_avail) {
		de_warn(c, "Chunk at %"I64_FMT" exceeds its parent's bounds (ends at %"I64_FMT
			", parent ends at %"I64_FMT")", ci->pos, ci->pos+ci->len, ci->pos+bytes_avail);
		ci->len = bytes_avail;
	}

	ci->dpos = ci->pos + 6;
	ci->dlen = ci->len - 6;
	*pbytes_consumed = ci->len;
	retval = 1;

	ci->chunktype = (UI)de_getu16le_p(&pos);

	identify_chunk(c, d, ci);
	de_dbg(c, "chunk type: 0x%04x (%s)", ci->chunktype, ci->chunk_type_name);

	if(ci->handler_fn) {
		ci->handler_fn(c, d, ci);
	}

	if(ci->handler_fn==NULL && (parent_mct==MCT_FLI_OR_FLC || parent_mct==MCT_FRAME))
	{
		de_warn(c, "Unknown chunk type 0x%04x at %"I64_FMT, ci->chunktype, ci->pos);
	}

done:
	de_free(c, ci);
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %r13d
movq %r8, %r12
movq %rcx, %r15
movq %rdx, %rbp
movq %rsi, %r14
movq %rdi, %rbx
movq %rcx, 0x8(%rsp)
leaq 0x4(%rsp), %rsi
callq 0xe8a1c
cmpq $0x6, %r12
jge 0x5a2e9
xorl %r14d, %r14d
xorl %ebp, %ebp
jmp 0x5a717
testq %rbp, %rbp
movq %r14, 0x10(%rsp)
je 0x5a305
movl $0xfffefffb, %eax       # imm = 0xFFFEFFFB
addl 0x8(%rbp), %eax
cmpl $-0x2, %eax
setb 0x3(%rsp)
jmp 0x5a30a
movb $0x1, 0x3(%rsp)
movl $0x50, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r14
movq %rbp, 0x30(%rax)
movl %r13d, 0x4(%rax)
movq %r15, 0x10(%rax)
testq %rbp, %rbp
je 0x5a333
movq 0x48(%rbp), %rax
movq %rax, 0x48(%r14)
leaq 0xf09ec(%rip), %rsi     # 0x14ad26
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xeed83
movq %rax, 0x18(%r14)
leaq 0xc7cf7(%rip), %rsi     # 0x122066
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%r14), %rcx
testq %rcx, %rcx
setne %al
testl %r13d, %r13d
setne %dl
orb %al, %dl
jne 0x5a39c
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x18(%r14)
testq %rcx, %rcx
je 0x5a717
cmpq $0x5, %rcx
jg 0x5a3c7
movq 0x10(%r14), %rdx
leaq 0xc7cbf(%rip), %rsi     # 0x122075
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x5a717
movq 0x50(%rsp), %r15
cmpq %r12, %rcx
jbe 0x5a3f3
movq 0x10(%r14), %rdx
addq %rdx, %rcx
leaq (%rdx,%r12), %r8
leaq 0xc7caa(%rip), %rsi     # 0x12208d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
movq %r12, 0x18(%r14)
jmp 0x5a3f6
movq %rcx, %r12
movq 0x10(%r14), %rax
addq $0x6, %rax
movq %rax, 0x20(%r14)
leaq -0x6(%r12), %rax
movq %rax, 0x28(%r14)
movq %r12, (%r15)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xeebeb
movl %eax, (%r14)
movq 0x30(%r14), %rcx
testq %rcx, %rcx
je 0x5a4bb
movl 0x8(%rcx), %edi
movl $0x10002, 0x8(%r14)     # imm = 0x10002
movq $0x0, 0x38(%r14)
leaq 0xd1d0b(%rip), %rcx     # 0x12c151
movq %rcx, 0x40(%r14)
cmpl $0x10003, %edi          # imm = 0x10003
je 0x5a4e8
leaq 0x8(%r14), %rsi
movq %r14, %rdx
addq $0x38, %rdx
cmpl $0x10002, %edi          # imm = 0x10002
je 0x5a4d1
leal -0x10004(%rdi), %r8d
cmpl $0x9, %r8d
ja 0x5a6bc
leaq 0xc7a93(%rip), %r9      # 0x121f14
movslq (%r9,%r8,4), %r8
addq %r9, %r8
jmpq *%r8
leal -0x4(%rax), %edx
cmpl $0xc, %edx
ja 0x5a588
leaq 0xc7a9e(%rip), %rsi     # 0x121f3c
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movl $0x10006, 0x8(%r14)     # imm = 0x10006
leaq 0xc7c7e(%rip), %rcx     # 0x122134
jmp 0x5a628
leaq 0x8(%r14), %rsi
movq %r14, %rdx
addq $0x38, %rdx
leaq 0xd1c84(%rip), %rcx     # 0x12c151
movq %rcx, 0x40(%r14)
cmpl $0xaf11, %eax           # imm = 0xAF11
je 0x5a512
cmpl $0xaf12, %eax           # imm = 0xAF12
jne 0x5a51f
leaq 0xc7c2f(%rip), %rcx     # 0x122115
jmp 0x5a519
cmpl $0xf100, %eax           # imm = 0xF100
je 0x5a55a
cmpl $0xf5fa, %eax           # imm = 0xF5FA
je 0x5a53b
cmpl $0xf1fa, %eax           # imm = 0xF1FA
jne 0x5a6bc
movl $0x10004, 0x8(%r14)     # imm = 0x10004
leaq 0xcd89a(%rip), %rcx     # 0x127daa
jmp 0x5a54a
leaq 0xc7bf8(%rip), %rcx     # 0x122111
movq %rcx, 0x40(%r14)
jmp 0x5a526
leaq 0xd1c2b(%rip), %rcx     # 0x12c151
movl $0x10003, (%rsi)        # imm = 0x10003
leaq 0x21a(%rip), %rsi       # 0x5a74d
movq %rsi, (%rdx)
jmp 0x5a6bc
movl $0x10004, 0x8(%r14)     # imm = 0x10004
leaq 0xc7bcf(%rip), %rcx     # 0x122119
movq %rcx, 0x40(%r14)
leaq 0x568(%rip), %rdx       # 0x5aabd
jmp 0x5a6b8
movl $0x10005, 0x8(%r14)     # imm = 0x10005
leaq 0xe77a8(%rip), %rcx     # 0x141d11
movq %rcx, 0x40(%r14)
leaq 0x675(%rip), %rdx       # 0x5abe9
jmp 0x5a6b8
movl $0x1000e, (%rsi)        # imm = 0x1000E
leaq 0x1015(%rip), %rsi      # 0x5b59b
jmp 0x5a533
movl %edi, %edx
xorl $0x10004, %edx          # imm = 0x10004
movl %eax, %esi
xorl $0x12, %esi
orl %edx, %esi
jne 0x5a670
movl $0x1000c, 0x8(%r14)     # imm = 0x1000C
leaq 0xc7c01(%rip), %rcx     # 0x1221ad
movq %rcx, 0x40(%r14)
leaq 0xcce(%rip), %rdx       # 0x5b285
jmp 0x5a6b8
movl $0x10009, 0x8(%r14)     # imm = 0x10009
leaq 0xc7b77(%rip), %rcx     # 0x122142
movq %rcx, 0x40(%r14)
leaq 0x789(%rip), %rdx       # 0x5ad5f
jmp 0x5a6b8
movl $0x1000b, 0x8(%r14)     # imm = 0x1000B
leaq 0xc7b88(%rip), %rcx     # 0x122172
movq %rcx, 0x40(%r14)
leaq 0xa28(%rip), %rdx       # 0x5b01d
jmp 0x5a6b8
movl $0x10007, 0x8(%r14)     # imm = 0x10007
leaq 0xc7b85(%rip), %rcx     # 0x12218e
movq %rcx, 0x40(%r14)
leaq 0xc13(%rip), %rdx       # 0x5b227
jmp 0x5a6b8
movl $0x10006, 0x8(%r14)     # imm = 0x10006
leaq 0xc7aff(%rip), %rcx     # 0x122127
movq %rcx, 0x40(%r14)
leaq 0x5c6(%rip), %rdx       # 0x5abf9
jmp 0x5a6b8
movl $0x1000a, 0x8(%r14)     # imm = 0x1000A
leaq 0xc7b0f(%rip), %rcx     # 0x122156
movq %rcx, 0x40(%r14)
leaq 0x839(%rip), %rdx       # 0x5ae8b
jmp 0x5a6b8
movl $0x10008, 0x8(%r14)     # imm = 0x10008
leaq 0xc7b3d(%rip), %rcx     # 0x1221a0
movq %rcx, 0x40(%r14)
leaq 0xbec(%rip), %rdx       # 0x5b25a
jmp 0x5a6b8
cmpl $0x10005, %edi          # imm = 0x10005
jne 0x5a6bc
cmpl $0x3, %eax
je 0x5a69e
cmpl $0x2, %eax
jne 0x5a6bc
movl $0x1000d, 0x8(%r14)     # imm = 0x1000D
leaq 0xbaf6c(%rip), %rcx     # 0x1155fd
movq %rcx, 0x40(%r14)
leaq 0xeeb(%rip), %rdx       # 0x5b587
jmp 0x5a6b8
movl $0x1000f, 0x8(%r14)     # imm = 0x1000F
leaq 0xc7b10(%rip), %rcx     # 0x1221bd
movq %rcx, 0x40(%r14)
leaq 0xee3(%rip), %rdx       # 0x5b59b
movq %rdx, 0x38(%r14)
leaq 0xc7a15(%rip), %rsi     # 0x1220d8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x38(%r14), %rax
testq %rax, %rax
je 0x5a73f
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq *%rax
cmpq $0x0, 0x38(%r14)
setne %al
orb 0x3(%rsp), %al
movl $0x1, %ebp
testb $0x1, %al
jne 0x5a717
movl (%r14), %edx
movq 0x10(%r14), %rcx
leaq 0xc79e8(%rip), %rsi     # 0x1220f0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8faa
movl $0x1, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %ebp
cmpb $0x0, 0x3(%rsp)
je 0x5a6fa
jmp 0x5a717