// File: /workspace/github_c_makefile_star2_O1/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 0xe958c
cmpq $0x6, %r12
jge 0x5a512
xorl %r14d, %r14d
xorl %ebp, %ebp
jmp 0x5a91e
testq %rbp, %rbp
movq %r14, 0x10(%rsp)
je 0x5a52e
movl $0xfffefffb, %eax       # imm = 0xFFFEFFFB
addl 0x8(%rbp), %eax
cmpl $-0x2, %eax
setb 0x3(%rsp)
jmp 0x5a533
movb $0x1, 0x3(%rsp)
movl $0x50, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r14
movq %rbp, 0x30(%rax)
movl %r13d, 0x4(%rax)
movq %r15, 0x10(%rax)
testq %rbp, %rbp
je 0x5a55c
movq 0x48(%rbp), %rax
movq %rax, 0x48(%r14)
leaq 0xf0213(%rip), %rsi     # 0x14a776
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef3a0
movq %rax, 0x18(%r14)
leaq 0xc78c6(%rip), %rsi     # 0x121e5e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
testl %r13d, %r13d
jne 0x5a5bd
cmpq $0x0, 0x18(%r14)
jne 0x5a5bd
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rax
movq %rax, 0x18(%r14)
movq 0x18(%r14), %rcx
testq %rcx, %rcx
je 0x5a91e
cmpq $0x5, %rcx
jg 0x5a5ec
movq 0x10(%r14), %rdx
leaq 0xc7892(%rip), %rsi     # 0x121e6d
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x5a91e
movq 0x50(%rsp), %r15
cmpq %r12, %rcx
jle 0x5a616
movq 0x10(%r14), %rdx
addq %rdx, %rcx
leaq (%rdx,%r12), %r8
leaq 0xc787d(%rip), %rsi     # 0x121e85
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
movq %r12, 0x18(%r14)
movq 0x10(%r14), %rax
movq 0x18(%r14), %rcx
addq $0x6, %rax
movq %rax, 0x20(%r14)
leaq -0x6(%rcx), %rax
movq %rax, 0x28(%r14)
movq %rcx, (%r15)
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xef1ed
movl %eax, (%r14)
movq 0x30(%r14), %rcx
testq %rcx, %rcx
je 0x5a650
movl 0x8(%rcx), %ecx
jmp 0x5a655
movl $0x10002, %ecx          # imm = 0x10002
movl $0x10002, 0x8(%r14)     # imm = 0x10002
movq $0x0, 0x38(%r14)
leaq 0xd17fd(%rip), %rdx     # 0x12be69
movq %rdx, 0x40(%r14)
cmpl $0x10003, %ecx          # imm = 0x10003
je 0x5a6a2
cmpl $0x10002, %ecx          # imm = 0x10002
jne 0x5a6d3
cmpl $0xaf11, %eax           # imm = 0xAF11
je 0x5a73c
cmpl $0xaf12, %eax           # imm = 0xAF12
jne 0x5a747
leaq 0xc7870(%rip), %rax     # 0x121f0d
jmp 0x5a743
cmpl $0xf100, %eax           # imm = 0xF100
je 0x5a7c3
cmpl $0xf5fa, %eax           # imm = 0xF5FA
je 0x5a7a4
cmpl $0xf1fa, %eax           # imm = 0xF1FA
jne 0x5a6d3
movl $0x10004, 0x8(%r14)     # imm = 0x10004
leaq 0xcd4ac(%rip), %rax     # 0x127b7a
jmp 0x5a7b3
movl %ecx, %edx
orl $0x8, %edx
cmpl $0x1000c, %edx          # imm = 0x1000C
jne 0x5a70c
leal -0x4(%rax), %edx
cmpl $0xc, %edx
ja 0x5a70c
leaq 0xc7715(%rip), %rsi     # 0x121e04
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movl $0x10006, 0x8(%r14)     # imm = 0x10006
leaq 0xc7825(%rip), %rax     # 0x121f2c
jmp 0x5a84e
movl %ecx, %edx
xorl $0x10004, %edx          # imm = 0x10004
movl %eax, %esi
xorl $0x12, %esi
orl %edx, %esi
jne 0x5a75b
movl $0x1000c, 0x8(%r14)     # imm = 0x1000C
leaq 0xc7879(%rip), %rax     # 0x121fa5
movq %rax, 0x40(%r14)
leaq 0xdef(%rip), %rax       # 0x5b526
jmp 0x5a8bf
leaq 0xc77c6(%rip), %rax     # 0x121f09
movq %rax, 0x40(%r14)
movl $0x10003, 0x8(%r14)     # imm = 0x10003
leaq 0x1f0(%rip), %rax       # 0x5a946
jmp 0x5a8bf
cmpl $0x1000d, %ecx          # imm = 0x1000D
je 0x5a8b0
cmpl $0x10005, %ecx          # imm = 0x10005
jne 0x5a8c3
cmpl $0x3, %eax
je 0x5a893
cmpl $0x2, %eax
jne 0x5a8a8
movl $0x1000d, 0x8(%r14)     # imm = 0x1000D
leaq 0xbadb9(%rip), %rax     # 0x11554d
movq %rax, 0x40(%r14)
leaq 0xf7b(%rip), %rax       # 0x5b71a
jmp 0x5a8bf
movl $0x10004, 0x8(%r14)     # imm = 0x10004
leaq 0xc775e(%rip), %rax     # 0x121f11
movq %rax, 0x40(%r14)
leaq 0x4dc(%rip), %rax       # 0x5ac9a
jmp 0x5a8bf
movl $0x10005, 0x8(%r14)     # imm = 0x10005
leaq 0xe705f(%rip), %rax     # 0x141831
movq %rax, 0x40(%r14)
leaq 0x5e9(%rip), %rax       # 0x5adc6
jmp 0x5a8bf
movl $0x10009, 0x8(%r14)     # imm = 0x10009
leaq 0xc7749(%rip), %rax     # 0x121f3a
movq %rax, 0x40(%r14)
leaq 0x764(%rip), %rax       # 0x5af60
jmp 0x5a8bf
movl $0x1000b, 0x8(%r14)     # imm = 0x1000B
leaq 0xc775a(%rip), %rax     # 0x121f6a
movq %rax, 0x40(%r14)
leaq 0xa4b(%rip), %rax       # 0x5b266
jmp 0x5a8bf
movl $0x10007, 0x8(%r14)     # imm = 0x10007
leaq 0xc7757(%rip), %rax     # 0x121f86
movq %rax, 0x40(%r14)
leaq 0xc8e(%rip), %rax       # 0x5b4c8
jmp 0x5a8bf
movl $0x10006, 0x8(%r14)     # imm = 0x10006
leaq 0xc76d1(%rip), %rax     # 0x121f1f
movq %rax, 0x40(%r14)
leaq 0x57d(%rip), %rax       # 0x5add6
jmp 0x5a8bf
movl $0x1000a, 0x8(%r14)     # imm = 0x1000A
leaq 0xc76e4(%rip), %rax     # 0x121f4e
movq %rax, 0x40(%r14)
leaq 0x803(%rip), %rax       # 0x5b078
jmp 0x5a8bf
movl $0x10008, 0x8(%r14)     # imm = 0x10008
leaq 0xc7712(%rip), %rax     # 0x121f98
movq %rax, 0x40(%r14)
leaq 0xc6a(%rip), %rax       # 0x5b4fb
jmp 0x5a8bf
movl $0x1000f, 0x8(%r14)     # imm = 0x1000F
leaq 0xc7713(%rip), %rax     # 0x121fb5
movq %rax, 0x40(%r14)
jmp 0x5a8b8
cmpl $0x1000d, %ecx          # imm = 0x1000D
jne 0x5a8c3
movl $0x1000e, 0x8(%r14)     # imm = 0x1000E
leaq 0xe6f(%rip), %rax       # 0x5b72e
movq %rax, 0x38(%r14)
movl (%r14), %edx
movq 0x40(%r14), %rcx
leaq 0xc75ff(%rip), %rsi     # 0x121ed0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x38(%r14), %rax
testq %rax, %rax
je 0x5a8f1
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 0x5a91e
movl (%r14), %edx
movq 0x10(%r14), %rcx
leaq 0xc75d4(%rip), %rsi     # 0x121ee8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9b27
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq