// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
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 0xeeb4b
movzbl %al, %edx
leaq 0x64f7e(%rip), %rsi     # 0x1228f7
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movl $0x2, %esi
movl $0x16f, %edx            # imm = 0x16F
movl $0x30, %ecx
callq 0xeb97d
movzbl %al, %edx
movl %edx, 0x20(%r14)
leaq 0x64f91(%rip), %rsi     # 0x12293a
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq 0x8(%r14), %rdi
callq 0xf6423
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
movl $0x1e, %edx
movl $0x1, %r8d
callq 0xefbd7
movq 0x8(%r14), %rdi
callq 0xf64a0
movq 0x8(%r14), %rdi
callq 0xf70f6
leaq 0x6a786(%rip), %rsi     # 0x128179
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x1e, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
leaq 0x7b7c8(%rip), %rsi     # 0x1391df
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
leaq 0x7b7c5(%rip), %rsi     # 0x1391fc
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%r14), %rdi
callq 0xf6423
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
movl $0x3f, %edx
movl $0x1, %r8d
callq 0xefbd7
movq 0x8(%r14), %rdi
callq 0xf64a0
movq 0x8(%r14), %rdi
callq 0xf70f6
leaq 0x7b795(%rip), %rsi     # 0x139219
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x3f, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
leaq 0x7b787(%rip), %rsi     # 0x13922f
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x8(%r14), %rdi
callq 0xf6423
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
movl $0x40, %edx
movl $0x1, %r8d
callq 0xefbd7
movq 0x8(%r14), %rdi
callq 0xf64a0
movq 0x8(%r14), %rdi
callq 0xf70f6
leaq 0x7b74a(%rip), %rsi     # 0x13923e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x40, (%r15)
movq 0x8(%r14), %rdi
callq 0xf6423
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
movl $0x40, %edx
movl $0x1, %r8d
callq 0xefbd7
movq 0x8(%r14), %rdi
callq 0xf64a0
movq 0x8(%r14), %rdi
callq 0xf70f6
leaq 0x7401a(%rip), %rsi     # 0x131b5f
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq