// File: /workspace/github_c_makefile_star2_O3/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 $0x98, %rsp
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x44(%rsp), %rsi
callq 0xe8a1c
cmpl $0x1, 0xa4(%r12)
jne 0x58c57
leaq 0x38(%rsp), %rsi
movq %r13, (%rsi)
movq 0x18(%rbx), %rdi
callq 0xeebeb
cmpq $0x36c, %rax            # imm = 0x36C
jne 0x58868
leaq 0xc9278(%rip), %rsi     # 0x121a33
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
leaq 0x38(%rsp), %r14
movq %r14, %rsi
callq 0xeebeb
movl %eax, 0x8c(%r12)
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeebeb
movl %eax, 0x88(%r12)
movl 0x8c(%r12), %ecx
leaq 0xc923a(%rip), %rsi     # 0x121a4b
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl 0x88(%r12), %edx
cmpl $0x1, %edx
jne 0x58881
movq 0x18(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0xeee2f
movq %rax, %r14
leaq 0x120(%r12), %rdi
testq %rax, %rax
movq %r12, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
je 0x5889f
movq %r14, %rdi
movq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0xea7f5
movq 0x20(%rsp), %rdi
jmp 0x588a2
leaq 0xc919e(%rip), %rsi     # 0x121a0d
movq %rbx, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe9295
jmp 0x58c57
movl 0x8c(%r12), %ecx
leaq 0xc91d6(%rip), %rsi     # 0x121a66
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9295
jmp 0x58c57
movb $0x0, (%rdi)
leaq 0x50(%rsp), %r12
xorl %ebp, %ebp
movl $0x40, %edx
movq %r12, %rsi
xorl %ecx, %ecx
callq 0xeaf46
leaq 0xc91c7(%rip), %rsi     # 0x121a86
movq %rbx, %rdi
movl %r14d, %edx
movq %r12, %rcx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0xeebeb
movq %rax, %r12
leaq 0xc91b0(%rip), %rsi     # 0x121a97
movq %rbx, %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%rsp), %r14
cmpl $0x11, 0x8c(%r14)
jl 0x5892c
cmpl $0x4, %r12d
je 0x58944
cmpl $0x8, %r12d
jne 0x58966
movq 0x10(%rsp), %r14
movl $0x1, 0x98(%r14)
movq $0x800, 0x90(%r14) # imm = 0x800
jmp 0x5895f
movl $0x0, 0x98(%r14)
movq $0x800, 0x90(%r14) # imm = 0x800
jmp 0x58981
movq 0x10(%rsp), %r14
movl $0x1, 0x98(%r14)
movq $0x1000, 0x90(%r14) # imm = 0x1000
movl $0x1, %ebp
jmp 0x58981
movq 0x10(%rsp), %r14
movl $0x0, 0x98(%r14)
movq $0x1000, 0x90(%r14) # imm = 0x1000
leaq 0xc9124(%rip), %rsi     # 0x121aac
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x90(%r14), %rdx
leaq 0xc911f(%rip), %rsi     # 0x121ac1
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
leaq 0xc(%r13), %r12
cmpl $0x10, 0x8c(%r14)
jg 0x589ed
movq %rbx, %rdi
callq 0xf6410
movq %rax, 0x110(%r14)
addq $-0xc, %r15
leaq 0xc902b(%rip), %r8      # 0x1219ff
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %rax, %r9
callq 0x5960e
jmp 0x58c57
movq %r15, 0x30(%rsp)
leaq -0xc(%r15), %rax
movq %r12, 0x50(%rsp)
cmpq $0x4, %rax
jl 0x58c57
addq %r13, 0x30(%rsp)
leaq 0x12906f(%rip), %r15    # 0x181a80
movq %rbx, 0x48(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x50(%rsp), %r13
movq %r13, %rsi
callq 0xeebeb
movq %rax, %r14
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeebeb
movq %rax, 0x18(%rsp)
xorl %ebp, %ebp
cmpl %r14d, (%rbp,%r15)
jne 0x58a4c
testb $0xf, 0x4(%rbp,%r15)
je 0x58a62
addq $0x10, %rbp
cmpq $0x100, %rbp            # imm = 0x100
jne 0x58a3d
leaq 0x129120(%rip), %rbp    # 0x181b80
jmp 0x58a65
addq %r15, %rbp
movq 0x8(%rbp), %rcx
movq 0x50(%rsp), %r9
movq 0x18(%rsp), %r13
movq %r13, (%rsp)
movq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0xc9051(%rip), %rsi     # 0x121ad7
movl %r14d, %edx
movq %rcx, 0x28(%rsp)
movq %r12, %r8
xorl %eax, %eax
callq 0xe8617
movq 0x50(%rsp), %rax
addq %r13, %rax
cmpq 0x30(%rsp), %rax
jg 0x58c57
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x50(%rsp), %r12
cmpl $0x2, %r14d
je 0x58af2
cmpl $0x1, %r14d
jne 0x58b61
movq 0x10(%rsp), %r14
movq 0x110(%r14), %r9
testq %r9, %r9
jne 0x58b15
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r9
movq %rax, 0x110(%r14)
jmp 0x58b15
movq 0x10(%rsp), %r14
movq 0x118(%r14), %r9
testq %r9, %r9
jne 0x58b15
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r9
movq %rax, 0x118(%r14)
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq 0x18(%rsp), %rbp
movq %rbp, %rcx
movq 0x28(%rsp), %r8
callq 0x5960e
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq 0x50(%rsp), %r12
addq %rbp, %r12
movq %r12, 0x50(%rsp)
movq 0x30(%rsp), %rax
subq %r12, %rax
cmpq $0x3, %rax
jg 0x58a16
jmp 0x58c57
cmpl $0x3, %r14d
setne %al
cmpq $0x4, 0x18(%rsp)
setne %cl
orb %al, %cl
jne 0x58b9b
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed61
movq %rbx, %rdi
leaq 0xc9020(%rip), %rsi     # 0x121bab
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rsp), %rbp
jmp 0x58b30
cmpl $0x5, %r14d
jne 0x58bfc
movq 0x10(%rsp), %rax
movl $0x1, 0xac(%rax)
movq %rbx, %rdi
callq 0xea504
movq %rax, %r14
movq 0x20(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, 0x18(%r14)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
movq 0x18(%rsp), %rbp
movq %rbp, %rdx
leaq 0xc857b(%rip), %rcx     # 0x121159
movq %r14, %r8
movl $0x1, %r9d
callq 0xefd48
movq %rbx, %rdi
movq %r14, %rsi
callq 0xea50e
jmp 0x58b30
testb $0x10, 0x4(%rbp)
jne 0x58c37
cmpl $0x2, (%rbx)
movq 0x18(%rsp), %rbp
jl 0x58b30
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 0xe8bea
jmp 0x58b30
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq %r12, %rdx
movq 0x18(%rsp), %rbp
movq %rbp, %rcx
movq 0x28(%rsp), %r8
xorl %r9d, %r9d
jmp 0x58b2b
movl 0x44(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq