// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/hlp.c
// Function: do_file_SYSTEM_header
static int do_file_SYSTEM_header(deark *c, lctx *d, i64 pos1)
{
	i64 pos = pos1;
	i64 magic;
	i64 gen_date;
	UI flags;
	char timestamp_buf[64];
	int retval = 0;

	magic = de_getu16le_p(&pos);
	if(magic!=0x036c) {
		de_err(c, "Expected SYSTEM data at %"I64_FMT" not found", pos1);
		goto done;
	}

	de_dbg(c, "SYSTEM file data at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);

	d->ver_minor = (int)de_getu16le_p(&pos);
	d->ver_major = (int)de_getu16le_p(&pos);
	de_dbg(c, "help format version: %d.%d", d->ver_major, d->ver_minor);

	if(d->ver_major!=1) {
		de_err(c, "Unsupported file version: %d.%d", d->ver_major, d->ver_minor);
		goto done;
	}

	gen_date = de_geti32le_p(&pos);
	hlptime_to_timestamp(gen_date, &d->gendate);
	de_timestamp_to_string(&d->gendate, timestamp_buf, sizeof(timestamp_buf), 0);
	de_dbg(c, "GenDate: %d (%s)", (int)gen_date, timestamp_buf);

	flags = (UI)de_getu16le_p(&pos);
	de_dbg(c, "system flags: 0x%04x", flags);

	if(d->ver_minor>16) {
		if(flags==8) {
			d->is_lz77_compressed = 1;
			d->topic_block_size = 2048;
		}
		else if(flags==4) {
			d->is_lz77_compressed = 1;
			d->topic_block_size = 4096;
		}
		else {
			d->is_lz77_compressed = 0;
			d->topic_block_size = 4096;
		}
	}
	else {
		d->is_lz77_compressed = 0;
		d->topic_block_size = 2048;
	}
	de_dbg(c, "lz77 compression: %d", d->is_lz77_compressed);
	de_dbg(c, "topic block size: %"I64_FMT, d->topic_block_size);

	retval = 1;
done:
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x84(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movq %rax, -0x28(%rbp)
cmpq $0x36c, -0x28(%rbp)     # imm = 0x36C
je 0x7ee53
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x12e76f(%rip), %rsi    # 0x1ad5b6
movb $0x0, %al
callq 0x15bfb0
jmp 0x7f070
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x12e77a(%rip), %rsi    # 0x1ad5dc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8c(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x88(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x88(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x8c(%rax), %ecx
leaq 0x12e724(%rip), %rsi    # 0x1ad5f4
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x1, 0x88(%rax)
je 0x7ef0f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x88(%rax), %edx
movq -0x10(%rbp), %rax
movl 0x8c(%rax), %ecx
leaq 0x12e70c(%rip), %rsi    # 0x1ad60f
movb $0x0, %al
callq 0x15bfb0
jmp 0x7f070
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165670
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x120, %rsi            # imm = 0x120
callq 0x7f280
movq -0x10(%rbp), %rdi
addq $0x120, %rdi            # imm = 0x120
leaq -0x80(%rbp), %rsi
movl $0x40, %edx
xorl %ecx, %ecx
callq 0x15e130
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq -0x80(%rbp), %rcx
leaq 0x12e6c7(%rip), %rsi    # 0x1ad62f
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1652c0
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %edx
leaq 0x12e6af(%rip), %rsi    # 0x1ad640
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpl $0x10, 0x8c(%rax)
jle 0x7f010
cmpl $0x8, -0x34(%rbp)
jne 0x7efca
movq -0x10(%rbp), %rax
movl $0x1, 0x98(%rax)
movq -0x10(%rbp), %rax
movq $0x800, 0x90(%rax) # imm = 0x800
jmp 0x7f00e
cmpl $0x4, -0x34(%rbp)
jne 0x7efef
movq -0x10(%rbp), %rax
movl $0x1, 0x98(%rax)
movq -0x10(%rbp), %rax
movq $0x1000, 0x90(%rax) # imm = 0x1000
jmp 0x7f00c
movq -0x10(%rbp), %rax
movl $0x0, 0x98(%rax)
movq -0x10(%rbp), %rax
movq $0x1000, 0x90(%rax) # imm = 0x1000
jmp 0x7f00e
jmp 0x7f02d
movq -0x10(%rbp), %rax
movl $0x0, 0x98(%rax)
movq -0x10(%rbp), %rax
movq $0x800, 0x90(%rax) # imm = 0x800
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x98(%rax), %edx
leaq 0x12e613(%rip), %rsi    # 0x1ad655
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x90(%rax), %rdx
leaq 0x12e60b(%rip), %rsi    # 0x1ad66a
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x84(%rbp)
movl -0x84(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nop