// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/amiga-dsk.c
// Function: do_file_ofs_data_block
static int do_file_ofs_data_block(deark *c, lctx *d, struct member_data *md,
	i64 seq_num_expected, i64 blknum)
{
	i64 pos1, pos;
	i64 data_size;
	i64 dpos;
	i64 n;
	int blocktype;
	int retval = 0;
	int dbg = (c->debug_level>=2);
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	pos1 = blocknum_to_offset(d, blknum);
	if(dbg) de_dbg(c, "data block: blk#%"I64_FMT" (%"I64_FMT"), seq=%d", blknum, pos1,
		(int)seq_num_expected);
	de_dbg_indent(c, 1);

	if(!claim_block(c, d, blknum)) {
		goto done;
	}

	pos = pos1;
	blocktype = (int)de_geti32be_p(&pos);
	if(dbg) de_dbg(c, "block type: %d", blocktype);
	if(blocktype!=ADF_T_DATA) {
		de_err(c, "%s: Bad block type in data block %d (%d, expected %d)",
			ucstring_getpsz_d(md->fn), (int)seq_num_expected,
			blocktype, (int)ADF_T_DATA);
		goto done;
	}

	n = de_getu32be_p(&pos);
	if(dbg) de_dbg(c, "header_key: %u", (UI)n);
	if(n!=md->header_blknum) {
		on_adf_error(c, d, 12);
		goto done;
	}

	n = de_getu32be_p(&pos);
	if(dbg) de_dbg(c, "seq_num: %u", (UI)n);
	if(n!=seq_num_expected) {
		on_adf_error(c, d, 13);
		goto done;
	}
	data_size = de_getu32be_p(&pos);
	if(dbg) de_dbg(c, "data size: %"I64_FMT, data_size);
	if(data_size > d->bsize-24) {
		de_err(c, "%s: Bad data size in data block %d (%"I64_FMT", max=%"I64_FMT")",
			ucstring_getpsz_d(md->fn), (int)seq_num_expected,
			data_size, (i64)(d->bsize-24));
		goto done;
	}
	if(md->nbytes_written + data_size > md->fsize) {
		on_adf_error(c, d, 15);
		goto done;
	}

	md->next_block_to_read = de_getu32be_p(&pos);
	if(dbg) de_dbg(c, "next data block: %"I64_FMT, md->next_block_to_read);

	dpos = pos1 + 24;
	dbuf_copy(c->infile, dpos, data_size, md->outf);
	md->nbytes_written += data_size;

	retval = 1;

done:
	de_dbg_indent_restore(c, saved_indent_level);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x58(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x2, (%rax)
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x33b10
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x34e3a
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movl %eax, %r8d
leaq 0x16c053(%rip), %rsi    # 0x1a0e86
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x33b30
cmpl $0x0, %eax
jne 0x34e63
jmp 0x350bb
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165630
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x34e9a
movq -0x8(%rbp), %rdi
movl -0x54(%rbp), %edx
leaq 0x16bd06(%rip), %rsi    # 0x1a0b99
movb $0x0, %al
callq 0x15b0d0
cmpl $0x8, -0x54(%rbp)
je 0x34edf
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x172650
movq -0x68(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rax
movl %eax, %ecx
movl -0x54(%rbp), %r8d
leaq 0x16bfdb(%rip), %rsi    # 0x1a0ea8
movl $0x8, %r9d
movb $0x0, %al
callq 0x15bfb0
jmp 0x350bb
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x34f12
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %edx
leaq 0x16be77(%rip), %rsi    # 0x1a0d82
movb $0x0, %al
callq 0x15b0d0
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
je 0x34f36
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0xc, %edx
callq 0x34440
jmp 0x350bb
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x34f69
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movl %eax, %edx
leaq 0x16bf7c(%rip), %rsi    # 0x1a0ede
movb $0x0, %al
callq 0x15b0d0
movq -0x50(%rbp), %rax
cmpq -0x20(%rbp), %rax
je 0x34f8a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0xd, %edx
callq 0x34440
jmp 0x350bb
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1654b0
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x34fbb
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0x188787(%rip), %rsi    # 0x1bd73b
movb $0x0, %al
callq 0x15b0d0
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x18, %rcx
cmpq %rcx, %rax
jle 0x35015
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x172650
movq -0x70(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rax
movl %eax, %ecx
movq -0x40(%rbp), %r8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %r9
subq $0x18, %r9
leaq 0x16bee1(%rip), %rsi    # 0x1a0eea
movb $0x0, %al
callq 0x15bfb0
jmp 0x350bb
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
addq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jle 0x3503f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0xf, %edx
callq 0x34440
jmp 0x350bb
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1654b0
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x60(%rax)
cmpl $0x0, -0x5c(%rbp)
je 0x3507b
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rdx
leaq 0x16bea8(%rip), %rsi    # 0x1a0f1c
movb $0x0, %al
callq 0x15b0d0
movq -0x30(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rcx
callq 0x166070
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rax
addq 0x58(%rax), %rcx
movq %rcx, 0x58(%rax)
movl $0x1, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movl -0x60(%rbp), %esi
callq 0x15b5a0
movl -0x58(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq