// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/flif.c
// Function: do_read_header
static int do_read_header(deark *c, lctx *d, i64 pos1,
	i64 *bytes_consumed)
{
	i64 pos = pos1;
	u8 b;
	u8 intl_anim_code;
	u8 bytes_per_channel_code;
	i64 tmpcode;
	i64 bytes_consumed2;
	int retval = 0;
	char tmps[80];

	de_dbg(c, "header at %d", (int)pos1);
	de_dbg_indent(c, 1);

	pos += 4; // Magic

	b = de_getbyte(pos++);

	intl_anim_code = (b&0xf0)>>4;
	switch(intl_anim_code) {
	case 3: break;
	case 4: d->is_interlaced = 1; break;
	case 5: d->is_animated = 1; break;
	case 6: d->is_interlaced = 1; d->is_animated = 1; break;
	default:
		de_warn(c, "Unknown interlace/animation code: %d", (int)intl_anim_code);
	}
	de_dbg(c, "interlaced: %d", d->is_interlaced);
	de_dbg(c, "animated: %d", d->is_animated);

	d->num_channels = (i64)(b&0x0f);
	de_dbg(c, "number of channels: %d", (int)d->num_channels);

	bytes_per_channel_code = de_getbyte(pos++);
	if(bytes_per_channel_code=='0') {
		de_strlcpy(tmps, "custom", sizeof(tmps));
	}
	else if(bytes_per_channel_code=='1' || bytes_per_channel_code=='2') {
		d->bytes_per_channel = (i64)(bytes_per_channel_code-'0');
		de_snprintf(tmps, sizeof(tmps), "%d", (int)(d->bytes_per_channel));
	}
	else {
		de_strlcpy(tmps, "?", sizeof(tmps));
	}
	de_dbg(c, "bytes per channel: 0x%02x (%s)",
		(unsigned int)bytes_per_channel_code, tmps);

	if(!read_varint(c, pos, &tmpcode, &bytes_consumed2)) goto done;
	d->width = tmpcode+1;
	pos += bytes_consumed2;

	if(!read_varint(c, pos, &tmpcode, &bytes_consumed2)) goto done;
	d->height = tmpcode+1;
	pos += bytes_consumed2;

	de_dbg_dimensions(c, d->width, d->height);

	if(d->is_animated) {
		if(!read_varint(c, pos, &tmpcode, &bytes_consumed2)) goto done;
		d->nb_frames = tmpcode+2;
		pos += bytes_consumed2;
		de_dbg(c, "number of frames: %d", (int)d->nb_frames);
	}
	else {
		d->nb_frames = 1;
	}

	retval = 1;
done:
	*bytes_consumed = pos - pos1;
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %edx
leaq 0x157056(%rip), %rsi    # 0x1c4f8e
xorl %eax, %eax
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x28(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq %rsi, %rax
incq %rax
movq %rax, -0x28(%rbp)
callq 0x165060
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %eax
shrl $0x4, %eax
movb %al, -0x2a(%rbp)
movzbl -0x2a(%rbp), %eax
addl $-0x3, %eax
movl %eax, %ecx
movq %rcx, -0xa8(%rbp)
subl $0x3, %eax
ja 0x6dfdf
movq -0xa8(%rbp), %rax
leaq 0x13c870(%rip), %rcx    # 0x1aa814
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x6dff5
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
jmp 0x6dff5
movq -0x10(%rbp), %rax
movl $0x1, 0x4(%rax)
jmp 0x6dff5
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x4(%rax)
jmp 0x6dff5
movq -0x8(%rbp), %rdi
movzbl -0x2a(%rbp), %edx
leaq 0x13c84d(%rip), %rsi    # 0x1aa83b
movb $0x0, %al
callq 0x15bc10
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
leaq 0x13c85a(%rip), %rsi    # 0x1aa860
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
leaq 0x13c850(%rip), %rsi    # 0x1aa86f
movb $0x0, %al
callq 0x15b0d0
movzbl -0x29(%rbp), %eax
andl $0xf, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
leaq 0x13c82f(%rip), %rsi    # 0x1aa87c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
callq 0x165060
movb %al, -0x2b(%rbp)
movzbl -0x2b(%rbp), %eax
cmpl $0x30, %eax
jne 0x6e096
leaq -0xa0(%rbp), %rdi
leaq 0x13c809(%rip), %rsi    # 0x1aa893
movl $0x50, %edx
callq 0x15aa30
jmp 0x6e0fa
movzbl -0x2b(%rbp), %eax
cmpl $0x31, %eax
je 0x6e0a8
movzbl -0x2b(%rbp), %eax
cmpl $0x32, %eax
jne 0x6e0e0
movzbl -0x2b(%rbp), %eax
subl $0x30, %eax
movslq %eax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
leaq -0xa0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
movl $0x50, %esi
leaq 0x153b47(%rip), %rdx    # 0x1c1c1e
movb $0x0, %al
callq 0x15a980
jmp 0x6e0f8
leaq -0xa0(%rbp), %rdi
leaq 0x149b3f(%rip), %rsi    # 0x1b7c2d
movl $0x50, %edx
callq 0x15aa30
jmp 0x6e0fa
movq -0x8(%rbp), %rdi
movzbl -0x2b(%rbp), %edx
leaq -0xa0(%rbp), %rcx
leaq 0x13c78a(%rip), %rsi    # 0x1aa89a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x6e3d0
cmpl $0x0, %eax
jne 0x6e136
jmp 0x6e219
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x6e3d0
cmpl $0x0, %eax
jne 0x6e171
jmp 0x6e219
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
callq 0x15bba0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x6e206
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq -0x38(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x6e3d0
cmpl $0x0, %eax
jne 0x6e1cc
jmp 0x6e219
movq -0x38(%rbp), %rcx
addq $0x2, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x40(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl %eax, %edx
leaq 0x131873(%rip), %rsi    # 0x19fa70
movb $0x0, %al
callq 0x15b0d0
jmp 0x6e212
movq -0x10(%rbp), %rax
movq $0x1, 0x28(%rax)
movl $0x1, -0x44(%rbp)
movq -0x28(%rbp), %rcx
subq -0x18(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x44(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)