// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/amiga-dsk.c
// Function: do_header_block
static int do_header_block(deark *c, lctx *d, i64 blknum)
{
	i64 pos1;
	int blocktype;
	int retval = 0;
	int saved_indent_level;
	struct member_data *md = NULL;

	de_dbg_indent_save(c, &saved_indent_level);

	d->nesting_level++;
	if(d->nesting_level>MAX_NESTING_LEVEL) goto done;

	pos1 = blocknum_to_offset(d, blknum);

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

	blocktype = (int)de_geti32be(pos1);
	if(blocktype==ADF_T_HEADER) {
		retval = 1;
	}

	md = de_malloc(c, sizeof(struct member_data));
	md->header_blknum = blknum;
	md->header_pos = blocknum_to_offset(d, md->header_blknum);
	md->fi = de_finfo_create(c);

	de_dbg(c, "header block: #%"I64_FMT" (%"I64_FMT")", blknum, pos1);
	de_dbg_indent(c, 1);

	de_dbg(c, "block type: %d", blocktype);
	if(blocktype!=ADF_T_HEADER) {
		de_err(c, "Expected header block #%"I64_FMT" (at %"I64_FMT") not found", blknum, pos1);
		goto done;
	}
	md->sec_type = (UI)de_getu32be(pos1+d->bsize-4);
	de_dbg(c, "block secondary type: %d", md->sec_type);

	if(md->sec_type==ADF_ST_ROOT || md->sec_type==ADF_ST_USERDIR) {
		do_directory(c, d, md);
	}
	else if(md->sec_type==ADF_ST_FILE) {
		do_file(c, d, md);
	}
	else {
		de_warn(c, "Unsupported file type: %d", md->sec_type);
		goto done;
	}

done:
	if(md) {
		if(md->outf) {
			dbuf_close(md->outf);
		}
		de_finfo_destroy(c, md->fi);
		ucstring_destroy(md->fn);
		de_free(c, md->tmpbpt.blocks_tbl);
		de_free(c, md);
	}
	de_dbg_indent_restore(c, saved_indent_level);
	d->nesting_level--;
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
cmpl $0x10, 0x20(%rax)
jle 0x3385c
jmp 0x339f9
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x33b10
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x33b30
cmpl $0x0, %eax
jne 0x33888
jmp 0x339f9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x1655d0
movl %eax, -0x24(%rbp)
cmpl $0x2, -0x24(%rbp)
jne 0x338a9
movl $0x1, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl $0x88, %esi
callq 0x15b780
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
movq (%rax), %rsi
callq 0x33b10
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
callq 0x15d230
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x16d33d(%rip), %rsi    # 0x1a0c45
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %edx
leaq 0x16d26e(%rip), %rsi    # 0x1a0b99
movb $0x0, %al
callq 0x15b0d0
cmpl $0x2, -0x24(%rbp)
je 0x33957
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x16d25d(%rip), %rsi    # 0x1a0ba8
movb $0x0, %al
callq 0x15bfb0
jmp 0x339f9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rsi
subq $0x4, %rsi
callq 0x165470
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x30(%rax), %edx
leaq 0x16d247(%rip), %rsi    # 0x1a0bd6
movb $0x0, %al
callq 0x15b0d0
movq -0x38(%rbp), %rax
cmpl $0x1, 0x30(%rax)
je 0x339aa
movq -0x38(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x339bd
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x33bf0
jmp 0x339f7
movq -0x38(%rbp), %rax
cmpl $-0x3, 0x30(%rax)
jne 0x339da
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x33f90
jmp 0x339f5
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x30(%rax), %edx
leaq 0x16d203(%rip), %rsi    # 0x1a0bef
movb $0x0, %al
callq 0x15bc10
jmp 0x339f9
jmp 0x339f7
jmp 0x339f9
cmpq $0x0, -0x38(%rbp)
je 0x33a57
movq -0x38(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x33a18
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rsi
callq 0x15d260
movq -0x38(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x80(%rax), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x15b820
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x15b5a0
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x20(%rax)
movl -0x28(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)