// File: /workspace/github_cpp_makefile_star2_O2/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, %r12d
movl %ecx, %r13d
movq %rdx, %rbx
movq %rsi, %r14
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rdi, 0x8(%rsp)
movb $0x0, (%rax)
movl %ecx, %r15d
testl %ecx, %ecx
jns 0x43ba
movslq (%rbx), %rax
leaq 0x1(%rax), %rcx
movl %ecx, (%rbx)
movzbl (%r14,%rax), %r15d
testl %r15d, %r15d
je 0x43e5
movl %r12d, 0x10(%rsp)
leaq 0x2(%rax), %rdx
movl %edx, (%rbx)
movzbl (%r14,%rcx), %ebp
leal 0x3(%rax), %ecx
movl %ecx, (%rbx)
movzbl 0x2(%r14,%rax), %ecx
shll $0x8, %ebp
orl %ecx, %ebp
leaq (%rax,%r14), %rsi
addq $0x3, %rsi
leaq 0xd8(%rsp), %rdi
movl %ebp, %edx
callq 0x49d0
leaq 0x18(%rsp), %rdi
leaq 0xd8(%rsp), %r12
movq %r12, %rsi
callq 0x21b0
movq %r12, %rdi
callq 0x20a0
addl %ebp, (%rbx)
movl 0x10(%rsp), %r12d
movb $0x1, %al
movl %eax, 0x14(%rsp)
decl %r15d
cmpl $0xb, %r15d
ja 0x47a8
leaq 0x3f20(%rip), %rax      # 0x82f4
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
addl $0x8, (%rbx)
jmp 0x47a8
movl $0x0, 0x14(%rsp)
jmp 0x47a8
movslq (%rbx), %rcx
movq %rcx, %rax
addq %r14, %rax
xorl %edx, %edx
xorl %r15d, %r15d
cmpl $0x4, %edx
je 0x4419
incl %ecx
movl %ecx, (%rbx)
movzbl (%rax,%rdx), %esi
shll $0x8, %r15d
orl %esi, %r15d
incq %rdx
jmp 0x4400
testl %r13d, %r13d
setns %al
cmpl $0x3, %r12d
setne %dl
orb %al, %dl
jne 0x445c
leaq 0x41d7(%rip), %rsi      # 0x8608
leaq 0x18(%rsp), %rdi
callq 0x49b9
movl (%rbx), %ecx
testb %al, %al
je 0x445c
movslq %ecx, %rax
addq %rax, %r14
movq 0x8(%rsp), %rdi
addq $0x38, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4ab8
movl (%rbx), %ecx
leal (%rcx,%r15,8), %eax
movl %eax, (%rbx)
jmp 0x47a8
testl %r13d, %r13d
jns 0x4498
movl %r12d, %ebp
leaq 0x78(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x21e0
leaq 0x78(%rsp), %r12
movl %ebp, %edi
movq %r12, %rsi
callq 0x39b4
movq %r12, %rdi
movl %eax, %r12d
callq 0x20a0
pushq $-0x1
popq %rbp
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl %ebp, %ecx
movl %r12d, %r8d
callq 0x430e
testb %al, %al
jne 0x449b
jmp 0x47a8
testl %r13d, %r13d
setns %al
movslq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movl %edx, (%rbx)
movzbl (%r14,%rcx), %ebp
leal 0x2(%rcx), %edx
movl %edx, (%rbx)
movzbl 0x1(%r14,%rcx), %ecx
shll $0x8, %ebp
orl %ecx, %ebp
cmpl $0x4, %r12d
setne %cl
orb %al, %cl
je 0x46f6
testl %r13d, %r13d
setns %al
cmpl $0x5, %r12d
setne %cl
orb %al, %cl
jne 0x473b
leaq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x21e0
movslq (%rbx), %rax
addq %rax, %r14
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x49d0
leaq 0x58(%rsp), %r12
leaq 0x38(%rsp), %rdx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x3cf2
leaq 0x38(%rsp), %rdi
callq 0x20a0
jmp 0x4733
testl %r13d, %r13d
setns %al
cmpl $0x2, %r12d
setne %cl
orb %al, %cl
je 0x473f
addl $0x4, (%rbx)
jmp 0x47a8
testl %r13d, %r13d
setns %al
cmpl $0x3, %r12d
setne %cl
orb %al, %cl
jne 0x459e
leaq 0x4077(%rip), %rsi      # 0x85f7
leaq 0x18(%rsp), %rdi
callq 0x49b9
testb %al, %al
je 0x459e
movslq (%rbx), %rax
movzbl (%r14,%rax), %eax
movq 0x8(%rsp), %rcx
movl %eax, 0x4(%rcx)
incl (%rbx)
jmp 0x47a8
addl $0x2, (%rbx)
jmp 0x47a8
movslq (%rbx), %rax
addq %rax, %r14
leal 0x1(%rax), %ecx
negl %eax
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x4, %edx
je 0x45d7
leal (%rcx,%rdx), %edi
movl %edi, (%rbx)
movzbl (%r14,%rdx), %edi
shll $0x8, %esi
orl %edi, %esi
decl %eax
incq %rdx
jmp 0x45bc
subl %eax, %esi
movl %esi, (%rbx)
jmp 0x47a8
movslq (%rbx), %rax
addq %rax, %r14
leal 0x1(%rax), %ecx
negl %eax
xorl %esi, %esi
xorl %edx, %edx
cmpl $0x4, %esi
je 0x460a
leal (%rcx,%rsi), %edi
movl %edi, (%rbx)
movzbl (%r14,%rsi), %edi
shll $0x8, %edx
orl %edi, %edx
decl %eax
incq %rsi
jmp 0x45ef
shll $0x2, %edx
subl %eax, %edx
movl %edx, (%rbx)
jmp 0x47a8
movslq (%rbx), %rcx
leal 0x1(%rcx), %eax
movl %eax, (%rbx)
movzbl (%r14,%rcx), %edx
movl %edx, 0x10(%rsp)
cltq
addq %r14, %rax
addl $0x2, %ecx
xorl %edx, %edx
xorl %r15d, %r15d
cmpl $0x4, %edx
je 0x464e
leal (%rcx,%rdx), %esi
movl %esi, (%rbx)
movzbl (%rax,%rdx), %esi
shll $0x8, %r15d
orl %esi, %r15d
incq %rdx
jmp 0x4634
movl %r15d, %eax
sarl $0x6, %eax
movq 0x8(%rsp), %rcx
movl %eax, 0x14(%rcx)
movl %r12d, %ebp
testl %r13d, %r13d
jns 0x4693
leaq 0x98(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x21e0
leaq 0x98(%rsp), %r13
movl %ebp, %edi
movq %r13, %rsi
callq 0x39b4
movl %eax, %r12d
movq %r13, %rdi
callq 0x20a0
movl %ebp, %eax
xorl $0x2, %eax
movl %r12d, %ecx
xorl $0x3, %ecx
orl %eax, %ecx
sete %r13b
xorl $0x3, %ebp
movl %r12d, %eax
xorl $0x4, %eax
orl %ebp, %eax
sete %bpl
subl $0x1, %r15d
jb 0x47a8
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl 0x10(%rsp), %ecx
movl %r12d, %r8d
callq 0x430e
testb %r13b, %r13b
je 0x46e5
movq 0x8(%rsp), %rdi
callq 0x4198
jmp 0x46b3
testb %bpl, %bpl
je 0x46b3
movq 0x8(%rsp), %rdi
callq 0x42a4
jmp 0x46b3
leaq 0x3f06(%rip), %rsi      # 0x8603
leaq 0x18(%rsp), %rdi
callq 0x49b9
testb %al, %al
je 0x473b
movslq (%rbx), %rax
addq %rax, %r14
leaq 0xb8(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x49d0
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x3a5c
movq %r12, %rdi
callq 0x20a0
addl %ebp, (%rbx)
jmp 0x47a8
leaq 0x3eb3(%rip), %rsi      # 0x85f9
leaq 0x18(%rsp), %rdi
callq 0x49b9
testb %al, %al
jne 0x476d
leaq 0x3ea3(%rip), %rsi      # 0x85fe
leaq 0x18(%rsp), %rdi
callq 0x49b9
testb %al, %al
je 0x4560
movslq (%rbx), %rax
addq %rax, %r14
leal 0x1(%rax), %ecx
xorl %edx, %edx
xorl %eax, %eax
cmpl $0x4, %edx
je 0x4793
leal (%rcx,%rdx), %esi
movl %esi, (%rbx)
movzbl (%r14,%rdx), %esi
shll $0x8, %eax
orl %esi, %eax
incq %rdx
jmp 0x477a
movq 0x18(%rsp), %rcx
xorl %edx, %edx
cmpb $0x78, (%rcx)
setne %dl
movq 0x8(%rsp), %rcx
movl %eax, (%rcx,%rdx,8)
leaq 0x18(%rsp), %rdi
callq 0x20a0
movl 0x14(%rsp), %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x20a0
jmp 0x47e7
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x47ec
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x20a0
jmp 0x4802
jmp 0x47ff
jmp 0x47ff
jmp 0x47ff
jmp 0x47ff
jmp 0x47ff
jmp 0x47ff
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x2240