// File: /workspace/github_cpp_makefile_star2_O3/kipa00[P]AplusB-mc/compiler/world.cpp
// Function: world::init(_IO_FILE*)
void world::init(FILE *fp) {
	int *arr = new int[1024];
	byte *temp = new byte[1048576];
	byte *inflated = new byte[1048576];
	int i;

	fseek(fp, 0, SEEK_SET);
	fread(temp, 1, 4096, fp);

	for (i=0; i<1024; ++i) {
		arr[i] = (temp[i << 2] << 16) | (temp[(i << 2) | 1] << 8) | temp[(i << 2) | 2];
	}

	// for performance issues
	for (i=0; i<1024; ++i) {
		if (arr[i]) {
			fseek(fp, arr[i] << 12, SEEK_SET);
			fread(temp, 1, 5, fp);
			int sz = (temp[0] << 24) | (temp[1] << 16) | (temp[2] << 8) | temp[3];
			if (temp[4] != 2) {
				throw UNSUPPORTED_COMPRESSION_ERROR;
			}
			fread(temp, 1, sz - 1, fp);

			{
				z_stream infstream;
				infstream.zalloc = Z_NULL;
				infstream.zfree = Z_NULL;
				infstream.opaque = Z_NULL;

				infstream.avail_in = (uInt)(sz - 1);
				infstream.next_in = (Bytef *)temp;
				infstream.avail_out = (uInt)1048576;
				infstream.next_out = (Bytef *)inflated;

				inflateInit(&infstream);
				if (inflate(&infstream, Z_NO_FLUSH) != Z_STREAM_END) {
					throw TOO_BIG_SECTION_ERROR;
				}
				inflateEnd(&infstream);
			}

			if (!this->world_data) {
				this->world_data = new chunk *[1024];
				memset(this->world_data, 0, sizeof(chunk *) * 1024);
			}
			this->world_data[i] = new chunk();
			try {
				this->world_data[i]->read(inflated);
			} catch (int reason) {
				if (reason == ATTR_VALUE_MISMATCH_ERROR) {
					fprintf(stderr, "Error: attribute does not have possible value; did you edit the world using hex editor?\n");
				}
				if (!this->world_data[i]->troubleshoot(i & 31, i >> 5)) {
					fprintf(stderr, "in chunk (%d, %d), exact position unknown.\n", i & 31, i >> 5);
				}
				throw reason;
			}
		}
	}
	delete []temp;
	delete []inflated;
	delete []arr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movl $0x1000, %edi           # imm = 0x1000
callq 0x2030
movq %rax, %r14
movl $0x100000, %edi         # imm = 0x100000
callq 0x2030
movq %rax, %r12
movl $0x100000, %edi         # imm = 0x100000
callq 0x2030
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2180
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
movq %r15, 0x10(%rsp)
movq %r15, %rcx
callq 0x21e0
movzbl (%r12,%r13,4), %eax
shll $0x10, %eax
movzbl 0x1(%r12,%r13,4), %ecx
shll $0x8, %ecx
orl %eax, %ecx
movzbl 0x2(%r12,%r13,4), %eax
orl %ecx, %eax
movl %eax, (%r14,%r13,4)
incq %r13
cmpq $0x400, %r13            # imm = 0x400
jne 0x4f49
xorl %ebp, %ebp
leaq 0x18(%rsp), %r15
movq 0x10(%rsp), %r13
movl (%r14,%rbp,4), %eax
testl %eax, %eax
je 0x50cf
shll $0xc, %eax
movslq %eax, %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x2180
movl $0x1, %esi
movl $0x5, %edx
movq %r12, %rdi
movq %r13, %rcx
callq 0x21e0
cmpb $0x2, 0x4(%r12)
jne 0x511d
movq %r13, %rcx
movzbl (%r12), %eax
shll $0x18, %eax
movzbl 0x1(%r12), %edx
shll $0x10, %edx
cltq
orq %rdx, %rax
movzbl 0x2(%r12), %edx
shll $0x8, %edx
orq %rax, %rdx
movzbl 0x3(%r12), %eax
leaq (%rax,%rdx), %r13
decq %r13
movl $0x1, %esi
movq %r12, %rdi
movq %r13, %rdx
callq 0x21e0
leaq 0x58(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movl %r13d, 0x20(%rsp)
movq %r12, 0x18(%rsp)
movl $0x100000, 0x38(%rsp)   # imm = 0x100000
movq 0x8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %r15, %r13
movq %r15, %rdi
leaq 0x3624(%rip), %rsi      # 0x865f
movl $0x70, %edx
callq 0x2110
movq %r15, %rdi
xorl %esi, %esi
callq 0x20f0
cmpl $0x1, %eax
jne 0x510b
movq %r13, %rdi
callq 0x2170
cmpq $0x0, (%rbx)
jne 0x5082
movl $0x2000, %edi           # imm = 0x2000
callq 0x2030
movq %rax, (%rbx)
movl $0x2000, %edx           # imm = 0x2000
movq %rax, %rdi
xorl %esi, %esi
callq 0x20c0
movl $0x50, %edi
callq 0x2140
movq %rax, %r13
leaq 0x38(%rax), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x40(%rax)
xorl %esi, %esi
xorl %edx, %edx
callq 0x4ec2
movq (%rbx), %rax
movq %r13, (%rax,%rbp,8)
movq (%rbx), %rax
movq (%rax,%rbp,8), %rdi
movq 0x8(%rsp), %rsi
callq 0x4b6e
movq 0x10(%rsp), %r13
incq %rbp
cmpq $0x400, %rbp            # imm = 0x400
jne 0x4f80
movq %r12, %rdi
callq 0x21c0
movq 0x8(%rsp), %rdi
callq 0x21c0
movq %r14, %rdi
callq 0x21c0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, %edi
callq 0x20a0
movl $0xfffffffb, (%rax)     # imm = 0xFFFFFFFB
jmp 0x512d
movl $0x4, %edi
callq 0x20a0
movl $0xfffffffc, (%rax)     # imm = 0xFFFFFFFC
movq 0x6e94(%rip), %rsi      # 0xbfc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x2210
movq %rax, %r14
cmpl $0x1, %edx
jne 0x51e4
leaq 0x18(%rsp), %r15
movq %r14, %rdi
movl %edx, %esi
movq %r15, %rdx
callq 0x2434
movl (%r15), %r14d
movq (%rbx), %rax
movq (%rax,%rbp,8), %rdi
movl %ebp, %ebx
andl $0x1f, %ebx
shrl $0x5, %ebp
movl %ebx, %esi
movl %ebp, %edx
callq 0x4c64
testb %al, %al
jne 0x5197
movq 0x6e5e(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
leaq 0x3533(%rip), %rsi      # 0x86bf
movl %ebx, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x21d0
movl $0x4, %edi
callq 0x20a0
movl %r14d, (%rax)
movq 0x6e1d(%rip), %rsi      # 0xbfc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x2210
movq %rax, %r14
callq 0x2200
jmp 0x51e4
movq %rax, %r14
movq 0x18(%r13), %rdi
testq %rdi, %rdi
je 0x51d7
movq 0x28(%r13), %rsi
subq %rdi, %rsi
callq 0x2150
movl $0x50, %esi
movq %r13, %rdi
callq 0x2150
movq %r14, %rdi
callq 0x2220