// File: /workspace/github_c_makefile_star2_O0/j-hoppe[P]tu58fs/rt11.c
// Function: render_homeblock
static void render_homeblock(rt11_filesystem_t *_this) {
	uint8_t *homeblk = IMAGE_BLOCKNR2PTR(_this, 1);
	uint16_t w;
	uint8_t *s;
	int i, sum;

	memset(homeblk, 0, RT11_BLOCKSIZE);
	// write the bad block replacement table
	// no idea about it, took from TU58 and RL02 image and from Don North
	rt11_image_set_word_at(_this, 1, 0, 0000000);
	rt11_image_set_word_at(_this, 1, 2, 0170000);
	rt11_image_set_word_at(_this, 1, 4, 0007777);

	// rest until 0203 was found to be 0x43 (RL02) or 0x00 ?

	// INITIALIZE/RESTORE data area 0204-0251 == 0x084-0xa9
	// leave blank

	// BUP information area 0252-0273 == 0xaa-0xbb found as 00's

	rt11_image_set_word_at(_this, 1, 0722, _this->pack_cluster_size);
	rt11_image_set_word_at(_this, 1, 0724, _this->first_dir_blocknr);

	w = rad50_encode(_this->system_version);
	rt11_image_set_word_at(_this, 1, 0726, w);

	// 12 char volume id. V3A, or V05, ...
	s = IMAGE_BLOCKNR2PTR(_this, 1) + 0730;
	// always 12 chars long, right padded with spaces
	strcpy((char *)s, strrpad(_this->volume_id, 12, ' '));

	// 12 char owner name
	s = IMAGE_BLOCKNR2PTR(_this, 1) + 0744;
	strcpy((char *)s, strrpad(_this->owner_name, 12, ' '));

	// 12 char system id
	s = IMAGE_BLOCKNR2PTR(_this, 1) + 0760;
	strcpy((char *)s, strrpad(_this->system_id, 12, ' '));

	// build checksum over all words
	for (sum = i = 0; i < 0776; i += 2)
		sum += rt11_image_get_word_at(_this, 1, i);
	sum &= 0xffff;
	_this->homeblock_chksum = sum;
	rt11_image_set_word_at(_this, 1, 0776, sum);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x3220
movq -0x8(%rbp), %rdi
movl $0x1, %esi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0x168c0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
movl $0x2, %edx
movl $0xf000, %ecx           # imm = 0xF000
callq 0x168c0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
movl $0x4, %edx
movl $0xfff, %ecx            # imm = 0xFFF
callq 0x168c0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
movl $0x1, %esi
movl $0x1d2, %edx            # imm = 0x1D2
movzwl %ax, %ecx
callq 0x168c0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl $0x1, %esi
movl $0x1d4, %edx            # imm = 0x1D4
movzwl 0x34(%rax), %ecx
callq 0x168c0
movq -0x8(%rbp), %rdi
addq $0x36, %rdi
callq 0xdaa0
movw %ax, -0x12(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
movl $0x1d6, %edx            # imm = 0x1D6
movzwl -0x12(%rbp), %ecx
callq 0x168c0
movq -0x8(%rbp), %rax
movq (%rax), %rax
addq $0x200, %rax            # imm = 0x200
addq $0x1d8, %rax            # imm = 0x1D8
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
addq $0x3a, %rdi
movl $0xc, %esi
movl $0x20, %edx
callq 0xd740
movq -0x40(%rbp), %rdi
movq %rax, %rsi
callq 0x30c0
movq -0x8(%rbp), %rax
movq (%rax), %rax
addq $0x200, %rax            # imm = 0x200
addq $0x1e4, %rax            # imm = 0x1E4
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
addq $0x47, %rdi
movl $0xc, %esi
movl $0x20, %edx
callq 0xd740
movq -0x38(%rbp), %rdi
movq %rax, %rsi
callq 0x30c0
movq -0x8(%rbp), %rax
movq (%rax), %rax
addq $0x200, %rax            # imm = 0x200
addq $0x1f0, %rax            # imm = 0x1F0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
addq $0x54, %rdi
movl $0xc, %esi
movl $0x20, %edx
callq 0xd740
movq -0x30(%rbp), %rdi
movq %rax, %rsi
callq 0x30c0
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x1fe, -0x24(%rbp)     # imm = 0x1FE
jge 0x14e11
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %edx
movl $0x1, %esi
callq 0x16740
movzwl %ax, %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x24(%rbp)
jmp 0x14de3
movl -0x28(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x62(%rax)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %eax
movl $0x1, %esi
movl $0x1fe, %edx            # imm = 0x1FE
movzwl %ax, %ecx
callq 0x168c0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)