// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/tivariable.c
// Function: do_ti83
static void do_ti83(deark *c, lctx *d)
{
	i64 pos;
	i64 data_section_size;
	i64 data_section_end;
	i64 var_data_size;
	u8 type_id;

	// 0-7: signature
	// 8-10: 0x1a 0x0a 0x00
	// 11-52: comment

	data_section_size = de_getu16le(53);
	de_dbg(c, "data section size: %d", (int)data_section_size);
	data_section_end = 55+data_section_size;
	if(data_section_end > c->infile->len) {
		de_err(c, "Data section goes beyond end of file");
		goto done;
	}

	// Read the variables
	pos = 55;
	while(pos < data_section_end) {
		var_data_size = de_getu16le(pos+2);
		type_id = de_getbyte(pos+4);
		pos += 15;
		if(d->fmt==DE_FMT_TI83F)
			pos += 2;
		de_dbg(c, "var type=0x%02x pos=%d len=%d", (unsigned int)type_id,
			(int)pos, (int)var_data_size);

		if(type_id==0x07) { // guess
			do_ti83_picture_var(c, d, pos);
		}
		else if(type_id==0x1a) {
			do_ti83c_picture_var(c, d, pos);
		}

		pos += var_data_size;
	}

done:
	;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r13
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
movl $0x35, %esi
callq 0xeebc8
movq %rax, %r15
leaq 0x6f44e(%rip), %rsi     # 0x14004e
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
leaq 0x37(%r15), %rcx
movq 0x18(%rbx), %rax
movq %rcx, 0x28(%rsp)
cmpq 0x18(%rax), %rcx
jle 0xd0c3f
leaq 0x6f43d(%rip), %rsi     # 0x140064
movq %rbx, %rdi
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9295
testq %r15, %r15
jle 0xd0ff2
movl $0x37, %r14d
movq %r13, 0x20(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x2(%r14), %rsi
callq 0xeebc8
movq %rax, %r12
movq 0x18(%rbx), %rdi
leaq 0x4(%r14), %rsi
callq 0xeead3
xorl %r15d, %r15d
cmpl $0x5, 0x10(%r13)
sete %r15b
leaq 0xf(%r14,%r15,2), %rcx
movzbl %al, %ebp
movq %rbx, %rdi
leaq 0x6f3fb(%rip), %rsi     # 0x140089
movl %ebp, %edx
movq %rcx, 0x10(%rsp)
movq %r12, 0x30(%rsp)
movl %r12d, %r8d
xorl %eax, %eax
callq 0xe8617
cmpb $0x1a, %bpl
je 0xd0d6f
cmpl $0x7, %ebp
jne 0xd0fda
movq %rbx, %rdi
leaq 0x6f3e6(%rip), %rsi     # 0x1400a7
movq 0x10(%rsp), %r14
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeebc8
movq %rax, %r15
movq %rbx, %rdi
leaq 0x6f3cc(%rip), %rsi     # 0x1400b5
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
leaq 0x2(%r14), %rbp
cmpq $0x55b9, %r15           # imm = 0x55B9
jne 0xd0e02
movq $0x109, (%r13)          # imm = 0x109
movq $0xa5, 0x8(%r13)
movl $0x109, %esi            # imm = 0x109
movl $0xa5, %edx
movq %rbx, %rdi
callq 0xe8f88
movq (%r13), %rsi
movq 0x8(%r13), %rdx
leaq 0x1(%rsi), %rax
shrq $0x3f, %rax
addq %rsi, %rax
incq %rax
sarq %rax
movq %rax, 0x8(%rsp)
imulq %rdx, %rax
addq %rbp, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xd0f12
movq %rbx, %rdi
leaq 0x41fb1(%rip), %rsi     # 0x112d14
xorl %eax, %eax
callq 0xe9295
jmp 0xd0fcf
movq %rbx, %rdi
leaq 0x6f32e(%rip), %rsi     # 0x1400a7
movq 0x10(%rsp), %r12
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq $0x85, (%r13)
movq $0x53, 0x8(%r13)
movl $0x85, %esi
movl $0x53, %edx
movq %rbx, %rdi
callq 0xe8f88
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rsi, %rcx
shlq $0x4, %rcx
leaq 0x1f(%rcx), %rax
addq $0x3e, %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
sarq $0x5, %rcx
shlq $0x2, %rcx
movq %rcx, (%rsp)
movq %rcx, %rax
imulq %rdx, %rax
addq %r12, %rax
addq $0x3, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xd0e25
movq %rbx, %rdi
leaq 0x41f1e(%rip), %rsi     # 0x112d14
xorl %eax, %eax
callq 0xe9295
jmp 0xd0f07
movq $0x5f, (%r13)
movq $0x3f, 0x8(%r13)
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xd13b4
jmp 0xd0fda
movq %rbx, %rdi
callq 0xf1db1
testl %eax, %eax
je 0xd0f07
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rbx, %rdi
movl $0x3, %ecx
callq 0xf266a
movq %rax, 0x18(%rsp)
movq 0x8(%r13), %rcx
testq %rcx, %rcx
jle 0xd0ef1
leaq 0xf(,%r15,2), %rdx
movq (%r13), %rax
addq %r14, %rdx
addq $0x4, %rdx
xorl %r12d, %r12d
testq %rax, %rax
jle 0xd0ee5
movq %rdx, 0x8(%rsp)
movq %rdx, %r13
xorl %ebp, %ebp
movq 0x18(%rsp), %r15
movq 0x18(%rbx), %rdi
leaq -0x1(%r13), %rsi
callq 0xeead3
movl %eax, %r14d
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeead3
movzbl %al, %eax
shll $0x8, %eax
movzbl %r14b, %edi
orl %eax, %edi
callq 0xec844
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movl %eax, %ecx
callq 0xf24ba
incq %rbp
movq 0x20(%rsp), %rax
movq (%rax), %rax
addq $0x2, %r13
cmpq %rax, %rbp
jl 0xd0e86
movq 0x20(%rsp), %r13
movq 0x8(%r13), %rcx
movq 0x8(%rsp), %rdx
incq %r12
addq (%rsp), %rdx
cmpq %rcx, %r12
jl 0xd0e72
movq 0x18(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0xf22dc
jmp 0xd0f0a
xorl %r14d, %r14d
movq %r14, %rdi
jmp 0xd0fd5
movq %rbx, %rdi
callq 0xf1db1
testl %eax, %eax
je 0xd0fcf
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0xf266a
movq %rax, %r15
movq 0x8(%r13), %rcx
testq %rcx, %rcx
jle 0xd0fc1
movq (%r13), %rax
xorl %r12d, %r12d
movq %rbp, (%rsp)
testq %rax, %rax
jle 0xd0fb9
movq %r13, %r14
movq %r12, %r13
imulq 0x8(%rsp), %r13
addq %rbp, %r13
xorl %ebp, %ebp
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
shrq %rsi
addq %r13, %rsi
callq 0xeead3
movl %eax, %ecx
andb $0xf, %cl
shrb $0x4, %al
testb $0x1, %bpl
movzbl %al, %eax
movzbl %cl, %ecx
cmovel %eax, %ecx
movl %ecx, %eax
shll $0x4, %eax
addl %ecx, %eax
movzbl %al, %ecx
movq %r15, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0xf2405
incq %rbp
movq (%r14), %rax
cmpq %rax, %rbp
jl 0xd0f64
movq 0x8(%r14), %rcx
movq %r14, %r13
movq (%rsp), %rbp
incq %r12
cmpq %rcx, %r12
jl 0xd0f4e
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf22dc
jmp 0xd0fd2
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xf228d
movq 0x10(%rsp), %rax
addq 0x30(%rsp), %rax
movq %rax, %r14
cmpq 0x28(%rsp), %rax
jl 0xd0c53
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq