// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/pif.c
// Function: do_pif_section_basic
static void do_pif_section_basic(deark *c, struct pif_ctx *d, i64 pos1, i64 len)
{
	i64 pos = pos1;
	i64 n;
	UI checksum_reported;

	pos++; // unused

	checksum_reported = (UI)de_getbyte_p(&pos);
	de_dbg(c, "checksum (reported): 0x%02x", checksum_reported);
	d->checksum_calc = (UI)de_calccrc_oneshot(c->infile, 2, PIF_BASIC_SECTION_SIZE-2,
		DE_CRCOBJ_SUM_BYTES);
	d->checksum_calc &= 0xff;
	// Note - Not all files set the checksum field. Often it's just set to 0x78,
	// but other wrong values are common.
	de_dbg(c, "checksum (calculated): 0x%02x", d->checksum_calc);

	ucstring_empty(d->tmpstr);
	dbuf_read_to_ucstring(c->infile, pos, 30, d->tmpstr, DE_CONVFLAG_STOP_AT_NUL,
		d->input_encoding_oem);
	ucstring_strip_trailing_spaces(d->tmpstr);
	de_dbg(c, "title: \"%s\"", ucstring_getpsz_d(d->tmpstr));
	pos += 30;

	n = de_getu16le_p(&pos);
	de_dbg(c, "max conventional mem: %"I64_FMT" kb", n);
	n = de_getu16le_p(&pos);
	de_dbg(c, "min conventional mem: %"I64_FMT" kb", n);

	ucstring_empty(d->tmpstr);
	dbuf_read_to_ucstring(c->infile, pos, 63, d->tmpstr, DE_CONVFLAG_STOP_AT_NUL,
		d->input_encoding_oem);
	ucstring_strip_trailing_spaces(d->tmpstr);
	de_dbg(c, "target filename: \"%s\"", ucstring_getpsz_d(d->tmpstr));
	pos += 63;

	// TODO: There's disagreement about what the next 2 bytes are.
	n = de_getu16le_p(&pos);
	de_dbg(c, "flags1: 0x%04x", (UI)n);

	ucstring_empty(d->tmpstr);
	dbuf_read_to_ucstring(c->infile, pos, 64, d->tmpstr, DE_CONVFLAG_STOP_AT_NUL,
		d->input_encoding_oem);
	ucstring_strip_trailing_spaces(d->tmpstr);
	de_dbg(c, "work dir: \"%s\"", ucstring_getpsz_d(d->tmpstr));
	pos += 64;

	ucstring_empty(d->tmpstr);
	dbuf_read_to_ucstring(c->infile, pos, 64, d->tmpstr, DE_CONVFLAG_STOP_AT_NUL,
		d->input_encoding_oem);
	ucstring_strip_trailing_spaces(d->tmpstr);
	de_dbg(c, "params: \"%s\"", ucstring_getpsz_d(d->tmpstr));
	pos += 64;

	// TODO: More fields
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
incq %rdx
leaq 0x8(%rsp), %r15
movq %rdx, (%r15)
movq 0x18(%rdi), %rdi
movq %r15, %rsi
callq 0xe3f2a
movzbl %al, %edx
leaq 0x5f3c2(%rip), %rsi     # 0x115737
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
pushq $0x2
popq %rsi
pushq $0x30
popq %rcx
movl $0x16f, %edx            # imm = 0x16F
callq 0xe0f6a
movzbl %al, %edx
movl %edx, 0x20(%r14)
leaq 0x5f3d9(%rip), %rsi     # 0x11577a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
movq 0x8(%r14), %rdi
callq 0xeac85
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
pushq $0x1e
popq %rdx
pushq $0x1
popq %rbp
movl %ebp, %r8d
callq 0xe4c9a
movq 0x8(%r14), %rdi
callq 0xead03
movq 0x8(%r14), %rdi
callq 0xeb877
leaq 0x64b50(%rip), %rsi     # 0x11af39
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq $0x1e, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
leaq 0x75ad2(%rip), %rsi     # 0x12bedf
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
leaq 0x75acf(%rip), %rsi     # 0x12befc
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
movq 0x8(%r14), %rdi
callq 0xeac85
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
pushq $0x3f
popq %rdx
movl %ebp, %r8d
callq 0xe4c9a
movq 0x8(%r14), %rdi
callq 0xead03
movq 0x8(%r14), %rdi
callq 0xeb877
leaq 0x75aa4(%rip), %rsi     # 0x12bf19
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq $0x3f, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
leaq 0x75a96(%rip), %rsi     # 0x12bf2f
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x8(%r14), %rdi
callq 0xeac85
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
pushq $0x40
popq %r12
movq %r12, %rdx
movl %ebp, %r8d
callq 0xe4c9a
movq 0x8(%r14), %rdi
callq 0xead03
movq 0x8(%r14), %rdi
callq 0xeb877
leaq 0x75a5a(%rip), %rsi     # 0x12bf3e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq $0x40, (%r15)
movq 0x8(%r14), %rdi
callq 0xeac85
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
movq %r12, %rdx
movl %ebp, %r8d
callq 0xe4c9a
movq 0x8(%r14), %rdi
callq 0xead03
movq 0x8(%r14), %rdi
callq 0xeb877
leaq 0x6e343(%rip), %rsi     # 0x124873
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq