// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
cmpq $0x2, %r9
jge 0x837a5
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, %r15
movq %rdi, %rbx
movq %r8, (%rsp)
movq 0x18(%rdi), %rdi
leaq 0x10(%rsp), %r12
movq %r12, %rsi
callq 0xe3f2a
movzbl %al, %edx
leaq 0x8212e(%rip), %rsi     # 0x1058f8
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3f2a
movzbl %al, %ebp
leaq 0x9c0d0(%rip), %rsi     # 0x11f8ba
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movl %ebp, %r13d
shrb $0x4, %r13b
andb $0x3, %r13b
movzbl %r13b, %r12d
leaq 0x9c0ba(%rip), %rsi     # 0x11f8d1
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
shrb $0x6, %bpl
andb $0x1, %bpl
movzbl %bpl, %r14d
leaq 0x9c0b9(%rip), %rsi     # 0x11f8f0
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
testb %r12b, %r12b
je 0x83877
cmpb $0x1, %r13b
je 0x83885
cmpl $0x2, %r12d
movq (%rsp), %rax
jne 0x83796
pushq $0x2
popq %r12
movq $0x0, 0x8(%rsp)
jmp 0x83890
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
jmp 0x8388c
movb $0x1, %al
movq %rax, 0x8(%rsp)
movq (%rsp), %rax
leaq (%r12,%r14,2), %rcx
addq $0x2, %rcx
addq %rax, %r15
leaq 0x10(%rsp), %r14
subq (%r14), %r15
movq %r15, %rax
cqto
idivq %rcx
movq %rax, %r15
leaq 0x9c05a(%rip), %rsi     # 0x11f90f
xorl %r12d, %r12d
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
testq %r15, %r15
cmovleq %r12, %r15
xorl %r12d, %r12d
cmpq %r12, %r15
je 0x83796
movq 0x10(%rsp), %rcx
movq %rbx, %rdi
leaq 0x852ad(%rip), %rsi     # 0x108b94
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
testb %r13b, %r13b
je 0x83935
movq 0x18(%rbx), %rdi
cmpb $0x0, 0x8(%rsp)
je 0x83919
movq %r14, %rsi
callq 0xe3f2a
movzbl %al, %edx
jmp 0x83924
movq %r14, %rsi
callq 0xe3f6e
movq %rax, %rdx
movq %rbx, %rdi
leaq 0x9c000(%rip), %rsi     # 0x11f92e
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r14, %rsi
testb %bpl, %bpl
jne 0x83948
callq 0xe3f6e
jmp 0x8394d
callq 0xe4071
movq %rbx, %rdi
leaq 0x9bfe7(%rip), %rsi     # 0x11f93e
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
incq %r12
jmp 0x838cf