// File: /workspace/github_c_makefile_star2_O1/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 0xef14d
movzbl %al, %edx
leaq 0x640b7(%rip), %rsi     # 0x1226ef
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movl $0x2, %esi
movl $0x16f, %edx            # imm = 0x16F
movl $0x30, %ecx
callq 0xebf42
movzbl %al, %edx
movl %edx, 0x20(%r14)
leaq 0x640ca(%rip), %rsi     # 0x122732
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq 0x8(%r14), %rdi
callq 0xf6883
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
movl $0x1e, %edx
movl $0x1, %r8d
callq 0xf01b0
movq 0x8(%r14), %rdi
callq 0xf6900
movq 0x8(%r14), %rdi
callq 0xf7557
leaq 0x69897(%rip), %rsi     # 0x127f49
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0x1e, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
leaq 0x7a79d(%rip), %rsi     # 0x138e73
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
leaq 0x7a79a(%rip), %rsi     # 0x138e90
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq 0x8(%r14), %rdi
callq 0xf6883
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
movl $0x3f, %edx
movl $0x1, %r8d
callq 0xf01b0
movq 0x8(%r14), %rdi
callq 0xf6900
movq 0x8(%r14), %rdi
callq 0xf7557
leaq 0x7a76a(%rip), %rsi     # 0x138ead
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0x3f, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
leaq 0x7a75c(%rip), %rsi     # 0x138ec3
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x8(%r14), %rdi
callq 0xf6883
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
movl $0x40, %edx
movl $0x1, %r8d
callq 0xf01b0
movq 0x8(%r14), %rdi
callq 0xf6900
movq 0x8(%r14), %rdi
callq 0xf7557
leaq 0x7a71f(%rip), %rsi     # 0x138ed2
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0x40, (%r15)
movq 0x8(%r14), %rdi
callq 0xf6883
movq 0x18(%rbx), %rdi
movq (%r15), %rsi
movq 0x8(%r14), %rcx
movl (%r14), %r9d
movl $0x40, %edx
movl $0x1, %r8d
callq 0xf01b0
movq 0x8(%r14), %rdi
callq 0xf6900
movq 0x8(%r14), %rdi
callq 0xf7557
leaq 0x72fd7(%rip), %rsi     # 0x1317db
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq