// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/gif.c
// Function: do_read_screen_descriptor
static int do_read_screen_descriptor(deark *c, lctx *d, i64 pos)
{
	i64 bgcol_index;
	u8 packed_fields;
	u8 aspect_ratio_code;
	unsigned int n;
	unsigned int global_color_table_size_code;

	de_dbg(c, "screen descriptor at %d", (int)pos);
	de_dbg_indent(c, 1);

	d->screen_w = de_getu16le(pos);
	d->screen_h = de_getu16le(pos+2);
	de_dbg(c, "screen dimensions: %d"DE_CHAR_TIMES"%d", (int)d->screen_w, (int)d->screen_h);

	packed_fields = de_getbyte(pos+4);
	de_dbg(c, "packed fields: 0x%02x", (unsigned int)packed_fields);
	de_dbg_indent(c, 1);
	d->has_global_color_table = (packed_fields&0x80)?1:0;
	de_dbg(c, "global color table flag: %d", d->has_global_color_table);

	n = (packed_fields&0x70)>>4;
	de_dbg(c, "color resolution: %u (%u bit%s)", n, n+1U, n?"s":"");

	if(d->has_global_color_table) {
		unsigned int sf;
		sf = (packed_fields&0x08)?1:0;
		de_dbg(c, "global color table sorted: %u", sf);
	}

	if(d->has_global_color_table) {
		global_color_table_size_code = (unsigned int)(packed_fields&0x07);
		d->global_color_table_size = de_pow2((i64)global_color_table_size_code+1);
		de_dbg(c, "global color table size: %u (%d colors)",
			global_color_table_size_code, (int)d->global_color_table_size);
	}

	de_dbg_indent(c, -1);

	// We don't care about the background color, because we always assume the
	// background is transparent.
	// TODO: If we ever support writing background-color chunks to PNG files,
	// then we should look up this color and use it.
	bgcol_index = (i64)de_getbyte(pos+5);
	de_dbg(c, "background color index: %d", (int)bgcol_index);

	aspect_ratio_code = de_getbyte(pos+6);
	de_dbg(c, "aspect ratio code: %d", (int)aspect_ratio_code);
	if(aspect_ratio_code!=0 && aspect_ratio_code!=49) {
		d->fi->density.code = DE_DENSITY_UNK_UNITS;
		d->fi->density.xdens = 64.0;
		d->fi->density.ydens = 15.0 + (double)aspect_ratio_code;
	}

	de_dbg_indent(c, -1);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0x138c4b(%rip), %rsi    # 0x1ab6d0
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x2, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, %ecx
leaq 0x12a41b(%rip), %rsi    # 0x19cf10
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x165060
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x21(%rbp), %edx
leaq 0x138bc5(%rip), %rsi    # 0x1ab6e8
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movzbl -0x21(%rbp), %edx
andl $0x80, %edx
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovnel %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x28(%rax), %edx
leaq 0x138b96(%rip), %rsi    # 0x1ab6fe
movb $0x0, %al
callq 0x15b0d0
movzbl -0x21(%rbp), %eax
andl $0x70, %eax
sarl $0x4, %eax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %edx
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
movl -0x28(%rbp), %esi
leaq 0x15e03d(%rip), %r8     # 0x1d0bd0
leaq 0x12df96(%rip), %rax    # 0x1a0b30
cmpl $0x0, %esi
cmovneq %rax, %r8
leaq 0x138b72(%rip), %rsi    # 0x1ab71a
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x72be5
movzbl -0x21(%rbp), %edx
andl $0x8, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl -0x30(%rbp), %edx
leaq 0x138b5c(%rip), %rsi    # 0x1ab73a
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x72c31
movzbl -0x21(%rbp), %eax
andl $0x7, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %edi
addq $0x1, %rdi
callq 0x15ce50
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, %ecx
leaq 0x138b2e(%rip), %rsi    # 0x1ab758
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x5, %rsi
callq 0x165060
movzbl %al, %eax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0x138b14(%rip), %rsi    # 0x1ab780
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x6, %rsi
callq 0x165060
movb %al, -0x22(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x22(%rbp), %edx
leaq 0x138b01(%rip), %rsi    # 0x1ab79b
movb $0x0, %al
callq 0x15b0d0
movzbl -0x22(%rbp), %eax
cmpl $0x0, %eax
je 0x72d08
movzbl -0x22(%rbp), %eax
cmpl $0x31, %eax
je 0x72d08
movq -0x10(%rbp), %rax
movq 0x448(%rax), %rax
movl $0x1, 0x78(%rax)
movq -0x10(%rbp), %rax
movq 0x448(%rax), %rax
movabsq $0x4050000000000000, %rcx # imm = 0x4050000000000000
movq %rcx, 0x80(%rax)
movzbl -0x22(%rbp), %eax
cvtsi2sd %eax, %xmm1
movsd 0x13894f(%rip), %xmm0   # 0x1ab640
addsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movq 0x448(%rax), %rax
movsd %xmm0, 0x88(%rax)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl $0x1, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)