// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tga.c
// Function: do_read_tga_headers
static int do_read_tga_headers(deark *c, lctx *d)
{
	int retval = 0;

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

	d->id_field_len = (i64)de_getbyte(0);
	de_dbg(c, "image ID len: %"I64_FMT, d->id_field_len);
	d->color_map_type = de_getbyte(1);
	de_dbg(c, "color map type: %d", (int)d->color_map_type);
	d->img_type = de_getbyte(2);
	de_dbg(c, "image type: %d", (int)d->img_type);

	switch(d->img_type) {
	case 0:
		d->color_type = TGA_CLRTYPE_UNKNOWN;
		d->clrtype_name = "no image";
		break;
	case 1: case 9:
	case 32: case 33:
		d->color_type = TGA_CLRTYPE_PALETTE;
		d->clrtype_name = "palette";
		break;
	case 2: case 10:
		d->color_type = TGA_CLRTYPE_TRUECOLOR;
		d->clrtype_name = "truecolor";
		break;
	case 3: case 11:
		d->color_type = TGA_CLRTYPE_GRAYSCALE;
		d->clrtype_name = "grayscale";
		break;
	default:
		d->color_type = TGA_CLRTYPE_UNKNOWN;
		d->clrtype_name = "unknown";
	}

	switch(d->img_type) {
	case 1: case 2: case 3:
		d->cmpr_type = TGA_CMPR_NONE;
		d->cmpr_name = "none";
		break;
	case 9: case 10: case 11:
		d->cmpr_type = TGA_CMPR_RLE;
		d->cmpr_name = "RLE";
		break;
	default:
		d->cmpr_type = TGA_CMPR_UNKNOWN;
		d->cmpr_name = "unknown";
	}

	de_dbg_indent(c, 1);
	de_dbg(c, "color type: %s", d->clrtype_name);
	de_dbg(c, "compression: %s", d->cmpr_name);
	de_dbg_indent(c, -1);

	if(d->color_map_type != 0) {
		d->cmap_start = de_getu16le(3);
		d->cmap_length = de_getu16le(5);
		d->cmap_depth = (i64)de_getbyte(7);
		de_dbg(c, "color map spec. at 3");
		de_dbg_indent(c, 1);
		de_dbg(c, "starting idx: %u", (UI)d->cmap_start);
		de_dbg(c, "num entries: %u", (UI)d->cmap_length);
		de_dbg(c, "bits/entry: %u", (UI)d->cmap_depth);
		de_dbg_indent(c, -1);
	}

	d->main_image.width = de_getu16le(12);
	d->main_image.height = de_getu16le(14);
	de_dbg_dimensions(c, d->main_image.width, d->main_image.height);

	d->pixel_depth = (i64)de_getbyte(16);
	de_dbg(c, "pixel depth: %d", (int)d->pixel_depth);

	do_read_image_descriptor(c, d);

	de_dbg_indent(c, -1);

	if(d->has_v2_signature) {
		do_read_footer(c, d);
	}

	if(!de_good_image_dimensions(c, d->main_image.width, d->main_image.height)) goto done;

	retval = 1;
done:
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x9988c(%rip), %rsi     # 0x1c4f8e
xorl %edx, %edx
movl %edx, -0x28(%rbp)
movb %dl, %al
movb %al, -0x21(%rbp)
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movl -0x28(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rdi
movl %eax, %esi
callq 0x165060
movb %al, %cl
movb -0x21(%rbp), %al
movzbl %cl, %ecx
movl %ecx, %edx
movq -0x10(%rbp), %rcx
movq %rdx, (%rcx)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rcx
movq (%rcx), %rdx
leaq 0x9c1bf(%rip), %rsi     # 0x1c7913
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x1, %esi
callq 0x165060
movb %al, %dl
movb -0x21(%rbp), %al
movq -0x10(%rbp), %rcx
movb %dl, 0x11(%rcx)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rcx
movzbl 0x11(%rcx), %edx
leaq 0x9c19b(%rip), %rsi     # 0x1c7925
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x2, %esi
callq 0x165060
movb %al, %dl
movb -0x21(%rbp), %al
movq -0x10(%rbp), %rcx
movb %dl, 0x12(%rcx)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rcx
movzbl 0x12(%rcx), %edx
leaq 0x9c178(%rip), %rsi     # 0x1c7938
callq 0x15b0d0
movq -0x10(%rbp), %rax
movzbl 0x12(%rax), %eax
movq %rax, -0x20(%rbp)
subq $0x21, %rax
ja 0x12b87a
movq -0x20(%rbp), %rax
leaq 0x9be9a(%rip), %rcx     # 0x1c7680
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movl $0x0, 0xa4(%rax)
movq -0x10(%rbp), %rax
leaq 0x9c13f(%rip), %rcx     # 0x1c7947
movq %rcx, 0xb0(%rax)
jmp 0x12b89a
movq -0x10(%rbp), %rax
movl $0x1, 0xa4(%rax)
movq -0x10(%rbp), %rax
leaq 0x96589(%rip), %rcx     # 0x1c1db6
movq %rcx, 0xb0(%rax)
jmp 0x12b89a
movq -0x10(%rbp), %rax
movl $0x2, 0xa4(%rax)
movq -0x10(%rbp), %rax
leaq 0x9649e(%rip), %rcx     # 0x1c1ced
movq %rcx, 0xb0(%rax)
jmp 0x12b89a
movq -0x10(%rbp), %rax
movl $0x3, 0xa4(%rax)
movq -0x10(%rbp), %rax
leaq 0x76657(%rip), %rcx     # 0x1a1ec8
movq %rcx, 0xb0(%rax)
jmp 0x12b89a
movq -0x10(%rbp), %rax
movl $0x0, 0xa4(%rax)
movq -0x10(%rbp), %rax
leaq 0x72cc9(%rip), %rcx     # 0x19e55c
movq %rcx, 0xb0(%rax)
movq -0x10(%rbp), %rax
movzbl 0x12(%rax), %eax
movl %eax, -0x2c(%rbp)
decl %eax
subl $0x3, %eax
jb 0x12b8bb
jmp 0x12b8ae
movl -0x2c(%rbp), %eax
addl $-0x9, %eax
subl $0x3, %eax
jb 0x12b8dd
jmp 0x12b8ff
movq -0x10(%rbp), %rax
movl $0x1, 0xa0(%rax)
movq -0x10(%rbp), %rax
leaq 0x70e39(%rip), %rcx     # 0x19c70d
movq %rcx, 0xa8(%rax)
jmp 0x12b91f
movq -0x10(%rbp), %rax
movl $0x2, 0xa0(%rax)
movq -0x10(%rbp), %rax
leaq 0x84e1c(%rip), %rcx     # 0x1b0712
movq %rcx, 0xa8(%rax)
jmp 0x12b91f
movq -0x10(%rbp), %rax
movl $0x0, 0xa0(%rax)
movq -0x10(%rbp), %rax
leaq 0x72c44(%rip), %rcx     # 0x19e55c
movq %rcx, 0xa8(%rax)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rdx
leaq 0x9c00d(%rip), %rsi     # 0x1c7950
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xa8(%rax), %rdx
leaq 0x7d2c4(%rip), %rsi     # 0x1a8c24
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x10(%rbp), %rax
movzbl 0x11(%rax), %eax
cmpl $0x0, %eax
je 0x12ba61
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x3, %esi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x5, %esi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x7, %esi
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x8(%rbp), %rdi
leaq 0x9bf75(%rip), %rsi     # 0x1c795f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movl %eax, %edx
leaq 0x9bf60(%rip), %rsi     # 0x1c7974
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl %eax, %edx
leaq 0x9bf55(%rip), %rsi     # 0x1c7985
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movl %eax, %edx
leaq 0x9bf49(%rip), %rsi     # 0x1c7995
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0xc, %esi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0xe, %esi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
callq 0x15bba0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x10, %esi
callq 0x165060
movzbl %al, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movl %eax, %edx
leaq 0x9bdb3(%rip), %rsi     # 0x1c789b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x12c8d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x10(%rbp), %rax
cmpl $0x0, 0x98(%rax)
je 0x12bb24
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x12ca40
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
callq 0x16a850
cmpl $0x0, %eax
jne 0x12bb44
jmp 0x12bb4b
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)