// File: /workspace/github_c_makefile_star2_O2/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, %rbp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq %rcx, 0x8(%rsp)
leaq 0x4(%rsp), %rsi
callq 0xdebae
cmpq $0x6, %r12
jge 0x57387
xorl %r14d, %r14d
jmp 0x5745b
testq %r15, %r15
movq %r14, 0x10(%rsp)
je 0x573a4
movl $0xfffefffb, %eax       # imm = 0xFFFEFFFB
addl 0x8(%r15), %eax
cmpl $-0x2, %eax
setb 0x3(%rsp)
jmp 0x573a9
movb $0x1, 0x3(%rsp)
pushq $0x50
popq %rsi
movq %rbx, %rdi
callq 0xdecaf
movq %rax, %r14
movq %r15, 0x30(%rax)
movl %r13d, 0x4(%rax)
movq %rbp, 0x10(%rax)
testq %r15, %r15
je 0x573d0
movq 0x48(%r15), %rax
movq %rax, 0x48(%r14)
leaq 0xe647f(%rip), %rsi     # 0x13d856
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
movq 0x18(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0xe40bf
movq %rax, 0x18(%r14)
leaq 0xbda9c(%rip), %rsi     # 0x114ea6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%r14), %rcx
testq %rcx, %rcx
setne %al
testl %r13d, %r13d
setne %dl
orb %al, %dl
jne 0x57437
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rcx
movq %rcx, 0x18(%r14)
testq %rcx, %rcx
je 0x5745b
cmpq $0x5, %rcx
jg 0x57485
movq 0x10(%r14), %rdx
leaq 0xbda68(%rip), %rsi     # 0x114eb5
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf2a5
jmp 0x5745d
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
movl 0x4(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rsp), %r15
cmpq %r12, %rcx
jbe 0x574b1
movq 0x10(%r14), %rdx
addq %rdx, %rcx
leaq (%rdx,%r12), %r8
leaq 0xbda2c(%rip), %rsi     # 0x114ecd
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
movq %r12, 0x18(%r14)
jmp 0x574b4
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 0xe3fc4
movl %eax, (%r14)
movq 0x30(%r14), %rcx
testq %rcx, %rcx
je 0x57576
movl 0x8(%rcx), %edi
movl $0x10002, 0x8(%r14)     # imm = 0x10002
andq $0x0, 0x38(%r14)
leaq 0xc79e0(%rip), %rcx     # 0x11eee1
movq %rcx, 0x40(%r14)
cmpl $0x10003, %edi          # imm = 0x10003
je 0x575a3
leaq 0x8(%r14), %rsi
movq %r14, %rdx
addq $0x38, %rdx
cmpl $0x10002, %edi          # imm = 0x10002
je 0x5758c
leal -0x10004(%rdi), %r8d
cmpl $0x9, %r8d
ja 0x57777
leaq 0xbd8e8(%rip), %r9      # 0x114e24
movslq (%r9,%r8,4), %r8
addq %r9, %r8
jmpq *%r8
leal -0x4(%rax), %edx
cmpl $0xc, %edx
ja 0x57643
leaq 0xbd8f3(%rip), %rsi     # 0x114e4c
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
movl $0x10006, 0x8(%r14)     # imm = 0x10006
leaq 0xbda03(%rip), %rcx     # 0x114f74
jmp 0x576e3
leaq 0x8(%r14), %rsi
movq %r14, %rdx
addq $0x38, %rdx
leaq 0xc7959(%rip), %rcx     # 0x11eee1
movq %rcx, 0x40(%r14)
cmpl $0xaf11, %eax           # imm = 0xAF11
je 0x575cd
cmpl $0xaf12, %eax           # imm = 0xAF12
jne 0x575da
leaq 0xbd9b4(%rip), %rcx     # 0x114f55
jmp 0x575d4
cmpl $0xf100, %eax           # imm = 0xF100
je 0x57615
cmpl $0xf5fa, %eax           # imm = 0xF5FA
je 0x575f6
cmpl $0xf1fa, %eax           # imm = 0xF1FA
jne 0x57777
movl $0x10004, 0x8(%r14)     # imm = 0x10004
leaq 0xc359f(%rip), %rcx     # 0x11ab6a
jmp 0x57605
leaq 0xbd97d(%rip), %rcx     # 0x114f51
movq %rcx, 0x40(%r14)
jmp 0x575e1
leaq 0xc7900(%rip), %rcx     # 0x11eee1
movl $0x10003, (%rsi)        # imm = 0x10003
leaq 0x1f0(%rip), %rsi       # 0x577de
movq %rsi, (%rdx)
jmp 0x57777
movl $0x10004, 0x8(%r14)     # imm = 0x10004
leaq 0xbd954(%rip), %rcx     # 0x114f59
movq %rcx, 0x40(%r14)
leaq 0x4f6(%rip), %rdx       # 0x57b06
jmp 0x57773
movl $0x10005, 0x8(%r14)     # imm = 0x10005
leaq 0xdd29d(%rip), %rcx     # 0x1348c1
movq %rcx, 0x40(%r14)
leaq 0x603(%rip), %rdx       # 0x57c32
jmp 0x57773
movl $0x1000e, (%rsi)        # imm = 0x1000E
leaq 0xe58(%rip), %rsi       # 0x58499
jmp 0x575ee
movl %edi, %edx
xorl $0x10004, %edx          # imm = 0x10004
movl %eax, %esi
xorl $0x12, %esi
orl %edx, %esi
jne 0x5772b
movl $0x1000c, 0x8(%r14)     # imm = 0x1000C
leaq 0xbd986(%rip), %rcx     # 0x114fed
movq %rcx, 0x40(%r14)
leaq 0xc53(%rip), %rdx       # 0x582c5
jmp 0x57773
movl $0x10009, 0x8(%r14)     # imm = 0x10009
leaq 0xbd8fc(%rip), %rcx     # 0x114f82
movq %rcx, 0x40(%r14)
leaq 0x728(%rip), %rdx       # 0x57db9
jmp 0x57773
movl $0x1000b, 0x8(%r14)     # imm = 0x1000B
leaq 0xbd90d(%rip), %rcx     # 0x114fb2
movq %rcx, 0x40(%r14)
leaq 0x9b7(%rip), %rdx       # 0x58067
jmp 0x57773
movl $0x10007, 0x8(%r14)     # imm = 0x10007
leaq 0xbd90a(%rip), %rcx     # 0x114fce
movq %rcx, 0x40(%r14)
leaq 0xba0(%rip), %rdx       # 0x5826f
jmp 0x57773
movl $0x10006, 0x8(%r14)     # imm = 0x10006
leaq 0xbd884(%rip), %rcx     # 0x114f67
movq %rcx, 0x40(%r14)
leaq 0x551(%rip), %rdx       # 0x57c3f
jmp 0x57773
movl $0x1000a, 0x8(%r14)     # imm = 0x1000A
leaq 0xbd894(%rip), %rcx     # 0x114f96
movq %rcx, 0x40(%r14)
leaq 0x7c3(%rip), %rdx       # 0x57ed0
jmp 0x57773
movl $0x10008, 0x8(%r14)     # imm = 0x10008
leaq 0xbd8c2(%rip), %rcx     # 0x114fe0
movq %rcx, 0x40(%r14)
leaq 0xb74(%rip), %rdx       # 0x5829d
jmp 0x57773
cmpl $0x10005, %edi          # imm = 0x10005
jne 0x57777
cmpl $0x3, %eax
je 0x57759
cmpl $0x2, %eax
jne 0x57777
movl $0x1000d, 0x8(%r14)     # imm = 0x1000D
leaq 0xb0e21(%rip), %rcx     # 0x10856d
movq %rcx, 0x40(%r14)
leaq 0xd31(%rip), %rdx       # 0x58488
jmp 0x57773
movl $0x1000f, 0x8(%r14)     # imm = 0x1000F
leaq 0xbd895(%rip), %rcx     # 0x114ffd
movq %rcx, 0x40(%r14)
leaq 0xd26(%rip), %rdx       # 0x58499
movq %rdx, 0x38(%r14)
leaq 0xbd79a(%rip), %rsi     # 0x114f18
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x38(%r14), %rax
testq %rax, %rax
je 0x577b6
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq *%rax
cmpq $0x0, 0x38(%r14)
setne %al
orb 0x3(%rsp), %al
testb $0x1, %al
jne 0x5745d
jmp 0x577c1
cmpb $0x0, 0x3(%rsp)
jne 0x5745d
movl (%r14), %edx
movq 0x10(%r14), %rcx
leaq 0xbd761(%rip), %rsi     # 0x114f30
movq %rbx, %rdi
xorl %eax, %eax
callq 0xdf05a
jmp 0x5745d