// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/hlp.c
// Function: do_file_SYSTEM
static void do_file_SYSTEM(deark *c, lctx *d, i64 pos1, i64 len)
{
	i64 pos = pos1;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);

	// We'll read the SYSTEM "file" before pass 2, most importantly to record
	// the format version information.
	//
	// The SYSTEM file may contain a series of SYSTEMREC records that we want
	// to parse.
	// Note: It seems like we might have to make two (sub)passes over the
	// SYSTEMREC records, the first pass to collect the "charset" setting, so it
	// can be used to interpret records that appear before it. But I've never
	// seen a charset record that I can make sense of -- it's usually just a
	// random number of NUL bytes.

	if(d->pass!=1) goto done;

	if(!do_file_SYSTEM_header(c, d, pos)) goto done;
	pos += 12;

	if(d->ver_minor<=16) {
		d->help_file_title = ucstring_create(c);
		do_display_and_store_STRINGZ(c, d, pos, (pos1+len)-pos, "HelpFileTitle", d->help_file_title);
	}
	else {
		// A sequence of variable-sized SYSTEMRECs
		do_file_SYSTEM_SYSTEMRECS(c, d, pos, (pos1+len)-pos, 1);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x34(%rsp), %rsi
callq 0xe958c
cmpl $0x1, 0xa4(%r15)
jne 0x58e2e
leaq 0x28(%rsp), %rsi
movq %r13, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xef1ed
cmpq $0x36c, %rax            # imm = 0x36C
jne 0x58a76
leaq 0xc8f54(%rip), %rsi     # 0x121927
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
leaq 0x28(%rsp), %r12
movq %r12, %rsi
callq 0xef1ed
movl %eax, 0x8c(%r15)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
movl %eax, 0x88(%r15)
movl 0x8c(%r15), %ecx
leaq 0xc8f19(%rip), %rsi     # 0x12193f
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movl 0x88(%r15), %edx
cmpl $0x1, %edx
jne 0x58a8f
movq 0x18(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0xef475
movq %rax, %r12
leaq 0x120(%r15), %rdi
testq %rax, %rax
movq %rdi, 0x18(%rsp)
je 0x58aac
movq %r12, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0xeace2
movq 0x18(%rsp), %rdi
jmp 0x58aaf
leaq 0xc8e84(%rip), %rsi     # 0x121901
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe9df7
jmp 0x58e2e
movl 0x8c(%r15), %ecx
leaq 0xc8ebd(%rip), %rsi     # 0x12195a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9df7
jmp 0x58e2e
movb $0x0, (%rdi)
leaq 0x40(%rsp), %rbp
movl $0x40, %edx
movq %rbp, %rsi
xorl %ecx, %ecx
callq 0xeb4f8
leaq 0xc8eb0(%rip), %rsi     # 0x12197a
movq %rbx, %rdi
movl %r12d, %edx
movq %rbp, %rcx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
leaq 0x28(%rsp), %rsi
callq 0xef1ed
movq %rax, %r12
leaq 0xc8e99(%rip), %rsi     # 0x12198b
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe9226
cmpl $0x11, 0x8c(%r15)
jl 0x58b22
cmpl $0x4, %r12d
je 0x58b3a
cmpl $0x8, %r12d
jne 0x58b47
movl $0x1, 0x98(%r15)
jmp 0x58b2d
movl $0x0, 0x98(%r15)
movq $0x800, 0x90(%r15) # imm = 0x800
jmp 0x58b5d
movl $0x1, 0x98(%r15)
jmp 0x58b52
movl $0x0, 0x98(%r15)
movq $0x1000, 0x90(%r15) # imm = 0x1000
movl 0x98(%r15), %edx
leaq 0xc8e35(%rip), %rsi     # 0x1219a0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x90(%r15), %rdx
leaq 0xc8e32(%rip), %rsi     # 0x1219b5
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
leaq 0xc(%r13), %r12
cmpl $0x10, 0x8c(%r15)
jg 0x58bce
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x110(%r15)
addq $-0xc, %r14
leaq 0xc8d3e(%rip), %r8      # 0x1218f3
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %rax, %r9
callq 0x5980e
jmp 0x58e2e
movq %r12, 0x40(%rsp)
movq %r14, 0x20(%rsp)
leaq -0xc(%r14), %rax
cmpq $0x4, %rax
jl 0x58e2e
addq %r13, 0x20(%rsp)
leaq 0x128dee(%rip), %r14    # 0x1819e0
movq %r15, 0x38(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x40(%rsp), %rbp
movq %rbp, %rsi
callq 0xef1ed
movq %rax, %r13
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef1ed
movq %rax, 0x10(%rsp)
xorl %eax, %eax
cmpl %r13d, (%rax,%r14)
jne 0x58c2c
testb $0xf, 0x4(%rax,%r14)
je 0x58c40
movb $0x1, %cl
testb %cl, %cl
je 0x58c4f
addq $0x10, %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x58c1e
jmp 0x58c48
leaq (%r14,%rax), %rbp
xorl %ecx, %ecx
jmp 0x58c2e
leaq 0x128e91(%rip), %rbp    # 0x181ae0
movq 0x8(%rbp), %rcx
movq 0x40(%rsp), %r9
movq 0x10(%rsp), %r15
movq %r15, (%rsp)
movq %rbx, %rdi
leaq 0xc8d60(%rip), %rsi     # 0x1219cb
movl %r13d, %edx
movq %r12, %r8
xorl %eax, %eax
callq 0xe9226
movq 0x40(%rsp), %rax
addq %r15, %rax
cmpq 0x20(%rsp), %rax
movq 0x38(%rsp), %r15
jg 0x58e2e
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x40(%rsp), %r12
cmpl $0x2, %r13d
je 0x58cd4
cmpl $0x1, %r13d
jne 0x58d3f
cmpq $0x0, 0x110(%r15)
jne 0x58ccb
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x110(%r15)
movq 0x110(%r15), %r9
jmp 0x58cf4
cmpq $0x0, 0x118(%r15)
jne 0x58ced
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x118(%r15)
movq 0x118(%r15), %r9
movq 0x8(%rbp), %r8
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq 0x10(%rsp), %rbp
movq %rbp, %rcx
callq 0x5980e
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq 0x40(%rsp), %r12
addq %rbp, %r12
movq %r12, 0x40(%rsp)
movq 0x20(%rsp), %rax
subq %r12, %rax
cmpq $0x3, %rax
jg 0x58bf7
jmp 0x58e2e
cmpl $0x3, %r13d
setne %al
cmpq $0x4, 0x10(%rsp)
setne %cl
orb %al, %cl
jne 0x58d79
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef37e
movq %rbx, %rdi
leaq 0xc8d36(%rip), %rsi     # 0x121a9f
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x10(%rsp), %rbp
jmp 0x58d0e
cmpl $0x5, %r13d
jne 0x58dd6
movl $0x1, 0xac(%r15)
movq %rbx, %rdi
callq 0xea9a9
movq %rax, %r13
movq 0x18(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, 0x18(%r13)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rbp
movq %rbp, %rdx
leaq 0xc8291(%rip), %rcx     # 0x121049
movq %r13, %r8
movl $0x1, %r9d
callq 0xf0321
movq %rbx, %rdi
movq %r13, %rsi
callq 0xea9b3
jmp 0x58d0e
testb $0x10, 0x4(%rbp)
jne 0x58e11
cmpl $0x2, (%rbx)
movq 0x10(%rsp), %rbp
jl 0x58d0e
movq 0x18(%rbx), %rsi
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
movq %r12, %rdx
movq %rbp, %rcx
xorl %r9d, %r9d
callq 0xe975a
jmp 0x58d0e
movq 0x8(%rbp), %r8
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq 0x10(%rsp), %rbp
movq %rbp, %rcx
xorl %r9d, %r9d
jmp 0x58d09
movl 0x34(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq