// File: /workspace/github_c_makefile_star2_O1/mortie[P]makeschem/makeschem.c
// Function: schem_write
int schem_write(struct blocks *blocks, FILE *out) {
	if (!nbt_start_named_tag(out, TAG_COMPOUND, "Schematic")) return 0;

	if (!nbt_start_named_tag(out, TAG_SHORT, "Width")) return 0;
	if (!nbt_write_short(out, blocks->width)) return 0;
	if (!nbt_start_named_tag(out, TAG_SHORT, "Height")) return 0;
	if (!nbt_write_short(out, blocks->height)) return 0;
	if (!nbt_start_named_tag(out, TAG_SHORT, "Length")) return 0;
	if (!nbt_write_short(out, blocks->length)) return 0;
	if (!nbt_start_named_tag(out, TAG_STRING, "Materials")) return 0;
	if (!nbt_write_string(out, "Alpha")) return 0;

	if (!nbt_start_named_tag(out, TAG_BYTE_ARRAY, "Blocks")) return 0;
	if (!nbt_start_byte_array(out, blocks->width * blocks->length * blocks->height)) return 0;
	for (size_t y = 0; y < blocks->height; ++y) {
		for (size_t z = 0; z < blocks->length; ++z) {
			for (size_t x = 0; x < blocks->width; ++x) {
				uint8_t id = blocks_get_id(blocks, x, y, z);
				nbt_write_byte(out, id);
			}
		}
	}

	if (!nbt_start_named_tag(out, TAG_BYTE_ARRAY, "Data")) return 0;
	if (!nbt_start_byte_array(out, blocks->width * blocks->length * blocks->height)) return 0;
	for (size_t y = 0; y < blocks->height; ++y) {
		for (size_t z = 0; z < blocks->length; ++z) {
			for (size_t x = 0; x < blocks->width; ++x) {
				uint8_t data = blocks_get_data(blocks, x, y, z);
				nbt_write_byte(out, data);
			}
		}
	}

	return nbt_write_end(out);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x47a(%rip), %rdx       # 0xd0c9
movq %rsi, %rdi
movl $0xa, %esi
callq 0xc49c
xorl %ebp, %ebp
testl %eax, %eax
je 0xceab
leaq 0x466(%rip), %rdx       # 0xd0d3
movq %rbx, %rdi
movl $0x2, %esi
callq 0xc49c
testl %eax, %eax
je 0xceab
movzwl (%r14), %eax
rolw $0x8, %ax
leaq 0x2(%rsp), %rdi
movw %ax, (%rdi)
movl $0x1, %esi
movl $0x2, %edx
movq %rbx, %rcx
callq 0xc100
cmpq $0x2, %rax
jne 0xceab
leaq 0x424(%rip), %rdx       # 0xd0d9
movq %rbx, %rdi
movl $0x2, %esi
callq 0xc49c
testl %eax, %eax
je 0xceab
movzwl 0x8(%r14), %eax
rolw $0x8, %ax
leaq 0x4(%rsp), %rdi
movw %ax, (%rdi)
movl $0x1, %esi
movl $0x2, %edx
movq %rbx, %rcx
callq 0xc100
cmpq $0x2, %rax
jne 0xceab
leaq 0x3e2(%rip), %rdx       # 0xd0e0
movq %rbx, %rdi
movl $0x2, %esi
callq 0xc49c
testl %eax, %eax
je 0xceab
movzwl 0x10(%r14), %eax
rolw $0x8, %ax
leaq 0x6(%rsp), %rdi
movw %ax, (%rdi)
movl $0x1, %esi
movl $0x2, %edx
movq %rbx, %rcx
callq 0xc100
cmpq $0x2, %rax
jne 0xceab
leaq 0x3a0(%rip), %rdx       # 0xd0e7
movq %rbx, %rdi
movl $0x8, %esi
callq 0xc49c
testl %eax, %eax
je 0xceab
leaq 0x38e(%rip), %rsi       # 0xd0f1
movq %rbx, %rdi
callq 0xc415
testl %eax, %eax
je 0xceab
leaq 0x37d(%rip), %rdx       # 0xd0f7
movq %rbx, %rdi
movl $0x7, %esi
callq 0xc49c
testl %eax, %eax
je 0xceab
movl 0x10(%r14), %esi
imull (%r14), %esi
imull 0x8(%r14), %esi
movq %rbx, %rdi
callq 0xc3ec
testl %eax, %eax
je 0xceab
cmpq $0x0, 0x8(%r14)
je 0xcdff
xorl %r15d, %r15d
cmpq $0x0, 0x10(%r14)
je 0xcdf6
xorl %r12d, %r12d
cmpq $0x0, (%r14)
je 0xcded
xorl %r13d, %r13d
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xc7c1
movsbl %al, %edi
movq %rbx, %rsi
callq 0xc080
incq %r13
cmpq (%r14), %r13
jb 0xcdc9
incq %r12
cmpq 0x10(%r14), %r12
jb 0xcdc0
incq %r15
cmpq 0x8(%r14), %r15
jb 0xcdb6
leaq 0x2f8(%rip), %rdx       # 0xd0fe
movq %rbx, %rdi
movl $0x7, %esi
callq 0xc49c
testl %eax, %eax
je 0xceab
movl 0x10(%r14), %esi
imull (%r14), %esi
imull 0x8(%r14), %esi
movq %rbx, %rdi
callq 0xc3ec
testl %eax, %eax
je 0xceab
cmpq $0x0, 0x8(%r14)
je 0xce87
xorl %r15d, %r15d
cmpq $0x0, 0x10(%r14)
je 0xce7e
xorl %r12d, %r12d
cmpq $0x0, (%r14)
je 0xce75
xorl %r13d, %r13d
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xc85f
movsbl %al, %edi
movq %rbx, %rsi
callq 0xc080
incq %r13
cmpq (%r14), %r13
jb 0xce51
incq %r12
cmpq 0x10(%r14), %r12
jb 0xce48
incq %r15
cmpq 0x8(%r14), %r15
jb 0xce3e
leaq 0x1(%rsp), %rdi
movb $0x0, (%rdi)
movl $0x1, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0xc100
xorl %ebp, %ebp
cmpq $0x1, %rax
sete %bpl
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq