// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/j2c.c
// Function: handler_tlm
static void handler_tlm(deark *c, lctx *d, struct page_ctx *pg,
	const struct marker_info *mi, i64 pos1, i64 len)
{
	u8 b;
	u8 item_size_code;
	i64 item_size;
	i64 pos = pos1;
	u8 t_code, p_code;
	i64 t_size, p_size;
	i64 num_items;
	i64 k;

	if(len<2) goto done;
	b = de_getbyte_p(&pos);
	de_dbg(c, "index: %d", (int)b);

	item_size_code = (i64)de_getbyte_p(&pos);
	de_dbg(c, "item size code: 0x%02x", (unsigned int)item_size_code);
	de_dbg_indent(c, 1);
	t_code = (item_size_code & 0x30)>>4;
	de_dbg(c, "size code for number field: %d", (int)t_code);
	p_code = (item_size_code & 0x40)>>6;
	de_dbg(c, "size code for length field: %d", (int)p_code);
	de_dbg_indent(c, -1);
	if(t_code==0) t_size=0;
	else if(t_code==1) t_size = 1;
	else if(t_code==2) t_size = 2;
	else goto done;
	if(p_code==0) p_size = 2;
	else p_size = 4;
	item_size = t_size + p_size;

	num_items = (pos1 + len - pos)/item_size;
	de_dbg(c, "calculated number of items: %d", (int)num_items);

	for(k=0; k<num_items; k++) {
		i64 x;
		de_dbg(c, "item[%d] at %"I64_FMT, (int)k, pos);
		de_dbg_indent(c, 1);
		if(t_size>0) {
			if(t_size==1) {
				x = (i64)de_getbyte_p(&pos);
			}
			else {
				x = de_getu16be_p(&pos);
			}
			de_dbg(c, "tile number: %u", (unsigned int)x);
		}

		if(p_size==2) {
			x = de_getu16be_p(&pos);
		}
		else {
			x = de_getu32be_p(&pos);
		}
		de_dbg(c, "tile length: %u", (unsigned int)x);
		de_dbg_indent(c, -1);
	}

done:
	;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, (%rsp)
cmpq $0x2, %r9
jl 0x88950
movq %r9, %r14
movq %rdi, %rbx
movq %r8, 0x8(%rsp)
movq 0x18(%rdi), %rdi
movq %rsp, %r12
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %edx
leaq 0x8a175(%rip), %rsi     # 0x112918
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %ebp
leaq 0xa4367(%rip), %rsi     # 0x12cb2a
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl %ebp, %r13d
shrb $0x4, %r13b
andb $0x3, %r13b
movzbl %r13b, %r12d
leaq 0xa434f(%rip), %rsi     # 0x12cb41
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
shrb $0x6, %bpl
andb $0x1, %bpl
movzbl %bpl, %r15d
leaq 0xa434e(%rip), %rsi     # 0x12cb60
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
testb %r12b, %r12b
je 0x88857
cmpb $0x1, %r13b
je 0x88865
cmpl $0x2, %r12d
movq 0x8(%rsp), %rax
jne 0x88950
movl $0x2, %r12d
movq $0x0, 0x10(%rsp)
jmp 0x88871
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
jmp 0x8886c
movb $0x1, %al
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rax
leaq (%r12,%r15,2), %rcx
addq $0x2, %rcx
addq %rax, %r14
subq (%rsp), %r14
movq %r14, %rax
cqto
idivq %rcx
movq %rax, %r14
leaq 0xa42ed(%rip), %rsi     # 0x12cb7f
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
testq %r14, %r14
jle 0x88950
movq %rsp, %r12
xorl %r15d, %r15d
movq (%rsp), %rcx
movq %rbx, %rdi
leaq 0x8d368(%rip), %rsi     # 0x115c24
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
testb %r13b, %r13b
je 0x8890c
movq 0x18(%rbx), %rdi
cmpb $0x0, 0x10(%rsp)
je 0x888f0
movq %r12, %rsi
callq 0xeeb4b
movzbl %al, %edx
jmp 0x888fb
movq %r12, %rsi
callq 0xeeb91
movq %rax, %rdx
movq %rbx, %rdi
leaq 0xa4299(%rip), %rsi     # 0x12cb9e
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
testb %bpl, %bpl
jne 0x8891f
callq 0xeeb91
jmp 0x88924
callq 0xeed31
movq %rbx, %rdi
leaq 0xa4280(%rip), %rsi     # 0x12cbae
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
incq %r15
cmpq %r15, %r14
jne 0x888ae
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq