// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x15b580
cmpq $0x6, -0x28(%rbp)
jge 0x80944
jmp 0x80ba7
cmpq $0x0, -0x18(%rbp)
je 0x80957
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x50(%rbp)
jmp 0x80961
movl $0x10002, %eax          # imm = 0x10002
movl %eax, -0x50(%rbp)
jmp 0x80961
movl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rdi
movl $0x50, %esi
callq 0x15b780
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x30(%rax)
movl -0x2c(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x809b2
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x155ddd(%rip), %rsi    # 0x1d67a2
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165580
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x12d0c5(%rip), %rsi    # 0x1adace
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x80a35
cmpl $0x0, -0x2c(%rbp)
jne 0x80a35
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x80a45
jmp 0x80ba7
movq -0x48(%rbp), %rax
cmpq $0x6, 0x18(%rax)
jge 0x80a6f
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x12d07a(%rip), %rsi    # 0x1adadd
movb $0x0, %al
callq 0x15bfb0
jmp 0x80ba7
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x28(%rbp), %rax
jle 0x80abf
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x48(%rbp), %rax
addq 0x18(%rax), %rcx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %r8
addq -0x28(%rbp), %r8
leaq 0x12d049(%rip), %rsi    # 0x1adaf5
movb $0x0, %al
callq 0x15bc10
movq -0x28(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rcx
addq $0x6, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rcx
subq $0x6, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x80bd0
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl (%rax), %edx
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rcx
leaq 0x12d000(%rip), %rsi    # 0x1adb40
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0x80b68
movq -0x48(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq *%rax
movq -0x48(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jne 0x80ba5
cmpl $0x10003, -0x4c(%rbp)   # imm = 0x10003
je 0x80b85
cmpl $0x10004, -0x4c(%rbp)   # imm = 0x10004
jne 0x80ba5
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl (%rax), %edx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rcx
leaq 0x12cfba(%rip), %rsi    # 0x1adb58
movb $0x0, %al
callq 0x15bc10
jmp 0x80ba7
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x15b5a0
movl -0x40(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)