// File: /workspace/github_c_makefile_star2_O1/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 0x89041
movq %r9, %r14
movq %rdi, %rbx
movq %r8, 0x8(%rsp)
movq 0x18(%rdi), %rdi
movq %rsp, %r12
movq %r12, %rsi
callq 0xef14d
movzbl %al, %edx
leaq 0x89a74(%rip), %rsi     # 0x112908
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef14d
movzbl %al, %ebp
leaq 0xa398e(%rip), %rsi     # 0x12c842
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movl %ebp, %r13d
shrb $0x4, %r13b
andb $0x3, %r13b
movzbl %r13b, %r12d
leaq 0xa3976(%rip), %rsi     # 0x12c859
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
shrb $0x6, %bpl
andb $0x1, %bpl
movzbl %bpl, %r15d
leaq 0xa3975(%rip), %rsi     # 0x12c878
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
testb %r12b, %r12b
je 0x88f48
cmpb $0x1, %r13b
je 0x88f56
cmpl $0x2, %r12d
movq 0x8(%rsp), %rax
jne 0x89041
movl $0x2, %r12d
movq $0x0, 0x10(%rsp)
jmp 0x88f62
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
jmp 0x88f5d
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 0xa3914(%rip), %rsi     # 0x12c897
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xe9226
testq %r14, %r14
jle 0x89041
movq %rsp, %r12
xorl %r15d, %r15d
movq (%rsp), %rcx
movq %rbx, %rdi
leaq 0x8cbc7(%rip), %rsi     # 0x115b74
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
testb %r13b, %r13b
je 0x88ffd
movq 0x18(%rbx), %rdi
cmpb $0x0, 0x10(%rsp)
je 0x88fe1
movq %r12, %rsi
callq 0xef14d
movzbl %al, %edx
jmp 0x88fec
movq %r12, %rsi
callq 0xef193
movq %rax, %rdx
movq %rbx, %rdi
leaq 0xa38c0(%rip), %rsi     # 0x12c8b6
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r12, %rsi
testb %bpl, %bpl
jne 0x89010
callq 0xef193
jmp 0x89015
callq 0xef34e
movq %rbx, %rdi
leaq 0xa38a7(%rip), %rsi     # 0x12c8c6
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
incq %r15
cmpq %r15, %r14
jne 0x88f9f
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq