// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/cfb.c
// Function: do_header
static int do_header(deark *c, lctx *d)
{
	i64 pos = 0;
	i64 byte_order_code;
	i64 sector_shift;
	i64 mini_sector_shift;
	char buf[80];
	int retval = 0;

	de_dbg(c, "header at %d", (int)pos);
	de_dbg_indent(c, 1);

	// offset 0-7: signature
	// offset 8-23: CLSID

	d->minor_ver = de_getu16le(pos+24);
	d->major_ver = de_getu16le(pos+26);
	de_dbg(c, "format version: %d.%d", (int)d->major_ver, (int)d->minor_ver);
	if(d->major_ver!=3 && d->major_ver!=4) {
		de_err(c, "Unsupported format version: %d", (int)d->major_ver);
		goto done;
	}

	byte_order_code = de_getu16le(pos+28);
	if(byte_order_code != 0xfffe) {
		de_err(c, "Unsupported byte order code: 0x%04x", (unsigned int)byte_order_code);
		goto done;
	}

	sector_shift = de_getu16le(pos+30); // aka ssz
	d->sec_size = de_pow2(sector_shift);
	de_dbg(c, "sector size: 2^%d (%d bytes)", (int)sector_shift,
		(int)d->sec_size);
	if(d->sec_size!=512 && d->sec_size!=4096) {
		de_err(c, "Unsupported sector size: %d", (int)d->sec_size);
		goto done;
	}

	mini_sector_shift = de_getu16le(pos+32); // aka sssz
	d->mini_sector_size = de_pow2(mini_sector_shift);
	de_dbg(c, "mini sector size: 2^%d (%d bytes)", (int)mini_sector_shift,
		(int)d->mini_sector_size);
	if(d->mini_sector_size!=64) {
		de_err(c, "Unsupported mini sector size: %d", (int)d->mini_sector_size);
		goto done;
	}

	// offset 34: 6 reserved bytes

	//d->num_dir_sectors = de_getu32le(pos+40);
	//de_dbg(c, "number of directory sectors: %u", (unsigned int)d->num_dir_sectors);
	// Should be 0 if major_ver==3

	// Number of sectors used by sector allocation table (FAT)
	d->num_fat_sectors = de_getu32le(pos+44);
	de_dbg(c, "number of FAT sectors: %d", (int)d->num_fat_sectors);

	d->first_dir_sec_id = de_geti32le(pos+48);
	describe_sec_id(c, d, d->first_dir_sec_id, buf, sizeof(buf));
	de_dbg(c, "first directory sector: %d (%s)", (int)d->first_dir_sec_id, buf);

	// offset 52, transaction signature number

	d->std_stream_min_size = de_getu32le(pos+56);
	de_dbg(c, "min size of a standard stream: %d", (int)d->std_stream_min_size);

	// First sector of mini sector allocation table (MiniFAT)
	d->first_minifat_sec_id = de_geti32le(pos+60);
	describe_sec_id(c, d, d->first_minifat_sec_id, buf, sizeof(buf));
	de_dbg(c, "first MiniFAT sector: %d (%s)", (int)d->first_minifat_sec_id, buf);

	// Number of sectors used by MiniFAT
	d->num_minifat_sectors = de_getu32le(pos+64);
	de_dbg(c, "number of MiniFAT sectors: %d", (int)d->num_minifat_sectors);

	// SecID of first (extra?) sector of the DIFAT
	// (also called the Master Sector Allocation Table (MSAT))
	d->first_difat_sec_id = de_geti32le(pos+68);
	describe_sec_id(c, d, d->first_difat_sec_id, buf, sizeof(buf));
	de_dbg(c, "first extended DIFAT sector: %d (%s)", (int)d->first_difat_sec_id, buf);

	// Number of (extra?) sectors used by the DIFAT
	d->num_difat_sectors = de_getu32le(pos+72);
	de_dbg(c, "number of extended DIFAT sectors: %d", (int)d->num_difat_sectors);

	// offset 76: 436 bytes of DIFAT data
	retval = 1;

done:
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x84(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %edx
leaq 0x1739e8(%rip), %rsi    # 0x1c4f8e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x1a, %rsi
callq 0x165280
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %ecx
leaq 0x174d95(%rip), %rsi    # 0x1c63af
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x3, 0x18(%rax)
je 0x51658
movq -0x10(%rbp), %rax
cmpq $0x4, 0x18(%rax)
je 0x51658
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %edx
leaq 0x153ec0(%rip), %rsi    # 0x1a550c
movb $0x0, %al
callq 0x15bfb0
jmp 0x519b6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x1c, %rsi
callq 0x165280
movq %rax, -0x20(%rbp)
cmpq $0xfffe, -0x20(%rbp)    # imm = 0xFFFE
je 0x51698
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %edx
leaq 0x153e9f(%rip), %rsi    # 0x1a552b
movb $0x0, %al
callq 0x15bfb0
jmp 0x519b6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x1e, %rsi
callq 0x165280
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x15ce50
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, %ecx
leaq 0x153e74(%rip), %rsi    # 0x1a5554
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x200, 0x20(%rax)      # imm = 0x200
je 0x51724
movq -0x10(%rbp), %rax
cmpq $0x1000, 0x20(%rax)     # imm = 0x1000
je 0x51724
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, %edx
leaq 0x14d4f8(%rip), %rsi    # 0x19ec10
movb $0x0, %al
callq 0x15bfb0
jmp 0x519b6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x20, %rsi
callq 0x165280
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x15ce50
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl %eax, %ecx
leaq 0x153de3(%rip), %rsi    # 0x1a554f
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
cmpq $0x40, 0x50(%rax)
je 0x5179f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movl %eax, %edx
leaq 0x153dde(%rip), %rsi    # 0x1a5571
movb $0x0, %al
callq 0x15bfb0
jmp 0x519b6
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x2c, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl %eax, %edx
leaq 0x153dbe(%rip), %rsi    # 0x1a5592
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x30, %rsi
callq 0x165600
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
leaq -0x80(%rbp), %rcx
movl $0x50, %r8d
callq 0x52250
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl %eax, %edx
leaq -0x80(%rbp), %rcx
leaq 0x153d79(%rip), %rsi    # 0x1a55ac
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x38, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %edx
leaq 0x153d5d(%rip), %rsi    # 0x1a55cc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x3c, %rsi
callq 0x165600
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdx
leaq -0x80(%rbp), %rcx
movl $0x50, %r8d
callq 0x52250
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movl %eax, %edx
leaq -0x80(%rbp), %rcx
leaq 0x153d20(%rip), %rsi    # 0x1a55ee
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x40, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl %eax, %edx
leaq 0x153d02(%rip), %rsi    # 0x1a560c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x44, %rsi
callq 0x165600
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdx
leaq -0x80(%rbp), %rcx
movl $0x50, %r8d
callq 0x52250
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movl %eax, %edx
leaq -0x80(%rbp), %rcx
leaq 0x153cc1(%rip), %rsi    # 0x1a562a
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x48, %rsi
callq 0x165540
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl %eax, %edx
leaq 0x153caa(%rip), %rsi    # 0x1a564f
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x84(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x84(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)