// File: /workspace/github_c_makefile_star2_O3/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 0x549(%rip), %rdx       # 0xd0c9
movq %rsi, %rdi
movl $0xa, %esi
callq 0xc49c
xorl %ebp, %ebp
testl %eax, %eax
je 0xce1a
leaq 0x535(%rip), %rdx       # 0xd0d3
movq %rbx, %rdi
movl $0x2, %esi
callq 0xc49c
testl %eax, %eax
je 0xce1a
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 0xce1a
leaq 0x4f3(%rip), %rdx       # 0xd0d9
movq %rbx, %rdi
movl $0x2, %esi
callq 0xc49c
testl %eax, %eax
je 0xce1a
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 0xce1a
leaq 0x4b1(%rip), %rdx       # 0xd0e0
movq %rbx, %rdi
movl $0x2, %esi
callq 0xc49c
testl %eax, %eax
je 0xce1a
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 0xce1a
leaq 0x46f(%rip), %rdx       # 0xd0e7
movq %rbx, %rdi
movl $0x8, %esi
callq 0xc49c
testl %eax, %eax
je 0xce1a
leaq 0x45d(%rip), %rsi       # 0xd0f1
movq %rbx, %rdi
callq 0xc415
testl %eax, %eax
je 0xce1a
leaq 0x44c(%rip), %rdx       # 0xd0f7
movq %rbx, %rdi
movl $0x7, %esi
callq 0xc49c
testl %eax, %eax
je 0xce1a
movl 0x10(%r14), %esi
imull (%r14), %esi
imull 0x8(%r14), %esi
movq %rbx, %rdi
callq 0xc3ec
testl %eax, %eax
je 0xce1a
movq 0x8(%r14), %rcx
testq %rcx, %rcx
je 0xcd4d
movq 0x10(%r14), %rax
xorl %r15d, %r15d
movq %rax, %rdx
testq %rdx, %rdx
je 0xcd43
movq (%r14), %rcx
xorl %r12d, %r12d
testq %rcx, %rcx
je 0xcd30
xorl %r13d, %r13d
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xc777
movsbl %al, %edi
movq %rbx, %rsi
callq 0xc080
incq %r13
movq (%r14), %rcx
cmpq %rcx, %r13
jb 0xcd03
movq 0x10(%r14), %rax
jmp 0xcd32
xorl %ecx, %ecx
incq %r12
cmpq %rax, %r12
jb 0xccfb
movq 0x8(%r14), %rcx
movq %rax, %rdx
jmp 0xcd45
xorl %edx, %edx
incq %r15
cmpq %rcx, %r15
jb 0xccf0
leaq 0x3aa(%rip), %rdx       # 0xd0fe
movq %rbx, %rdi
movl $0x7, %esi
callq 0xc49c
testl %eax, %eax
je 0xce1a
movl 0x10(%r14), %esi
imull (%r14), %esi
imull 0x8(%r14), %esi
movq %rbx, %rdi
callq 0xc3ec
testl %eax, %eax
je 0xce1a
movq 0x8(%r14), %rcx
testq %rcx, %rcx
je 0xcdf6
movq 0x10(%r14), %rax
xorl %r15d, %r15d
movq %rax, %rdx
testq %rdx, %rdx
je 0xcdec
movq (%r14), %rcx
xorl %r12d, %r12d
testq %rcx, %rcx
je 0xcdd9
xorl %r13d, %r13d
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0xc7db
movsbl %al, %edi
movq %rbx, %rsi
callq 0xc080
incq %r13
movq (%r14), %rcx
cmpq %rcx, %r13
jb 0xcdac
movq 0x10(%r14), %rax
jmp 0xcddb
xorl %ecx, %ecx
incq %r12
cmpq %rax, %r12
jb 0xcda4
movq 0x8(%r14), %rcx
movq %rax, %rdx
jmp 0xcdee
xorl %edx, %edx
incq %r15
cmpq %rcx, %r15
jb 0xcd99
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