// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x35
popq %rsi
callq 0xe3fa3
movq %rax, %r12
leaq 0x6aca7(%rip), %rsi     # 0x132d1e
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
addq $0x37, %r12
movq 0x18(%rbx), %rax
cmpq 0x18(%rax), %r12
jle 0xc80b1
leaq 0x6ac9b(%rip), %rsi     # 0x132d34
movq %rbx, %rdi
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdf2a5
pushq $0x37
popq %r14
movq %r12, 0x20(%rsp)
cmpq %r12, %r14
jge 0xc843c
movq 0x18(%rbx), %rdi
leaq 0x2(%r14), %rsi
callq 0xe3fa3
movq %rax, %r13
movq 0x18(%rbx), %rdi
leaq 0x4(%r14), %rsi
callq 0xe3eb4
xorl %r15d, %r15d
movq 0x8(%rsp), %rcx
cmpl $0x5, 0x10(%rcx)
sete %r15b
leaq (%r14,%r15,2), %rcx
addq $0xf, %rcx
movzbl %al, %ebp
movq %rbx, %rdi
leaq 0x6ac54(%rip), %rsi     # 0x132d59
movl %ebp, %edx
movq %rcx, 0x10(%rsp)
movq %r13, 0x28(%rsp)
movl %r13d, %r8d
xorl %eax, %eax
callq 0xde896
cmpb $0x1a, %bpl
je 0xc81e4
cmpl $0x7, %ebp
movq 0x10(%rsp), %r13
jne 0xc842f
movq %rbx, %rdi
leaq 0x6ac3a(%rip), %rsi     # 0x132d77
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fa3
movq %rax, %r15
movq %rbx, %rdi
leaq 0x6ac25(%rip), %rsi     # 0x132d85
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
leaq 0x2(%r13), %rbp
cmpq $0x55b9, %r15           # imm = 0x55B9
jne 0xc8273
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 0xdf038
movq (%r14), %rsi
movq 0x8(%r14), %rcx
leaq 0x1(%rsi), %rax
cqto
pushq $0x2
popq %rdi
idivq %rdi
movq %rax, 0x18(%rsp)
imulq %rcx, %rax
addq %rbp, %rax
movq 0x18(%rbx), %rdx
cmpq 0x18(%rdx), %rax
jle 0xc8371
movq %rbx, %rdi
leaq 0x3db1c(%rip), %rsi     # 0x105cf4
xorl %eax, %eax
callq 0xdf2a5
jmp 0xc840d
movq %rbx, %rdi
leaq 0x6ab89(%rip), %rsi     # 0x132d77
movq 0x10(%rsp), %r13
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x8(%rsp), %r12
movq $0x85, (%r12)
movq $0x53, 0x8(%r12)
movl $0x85, %esi
movq %rbx, %rdi
pushq $0x53
popq %rdx
callq 0xdf038
movq (%r12), %rsi
movq 0x8(%r12), %rcx
movq %rsi, %rax
shlq $0x4, %rax
addq $0x1f, %rax
cqto
pushq $0x20
popq %rdi
idivq %rdi
shlq $0x2, %rax
movq %rax, 0x30(%rsp)
imulq %rcx, %rax
addq %r13, %rax
addq $0x3, %rax
movq 0x18(%rbx), %rdx
cmpq 0x18(%rdx), %rax
jle 0xc8297
movq %rbx, %rdi
leaq 0x3da8d(%rip), %rsi     # 0x105cf4
xorl %eax, %eax
callq 0xdf2a5
jmp 0xc8348
movq 0x8(%rsp), %rsi
movq $0x5f, (%rsi)
movq $0x3f, 0x8(%rsi)
movq %rbx, %rdi
movq %rbp, %rdx
callq 0xc87dd
jmp 0xc842f
movq %rbx, %rdi
movq %rcx, %rdx
callq 0xe6be1
testl %eax, %eax
je 0xc8348
leaq 0xf(,%r15,2), %r12
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
pushq $0x3
popq %rcx
callq 0xe7437
movq %rax, %r15
leaq (%r12,%r14), %r13
addq $0x4, %r13
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
cmpq 0x8(%rax), %rbp
jge 0xc834d
movq %r13, 0x18(%rsp)
xorl %r12d, %r12d
movq 0x8(%rsp), %rax
cmpq (%rax), %r12
jge 0xc8339
movq 0x18(%rbx), %rdi
leaq -0x1(%r13), %rsi
callq 0xe3eb4
movl %eax, %r14d
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3eb4
movzbl %al, %eax
shll $0x8, %eax
movzbl %r14b, %edi
orl %eax, %edi
callq 0xe1da6
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movl %eax, %ecx
callq 0xe7287
incq %r12
addq $0x2, %r13
jmp 0xc82e9
incq %rbp
movq 0x18(%rsp), %r13
addq 0x30(%rsp), %r13
jmp 0xc82d6
xorl %r15d, %r15d
jmp 0xc835f
movq %r15, %rdi
xorl %esi, %esi
pushq $0x4
popq %rdx
callq 0xe70b7
movq 0x10(%rsp), %r13
movq %r15, %rdi
callq 0xe7084
movq 0x20(%rsp), %r12
jmp 0xc842f
movq %rbx, %rdi
movq %rcx, %rdx
callq 0xe6be1
testl %eax, %eax
je 0xc840d
movq %rbp, %r15
movq 0x8(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbx, %rdi
pushq $0x1
popq %rcx
callq 0xe7437
movq %rax, %rbp
xorl %r12d, %r12d
movq 0x8(%rsp), %rax
cmpq 0x8(%rax), %r12
jge 0xc8411
movq %r12, %r14
imulq 0x18(%rsp), %r14
addq %r15, %r14
xorl %r13d, %r13d
movq 0x8(%rsp), %rax
cmpq (%rax), %r13
jge 0xc8408
movq 0x18(%rbx), %rdi
movq %r13, %rsi
shrq %rsi
addq %r14, %rsi
callq 0xe3eb4
movl %eax, %ecx
andb $0xf, %cl
shrb $0x4, %al
testb $0x1, %r13b
movzbl %al, %eax
movzbl %cl, %ecx
cmovel %eax, %ecx
imull $0x11, %ecx, %eax
movzbl %al, %ecx
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0xe71da
incq %r13
jmp 0xc83be
incq %r12
jmp 0xc83a4
xorl %ebp, %ebp
jmp 0xc8422
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xe70b7
movq 0x20(%rsp), %r12
movq %rbp, %rdi
callq 0xe7084
movq 0x10(%rsp), %r13
addq 0x28(%rsp), %r13
movq %r13, %r14
jmp 0xc80ba
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq