// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/tim.c
// Function: de_run_tim
static void de_run_tim(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	unsigned int tim_type;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	d = de_malloc(c, sizeof(lctx));

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

	tim_type = (unsigned int)de_getu32le(4);
	d->bpp_code = tim_type & 0x07;
	d->palette_flag = (tim_type>>3)&0x01;

	de_dbg(c, "TIM type: 0x%08x", tim_type);
	de_dbg_indent(c, 1);

	switch(d->bpp_code) {
	case 0: d->bpp = 4; break;
	case 1: d->bpp = 8; break;
	case 2: d->bpp = 16; break;
	case 3: d->bpp = 24; break;
	case 4:
		de_err(c, "Mixed Format not supported");
		goto done;
	default:
		de_err(c, "Unknown bits/pixel code (%u)", d->bpp_code);
		goto done;
	}

	de_dbg(c, "bits/pixel: %d, has-palette: %u", (int)d->bpp, d->palette_flag);

	de_dbg_indent(c, -1); // end of TIM type field

	// Hack: Unindent as if the first header block were complete.
	// But it probably isn't. We'll re-indent if needed.
	de_dbg_indent(c, -1);

	switch(d->bpp) {
	case 8:
		do_pal8(c, d);
		break;
	default:
		de_err(c, "Unsupported bits/pixel (%d)", (int)d->bpp);
		goto done;
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
	de_free(c, d);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x15b580
movq -0x8(%rbp), %rdi
movl $0x420, %esi            # imm = 0x420
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x95cf0(%rip), %rsi     # 0x1cb9d2
xorl %edx, %edx
movb %dl, %al
movb %al, -0x2d(%rbp)
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
movl %esi, -0x2c(%rbp)
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x4, %esi
callq 0x165540
movq %rax, %rcx
movb -0x2d(%rbp), %al
movl %ecx, -0x1c(%rbp)
movl -0x1c(%rbp), %edx
andl $0x7, %edx
movq -0x18(%rbp), %rcx
movl %edx, (%rcx)
movl -0x1c(%rbp), %edx
shrl $0x3, %edx
andl $0x1, %edx
movq -0x18(%rbp), %rcx
movl %edx, 0x4(%rcx)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %edx
leaq 0x95ca7(%rip), %rsi     # 0x1cb9eb
callq 0x15b0d0
movl -0x2c(%rbp), %esi
movq -0x8(%rbp), %rdi
callq 0x15b560
movq -0x18(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x28(%rbp)
subq $0x4, %rax
ja 0x135dc8
movq -0x28(%rbp), %rax
leaq 0x95c30(%rip), %rcx     # 0x1cb9a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movq $0x4, 0x8(%rax)
jmp 0x135de2
movq -0x18(%rbp), %rax
movq $0x8, 0x8(%rax)
jmp 0x135de2
movq -0x18(%rbp), %rax
movq $0x10, 0x8(%rax)
jmp 0x135de2
movq -0x18(%rbp), %rax
movq $0x18, 0x8(%rax)
jmp 0x135de2
movq -0x8(%rbp), %rdi
leaq 0x95c40(%rip), %rsi     # 0x1cb9fc
movb $0x0, %al
callq 0x15bfb0
jmp 0x135e5a
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %edx
leaq 0x95c3e(%rip), %rsi     # 0x1cba17
movb $0x0, %al
callq 0x15bfb0
jmp 0x135e5a
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movl 0x8(%rax), %edx
leaq 0x95c3d(%rip), %rsi     # 0x1cba34
xorl %eax, %eax
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %esi, -0x34(%rbp)
callq 0x15b560
movl -0x34(%rbp), %esi
movq -0x8(%rbp), %rdi
callq 0x15b560
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
subq $0x8, %rax
jne 0x135e3a
jmp 0x135e2b
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x135f20
jmp 0x135e58
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
leaq 0x95c05(%rip), %rsi     # 0x1cba54
movb $0x0, %al
callq 0x15bfb0
jmp 0x135e5a
jmp 0x135e5a
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x15b5a0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)