// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
movl $0x35, %esi
callq 0xef1ca
movq %rax, %r15
leaq 0x6e441(%rip), %rsi     # 0x13fc46
movq %rbx, %rdi
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
leaq 0x37(%r15), %rcx
movq 0x18(%rbx), %rax
movq %rcx, 0x20(%rsp)
cmpq 0x18(%rax), %rcx
jle 0xd1844
leaq 0x6e430(%rip), %rsi     # 0x13fc5c
movq %rbx, %rdi
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe9df7
testq %r15, %r15
jle 0xd1c09
movl $0x37, %r14d
leaq 0x6e427(%rip), %r12     # 0x13fc81
movq 0x18(%rbx), %rdi
leaq 0x2(%r14), %rsi
callq 0xef1ca
movq %rax, %r13
movq 0x18(%rbx), %rdi
leaq 0x4(%r14), %rsi
callq 0xef0d5
xorl %r15d, %r15d
movq 0x8(%rsp), %rcx
cmpl $0x5, 0x10(%rcx)
sete %r15b
leaq 0xf(%r14,%r15,2), %rcx
movzbl %al, %ebp
movq %rbx, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %rcx, 0x18(%rsp)
movq %r13, 0x28(%rsp)
movl %r13d, %r8d
xorl %eax, %eax
callq 0xe9226
cmpb $0x1a, %bpl
je 0xd1978
cmpl $0x7, %ebp
movq 0x18(%rsp), %r13
jne 0xd1bf6
movq %rbx, %rdi
leaq 0x6e3d2(%rip), %rsi     # 0x13fc9f
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef1ca
movq %rax, %r15
movq %rbx, %rdi
leaq 0x6e3bd(%rip), %rsi     # 0x13fcad
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
leaq 0x2(%r13), %rbp
cmpq $0x55b9, %r15           # imm = 0x55B9
jne 0xd1a13
movq 0x8(%rsp), %r14
movq $0x109, (%r14)          # imm = 0x109
movq $0xa5, 0x8(%r14)
movl $0x109, %esi            # imm = 0x109
movl $0xa5, %edx
movq %rbx, %rdi
callq 0xe9b05
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq 0x1(%rsi), %rax
shrq $0x3f, %rax
leaq (%rsi,%rax), %r14
incq %r14
sarq %r14
movq %r14, %rax
imulq %rdx, %rax
addq %rbp, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xd1b2a
movq %rbx, %rdi
leaq 0x41398(%rip), %rsi     # 0x112d04
xorl %eax, %eax
callq 0xe9df7
jmp 0xd1beb
movq %rbx, %rdi
leaq 0x6e31d(%rip), %rsi     # 0x13fc9f
movq 0x18(%rsp), %r13
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x8(%rsp), %r12
movq $0x85, (%r12)
movq $0x53, 0x8(%r12)
movl $0x85, %esi
movl $0x53, %edx
movq %rbx, %rdi
callq 0xe9b05
movq (%r12), %rsi
movq 0x8(%r12), %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, 0x30(%rsp)
movq %rcx, %rax
imulq %rdx, %rax
addq %r13, %rax
addq $0x3, %rax
movq 0x18(%rbx), %rcx
cmpq 0x18(%rcx), %rax
jle 0xd1a37
movq %rbx, %rdi
leaq 0x412fd(%rip), %rsi     # 0x112d04
xorl %eax, %eax
callq 0xe9df7
jmp 0xd1b13
movq 0x8(%rsp), %rsi
movq $0x5f, (%rsi)
movq $0x3f, 0x8(%rsi)
movq %rbx, %rdi
movq %rbp, %rdx
callq 0xd1fcb
jmp 0xd1bf6
movq %rbx, %rdi
callq 0xf241d
testl %eax, %eax
je 0xd1b13
movq 0x8(%rsp), %r12
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %rbx, %rdi
movl $0x3, %ecx
callq 0xf2cab
movq %r12, %rcx
movq %rax, %r12
cmpq $0x0, 0x8(%rcx)
jle 0xd1afd
leaq 0xf(,%r15,2), %rax
addq %r14, %rax
addq $0x4, %rax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
cmpq $0x0, (%rcx)
jle 0xd1ae5
movq 0x10(%rsp), %r13
xorl %ebp, %ebp
movq 0x18(%rbx), %rdi
leaq -0x1(%r13), %rsi
callq 0xef0d5
movl %eax, %r14d
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xef0d5
movzbl %al, %eax
shll $0x8, %eax
movzbl %r14b, %edi
orl %eax, %edi
callq 0xece9d
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movl %eax, %ecx
callq 0xf2afd
movq 0x8(%rsp), %rcx
incq %rbp
addq $0x2, %r13
cmpq (%rcx), %rbp
jl 0xd1a97
incq %r15
movq 0x10(%rsp), %rax
addq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq 0x8(%rcx), %r15
jl 0xd1a8a
movq %r12, %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0xf2923
movq 0x18(%rsp), %r13
jmp 0xd1b16
xorl %r12d, %r12d
movq %r12, %rdi
callq 0xf28d4
leaq 0x6e15c(%rip), %r12     # 0x13fc81
jmp 0xd1bf6
movq %rbx, %rdi
callq 0xf241d
testl %eax, %eax
je 0xd1beb
movq %rbp, 0x10(%rsp)
movq 0x8(%rsp), %r15
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0xf2cab
movq %r15, %rcx
movq %rax, %r15
cmpq $0x0, 0x8(%rcx)
jle 0xd1bd1
xorl %r13d, %r13d
cmpq $0x0, (%rcx)
jle 0xd1bc8
movq %r13, %r12
imulq %r14, %r12
addq 0x10(%rsp), %r12
xorl %ebp, %ebp
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
shrq %rsi
addq %r12, %rsi
callq 0xef0d5
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 %r13, %rdx
callq 0xf2a4a
movq 0x8(%rsp), %rcx
incq %rbp
cmpq (%rcx), %rbp
jl 0xd1b7c
incq %r13
cmpq 0x8(%rcx), %r13
jl 0xd1b68
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xf2923
leaq 0x6e09d(%rip), %r12     # 0x13fc81
movq 0x18(%rsp), %r13
jmp 0xd1bee
xorl %r15d, %r15d
movq %r15, %rdi
callq 0xf28d4
addq 0x28(%rsp), %r13
movq %r13, %r14
cmpq 0x20(%rsp), %r13
jl 0xd185a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq