// File: /workspace/github_cpp_makefile_star2_O3/kipa00[P]AplusB-mc/compiler/chunk.cpp
// Function: chunk::read(unsigned char const*, int*, int, int)
bool chunk::read(const byte *data, int *pos, int tag_type, int stage) {
	bool named;
	string name;
	if (tag_type < 0) {
		tag_type = data[(*pos)++];
		if (!tag_type) {
			return false;
		}

		int len = data[(*pos)++];
		(len <<= 8) |= data[(*pos)++];
		name = bytes_to_string(data+*pos, len);
		named = true;
		*pos += len;
	} else {
		named = false;
	}
	switch (tag_type) {
		case 1:
			if (stage == 3 && named && name == "Y") {
				this->feed((int)data[*pos]);
			}
			++*pos;
			break;
		case 2:
			*pos += 2;
			break;
		case 3:
			if (stage == 2 && named && (name == "xPos" || name == "zPos")) {
				u32 coord = 0;
				for (int i=0; i<4; ++i) {
					(coord <<= 8) |= data[(*pos)++];
				}
				(name[0] == 'x' ? this->x : this->z) = (int)coord;
			} else *pos += 4;
			break;
		case 4:
			*pos += 8;
			break;
		case 5:
			*pos += 4;
			break;
		case 6:
			*pos += 8;
			break;
		case 7:
			{
				int len = 0;
				for (int i=0; i<4; ++i) {
					(len <<= 8) |= data[(*pos)++];
				}
				*pos += len;
			}
			break;
		case 8:
			{
				int len = data[(*pos)++];
				(len <<= 8) |= data[(*pos)++];
				if (stage == 4 && named && name == "Name") this->feed(bytes_to_string(data+*pos, len));
				if (stage == 5 && named) this->feed(name, bytes_to_string(data+*pos, len));
				*pos += len;
			}
			break;
		case 9:
			{
				byte subid = data[(*pos)++];
				int len = 0;
				for (int i=0; i<4; ++i) {
					(len <<= 8) |= data[(*pos)++];
				}
				this->troubleshoot_bit = len >> 6;
				int next_stage = named ? need_progress(stage, name) : stage;
				while (len--) {
					this->read(data, pos, (int)subid, next_stage);
					if (stage == 2 && next_stage == 3) this->flush_section();
					if (stage == 3 && next_stage == 4) this->flush_block();
				}
			}
			break;
		case 10:
			{
				int next_stage = named ? need_progress(stage, name) : stage;
				while (this->read(data, pos, -1, next_stage));
			}
			break;
		case 11:
			{
				int len = 0;
				for (int i=0; i<4; ++i) {
					(len <<= 8) |= data[(*pos)++];
				}
				*pos += len * 4;
			}
			break;
		case 12:
			{
				int len = 0;
				for (int i=0; i<4; ++i) {
					(len <<= 8) |= data[(*pos)++];
				}
				if (stage == 3 && named && name == "BlockStates") {
					this->feed(data+*pos, len * 8);
				}
				*pos += len * 8;
			}
			break;
	}
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %r8d, %r15d
movl %ecx, %r13d
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %ecx, %ebp
testl %ecx, %ecx
jns 0x461b
movslq (%rbx), %rax
leaq 0x1(%rax), %rcx
movl %ecx, (%rbx)
movzbl (%r14,%rax), %ebp
testl %ebp, %ebp
je 0x4644
movl %r15d, 0x4(%rsp)
movq %r12, 0x8(%rsp)
leaq 0x2(%rax), %rdx
movl %edx, (%rbx)
movzbl (%r14,%rcx), %r12d
leal 0x3(%rax), %ecx
movl %ecx, (%rbx)
movzbl 0x2(%r14,%rax), %ecx
shll $0x8, %r12d
orl %ecx, %r12d
leaq (%rax,%r14), %rsi
addq $0x3, %rsi
leaq 0xd8(%rsp), %rdi
movl %r12d, %edx
callq 0x4dc4
leaq 0x10(%rsp), %rdi
leaq 0xd8(%rsp), %r15
movq %r15, %rsi
callq 0x21a0
movq (%r15), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x460e
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2150
addl %r12d, (%rbx)
movq 0x8(%rsp), %r12
movl 0x4(%rsp), %r15d
movb $0x1, %al
movl %eax, 0x8(%rsp)
decl %ebp
cmpl $0xb, %ebp
ja 0x4aaf
leaq 0x3cc1(%rip), %rax      # 0x82f4
movslq (%rax,%rbp,4), %rcx
addq %rax, %rcx
jmpq *%rcx
addl $0x8, (%rbx)
jmp 0x4aaf
movl $0x0, 0x8(%rsp)
jmp 0x4aaf
movl %r15d, %edi
movslq (%rbx), %rcx
movq %rcx, %rax
addq %r14, %rax
xorl %r15d, %r15d
movl $0x1, %edx
incl %ecx
movl %ecx, (%rbx)
movzbl -0x1(%rax,%rdx), %esi
shll $0x8, %r15d
orl %esi, %r15d
incq %rdx
cmpl $0x5, %edx
jne 0x4665
testl %r13d, %r13d
setns %al
cmpl $0x3, %edi
setne %dl
orb %al, %dl
jne 0x46bd
leaq 0x3f74(%rip), %rsi      # 0x8608
leaq 0x10(%rsp), %rdi
callq 0x2050
movl (%rbx), %ecx
testl %eax, %eax
jne 0x46bd
movslq %ecx, %rax
addq %rax, %r14
addq $0x38, %r12
movq %r12, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4ec2
movl (%rbx), %ecx
leal (%rcx,%r15,8), %eax
movl %eax, (%rbx)
jmp 0x4aaf
testl %r13d, %r13d
jns 0x472c
movl %r15d, %ebp
movq %r12, %r13
leaq 0xc8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x4d2c
leaq 0xb8(%rsp), %r15
movl %ebp, %edi
movq %r15, %rsi
callq 0x3bb0
movl %eax, %ebp
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x4726
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x2150
movq %r13, %r12
movl %ebp, %r15d
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %r15d, %r8d
callq 0x4546
testb %al, %al
jne 0x472c
jmp 0x4aaf
movq %r12, %rbp
testl %r13d, %r13d
setns %al
movslq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movl %edx, (%rbx)
movzbl (%r14,%rcx), %r12d
leal 0x2(%rcx), %edx
movl %edx, (%rbx)
movzbl 0x1(%r14,%rcx), %ecx
shll $0x8, %r12d
orl %ecx, %r12d
cmpl $0x4, %r15d
setne %cl
orb %al, %cl
je 0x4a1b
testl %r13d, %r13d
setns %al
cmpl $0x5, %r15d
setne %cl
orb %al, %cl
jne 0x4a75
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x4d2c
movslq (%rbx), %rax
addq %rax, %r14
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x4dc4
leaq 0x58(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %rbp, %rdi
callq 0x3f4a
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47fb
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x58(%rsp), %rdi
jmp 0x4a65
testl %r13d, %r13d
setns %al
cmpl $0x2, %r15d
setne %cl
orb %al, %cl
jne 0x4848
leaq 0x3ddc(%rip), %rsi      # 0x85f9
leaq 0x10(%rsp), %rdi
callq 0x2050
testl %eax, %eax
je 0x4a7a
leaq 0x3dc8(%rip), %rsi      # 0x85fe
leaq 0x10(%rsp), %rdi
callq 0x2050
testl %eax, %eax
je 0x4a7a
addl $0x4, (%rbx)
jmp 0x4aaf
testl %r13d, %r13d
setns %al
cmpl $0x3, %r15d
setne %cl
orb %al, %cl
jne 0x4883
leaq 0x3d8f(%rip), %rsi      # 0x85f7
leaq 0x10(%rsp), %rdi
callq 0x2050
testl %eax, %eax
jne 0x4883
movslq (%rbx), %rax
movzbl (%r14,%rax), %eax
movl %eax, 0x4(%r12)
incl (%rbx)
jmp 0x4aaf
addl $0x2, (%rbx)
jmp 0x4aaf
movl (%rbx), %ecx
movslq %ecx, %rax
addq %rax, %r14
negl %eax
xorl %esi, %esi
movl $0x1, %edx
leal (%rcx,%rdx), %edi
movl %edi, (%rbx)
movzbl -0x1(%r14,%rdx), %r8d
movl %esi, %edi
shll $0x8, %edi
leal (%rdi,%r8), %esi
incq %rdx
decl %eax
cmpl $0x5, %edx
jne 0x48a3
orl %r8d, %edi
subl %eax, %edi
movl %edi, (%rbx)
jmp 0x4aaf
movl (%rbx), %ecx
movslq %ecx, %rax
addq %rax, %r14
negl %eax
xorl %edi, %edi
movl $0x1, %edx
movl %edi, %esi
leal (%rcx,%rdx), %edi
movl %edi, (%rbx)
movzbl -0x1(%r14,%rdx), %r8d
movl %esi, %edi
shll $0x8, %edi
orl %r8d, %edi
incq %rdx
decl %eax
cmpl $0x5, %edx
jne 0x48de
shll $0xa, %esi
leal (%rsi,%r8,4), %ecx
subl %eax, %ecx
movl %ecx, (%rbx)
jmp 0x4aaf
movl %r15d, %ebp
movslq (%rbx), %rcx
leal 0x1(%rcx), %eax
movl %eax, (%rbx)
movzbl (%r14,%rcx), %edx
movl %edx, 0x34(%rsp)
cltq
addq %r14, %rax
addl $0x2, %ecx
xorl %edx, %edx
xorl %r15d, %r15d
leal (%rcx,%rdx), %esi
movl %esi, (%rbx)
movzbl (%rax,%rdx), %esi
shll $0x8, %r15d
orl %esi, %r15d
incq %rdx
cmpl $0x4, %edx
jne 0x492e
movl %r15d, %eax
sarl $0x6, %eax
movl %eax, 0x14(%r12)
movl %ebp, 0x4(%rsp)
testl %r13d, %r13d
jns 0x49b1
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x4d2c
leaq 0x78(%rsp), %r13
movl %ebp, %edi
movq %r13, %rsi
callq 0x3bb0
movl %eax, 0x4(%rsp)
movq (%r13), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x49b1
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2150
testl %r15d, %r15d
je 0x4aaf
movl %ebp, %edx
movl %ebp, %eax
xorl $0x2, %eax
movl 0x4(%rsp), %esi
movl %esi, %ecx
xorl $0x3, %ecx
orl %eax, %ecx
sete %bpl
xorl $0x3, %edx
movl %esi, %eax
xorl $0x4, %eax
orl %edx, %eax
sete %r13b
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl 0x34(%rsp), %ecx
movl 0x4(%rsp), %r8d
callq 0x4546
testb %bpl, %bpl
je 0x4a04
movq %r12, %rdi
callq 0x441a
jmp 0x4a11
testb %r13b, %r13b
je 0x4a11
movq %r12, %rdi
callq 0x44f6
decl %r15d
jne 0x49de
jmp 0x4aaf
leaq 0x3be1(%rip), %rsi      # 0x8603
leaq 0x10(%rsp), %rdi
callq 0x2050
testl %eax, %eax
jne 0x4a75
movslq (%rbx), %rax
addq %rax, %r14
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x4dc4
leaq 0x98(%rsp), %rsi
movq %rbp, %rdi
callq 0x3c66
leaq 0xa8(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x4a75
movq (%r15), %rsi
incq %rsi
callq 0x2150
addl %r12d, (%rbx)
jmp 0x4aaf
movslq (%rbx), %rax
addq %rax, %r14
leal 0x1(%rax), %ecx
xorl %edx, %edx
xorl %eax, %eax
leal (%rcx,%rdx), %esi
movl %esi, (%rbx)
movzbl (%r14,%rdx), %esi
shll $0x8, %eax
orl %esi, %eax
incq %rdx
cmpl $0x4, %edx
jne 0x4a87
movq 0x10(%rsp), %rcx
xorl %edx, %edx
cmpb $0x78, (%rcx)
setne %dl
movl %eax, (%r12,%rdx,8)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4acb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2150
movl 0x8(%rsp), %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4b4a
movq 0xa8(%rsp), %rsi
jmp 0x4b33
jmp 0x4b47
movq %rax, %rbx
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4b24
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x4b24
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x4b4a
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x4b4a
jmp 0x4b47
jmp 0x4b47
jmp 0x4b47
jmp 0x4b47
jmp 0x4b47
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4b66
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2220