// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/fat.c
// Function: loaddskf_read_header
static int loaddskf_read_header(deark *c, struct skf_ctx *d)
{
	i64 bytes_per_sector;
	i64 num_sectors_per_track;
	i64 num_cylinders;
	i64 num_heads;
	i64 num_sectors_in_image;
	int retval = 0;

	de_dbg(c, "header");
	de_dbg_indent(c, 1);

	bytes_per_sector = de_getu16le(4);
	de_dbg(c, "bytes per sector: %u", (UI)bytes_per_sector);
	d->checksum_reported = (u32)de_getu32le(20); // TODO: What is this?
	de_dbg(c, "checksum (reported): 0x%08x", (UI)d->checksum_reported);
	num_cylinders = de_getu16le(24);
	de_dbg(c, "cylinders: %u", (UI)num_cylinders);
	num_heads = de_getu16le(26);
	de_dbg(c, "number of heads: %u", (UI)num_heads);
	num_sectors_per_track = de_getu16le(28);
	de_dbg(c, "sectors per track: %u", (UI)num_sectors_per_track);
	num_sectors_in_image = de_getu16le(34);
	de_dbg(c, "num sectors in image: %u", (UI)num_sectors_in_image);

	d->hdr_size = de_getu16le(38);
	if(d->hdr_size==0) d->hdr_size = 512;
	de_dbg(c, "header size: %"I64_FMT, d->hdr_size);
	if(d->hdr_size<40 || d->hdr_size>c->infile->len) {
		goto done;
	}

	retval = 1;

	if(num_cylinders<20 || num_cylinders>200 ||
		num_heads<1 || num_heads>2 ||
		num_sectors_per_track<8 || num_sectors_per_track>200 ||
		bytes_per_sector<128 || bytes_per_sector>2048)
	{
		de_warn(c, "Unexpected disk geometry. Something may have failed.");
		goto done;
	}

	d->expected_dcmpr_size = num_sectors_in_image * bytes_per_sector;
	d->padded_size = num_cylinders * num_heads * num_sectors_per_track * bytes_per_sector;
	de_dbg(c, "expected uncmpr image size: %"I64_FMT", padded=%"I64_FMT,
		d->expected_dcmpr_size, d->padded_size);

	retval = 1;

done:
	if(!retval) {
		de_err(c, "Failed to parse LoadDskF file");
	}
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x11c2fe(%rip), %rsi    # 0x1a1750
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x4, %esi
callq 0x165280
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0x1290cd(%rip), %rsi    # 0x1ae55b
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x14, %esi
callq 0x165540
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edx
leaq 0x1290ae(%rip), %rsi    # 0x1ae570
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x18, %esi
callq 0x165280
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x12909c(%rip), %rsi    # 0x1ae58c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x1a, %esi
callq 0x165280
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
leaq 0x12907c(%rip), %rsi    # 0x1ae59a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x1c, %esi
callq 0x165280
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0x129062(%rip), %rsi    # 0x1ae5ae
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x22, %esi
callq 0x165280
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
leaq 0x12904a(%rip), %rsi    # 0x1ae5c4
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movl $0x26, %esi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x855b5
movq -0x10(%rbp), %rax
movq $0x200, 0x18(%rax)      # imm = 0x200
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
leaq 0x11e7ce(%rip), %rsi    # 0x1a3d96
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x28, 0x18(%rax)
jl 0x855f0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jle 0x855f5
jmp 0x856a9
movl $0x1, -0x3c(%rbp)
cmpq $0x14, -0x28(%rbp)
jl 0x85640
cmpq $0xc8, -0x28(%rbp)
jg 0x85640
cmpq $0x1, -0x30(%rbp)
jl 0x85640
cmpq $0x2, -0x30(%rbp)
jg 0x85640
cmpq $0x8, -0x20(%rbp)
jl 0x85640
cmpq $0xc8, -0x20(%rbp)
jg 0x85640
cmpq $0x80, -0x18(%rbp)
jl 0x85640
cmpq $0x800, -0x18(%rbp)     # imm = 0x800
jle 0x85654
movq -0x8(%rbp), %rdi
leaq 0x128f92(%rip), %rsi    # 0x1ae5dd
movb $0x0, %al
callq 0x15bc10
jmp 0x856a9
movq -0x38(%rbp), %rcx
imulq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rcx
imulq -0x30(%rbp), %rcx
imulq -0x20(%rbp), %rcx
imulq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
leaq 0x128f77(%rip), %rsi    # 0x1ae612
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x856c1
movq -0x8(%rbp), %rdi
leaq 0x128f84(%rip), %rsi    # 0x1ae63e
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x3c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)