// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/atari-dsk.c
// Function: do_msa_header
static int do_msa_header(deark *c, struct msactx *d, i64 pos1)
{
	i64 pos;
	int retval = 0;

	de_dbg(c, "header at %"I64_FMT, pos1);
	de_dbg_indent(c, 1);
	pos = pos1+2;
	d->sectors_per_track = de_getu16be_p(&pos);
	de_dbg(c, "sectors/track: %d", (int)d->sectors_per_track);
	d->sides = 1 + de_getu16be_p(&pos);
	de_dbg(c, "sides: %d", (int)d->sides);
	d->first_track = de_getu16be_p(&pos);
	de_dbg(c, "first track: %d", (int)d->first_track);
	d->last_track = de_getu16be_p(&pos);
	de_dbg(c, "last track: %d", (int)d->last_track);

	d->num_tracks_per_side = d->last_track - d->first_track + 1;
	if(d->sides<1 || d->sides>2) goto done;
	if(d->sectors_per_track<1 || d->sectors_per_track>30) goto done;
	d->num_tracks_total = d->num_tracks_per_side * d->sides;
	if(d->num_tracks_total<1 || d->num_tracks_total>200) goto done;
	d->track_size = d->sectors_per_track * 512;
	d->disk_size = d->track_size * d->num_tracks_total;
	retval = 1;

done:
	if(!retval) {
		de_err(c, "Bad or unsupported disk layout");
	}
	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x188849(%rip), %rsi    # 0x1aed63
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x18(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edx
leaq 0x1787f5(%rip), %rsi    # 0x19ed61
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, %edx
leaq 0x17c1fa(%rip), %rsi    # 0x1a27a2
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
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
leaq 0x178793(%rip), %rsi    # 0x19ed73
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x165210
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, %edx
leaq 0x17876b(%rip), %rsi    # 0x19ed83
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
subq 0x18(%rax), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
cmpq $0x1, 0x10(%rax)
jl 0x26651
movq -0x10(%rbp), %rax
cmpq $0x2, 0x10(%rax)
jle 0x26656
jmp 0x266d6
movq -0x10(%rbp), %rax
cmpq $0x1, 0x8(%rax)
jl 0x2666c
movq -0x10(%rbp), %rax
cmpq $0x1e, 0x8(%rax)
jle 0x2666e
jmp 0x266d6
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x10(%rbp), %rax
imulq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
cmpq $0x1, 0x30(%rax)
jl 0x266a0
movq -0x10(%rbp), %rax
cmpq $0xc8, 0x30(%rax)
jle 0x266a2
jmp 0x266d6
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
shlq $0x9, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x10(%rbp), %rax
imulq 0x30(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movl $0x1, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x266ee
movq -0x8(%rbp), %rdi
leaq 0x1786ab(%rip), %rsi    # 0x19ed92
movb $0x0, %al
callq 0x15bfb0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x24(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)