// File: /workspace/github_c_makefile_star2_O0/j-hoppe[P]tu58fs/rt11.c
// Function: rt11_filesystem_layout
static int rt11_filesystem_layout(rt11_filesystem_t *_this) {
	int i;
	int file_start_blocknr;

	if (_this->bootblock->data_size) {
		_this->bootblock->blocknr = 0;
		if (_this->bootblock->data_size != RT11_BLOCKSIZE)
			return error_set(ERROR_FILESYSTEM_FORMAT, "bootblock has illegal size of %d bytes.",
					_this->bootblock->data_size);
	}
	if (_this->monitor->data_size) {
		_this->monitor->blocknr = 2; // 2..5
		if (_this->monitor->data_size > 4 * RT11_BLOCKSIZE)
			return error_set(ERROR_FILESYSTEM_FORMAT, "monitor has illegal size of %d bytes.",
					_this->monitor->data_size);
	}

	if (rt11_filesystem_calc_block_use(_this, 0))
		return error_code;
	// free, used blocks, dir_total_seg_num now set

	// file area begins after directory segment list
	file_start_blocknr = _this->first_dir_blocknr + 2 * _this->dir_total_seg_num;
	_this->file_space_blocknr = file_start_blocknr;
	for (i = 0; i < _this->file_count; i++) {
		rt11_file_t *f = _this->file[i];
		f->block_nr = file_start_blocknr;
		// set start of prefix and data
		if (f->prefix) {
			f->prefix->blocknr = file_start_blocknr;
			// prefix needs 1 extra word for blockcount
			f->prefix->byte_offset = 2;
			file_start_blocknr += NEEDED_BLOCKS(RT11_BLOCKSIZE, f->prefix->data_size + 2);
		}
		if (f->data) {
			f->data->blocknr = file_start_blocknr;
			file_start_blocknr += NEEDED_BLOCKS(RT11_BLOCKSIZE, f->data->data_size);
		}
		// f->block_count set in file_stream_add()
		assert(file_start_blocknr - f->block_nr == f->block_count);
	}
	// save begin of free space for _render()
	_this->render_free_space_blocknr = file_start_blocknr;

	return ERROR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0x149f0
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movw $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
cmpl $0x200, 0x10(%rax)      # imm = 0x200
je 0x149ee
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movl 0x10(%rax), %edx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leaq 0x9036(%rip), %rsi      # 0x1da15
movb $0x0, %al
callq 0xcd70
movl %eax, -0x4(%rbp)
jmp 0x14bce
jmp 0x149f0
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0x14a50
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movw $0x2, (%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
cmpl $0x800, 0x10(%rax)      # imm = 0x800
jbe 0x14a4e
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movl 0x10(%rax), %edx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
leaq 0x8ffe(%rip), %rsi      # 0x1da3d
movb $0x0, %al
callq 0xcd70
movl %eax, -0x4(%rbp)
jmp 0x14bce
jmp 0x14a50
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x15680
cmpl $0x0, %eax
je 0x14a71
leaq 0x10ad1(%rip), %rax     # 0x25538
movl (%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x14bce
movq -0x10(%rbp), %rax
movzwl 0x34(%rax), %eax
movq -0x10(%rbp), %rcx
movzwl 0x64(%rcx), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x1fd4(%rax)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8c(%rcx), %eax
jge 0x14bb6
movq -0x10(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq 0x90(%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
movl -0x18(%rbp), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x7a(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x88(%rax)
je 0x14b2b
movl -0x18(%rbp), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movw %cx, (%rax)
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movl $0x2, 0x4(%rax)
movq -0x20(%rbp), %rax
movq 0x88(%rax), %rax
movl 0x10(%rax), %eax
addl $0x2, %eax
addl $0x200, %eax            # imm = 0x200
subl $0x1, %eax
shrl $0x9, %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x14b6c
movl -0x18(%rbp), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movw %cx, (%rax)
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rax
movl 0x10(%rax), %eax
addl $0x200, %eax            # imm = 0x200
subl $0x1, %eax
shrl $0x9, %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x20(%rbp), %rcx
movzwl 0x7a(%rcx), %ecx
subl %ecx, %eax
movq -0x20(%rbp), %rcx
movzwl 0x7c(%rcx), %ecx
cmpl %ecx, %eax
jne 0x14b87
jmp 0x14ba6
leaq 0x8ed5(%rip), %rdi      # 0x1da63
leaq 0x8aa3(%rip), %rsi      # 0x1d638
movl $0x305, %edx            # imm = 0x305
leaq 0x8ef5(%rip), %rcx      # 0x1da96
callq 0x3200
jmp 0x14ba8
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x14aa0
movl -0x18(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x1fd6(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)