// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, (%rsp)
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %ecx, %r15d
testl %ecx, %ecx
jns 0x46c5
movslq (%rbx), %rax
leaq 0x1(%rax), %rcx
movl %ecx, (%rbx)
movzbl (%r14,%rax), %r15d
testl %r15d, %r15d
je 0x46f0
movl %r12d, 0xc(%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 0x4e3c
leaq 0x10(%rsp), %rdi
leaq 0xd8(%rsp), %rbp
movq %rbp, %rsi
callq 0x21a0
movq (%rbp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x46bd
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2150
addl %r12d, (%rbx)
movl 0xc(%rsp), %r12d
movb $0x1, %al
movl %eax, 0xc(%rsp)
decl %r15d
cmpl $0xb, %r15d
ja 0x4b2e
leaq 0x3c25(%rip), %rax      # 0x8304
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
addl $0x8, (%rbx)
jmp 0x4b2e
movl $0x0, 0xc(%rsp)
jmp 0x4b2e
movslq (%rbx), %rcx
leal 0x1(%rcx), %eax
addq %r14, %rcx
xorl %edx, %edx
xorl %ebp, %ebp
leal (%rax,%rdx), %esi
movl %esi, (%rbx)
movzbl (%rcx,%rdx), %esi
shll $0x8, %ebp
orl %esi, %ebp
incq %rdx
cmpl $0x4, %edx
jne 0x470a
testl %r13d, %r13d
setns %al
cmpl $0x3, %r12d
setne %cl
orb %al, %cl
jne 0x475e
leaq 0x3ee0(%rip), %rsi      # 0x8618
leaq 0x10(%rsp), %rdi
callq 0x2050
testl %eax, %eax
jne 0x475e
movslq (%rbx), %rax
addq %rax, %r14
movq (%rsp), %rdi
addq $0x38, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4f2a
shll $0x3, %ebp
addl %ebp, (%rbx)
jmp 0x4b2e
testl %r13d, %r13d
jns 0x47a6
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x4daa
leaq 0x98(%rsp), %rsi
movl %r12d, %edi
callq 0x3c04
movl %eax, %r12d
testl %r13d, %r13d
jns 0x47cc
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x47cc
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2150
movq (%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %r12d, %r8d
callq 0x45f6
testb %al, %al
jne 0x47cc
jmp 0x4b2e
testl %r13d, %r13d
setns %al
movslq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movl %edx, (%rbx)
movl %r12d, %esi
movzbl (%r14,%rcx), %r12d
leal 0x2(%rcx), %edx
movl %edx, (%rbx)
movzbl 0x1(%r14,%rcx), %ecx
shll $0x8, %r12d
orl %ecx, %r12d
movl %esi, %ebp
cmpl $0x4, %esi
setne %cl
orb %al, %cl
jne 0x4878
leaq 0x3deb(%rip), %rsi      # 0x8613
leaq 0x10(%rsp), %rdi
callq 0x2050
testl %eax, %eax
jne 0x4878
movslq (%rbx), %rsi
addq %r14, %rsi
leaq 0x78(%rsp), %rdi
movl %r12d, %edx
callq 0x4e3c
leaq 0x78(%rsp), %rsi
movq (%rsp), %rdi
callq 0x3cf4
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4878
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2150
testl %r13d, %r13d
setns %al
cmpl $0x5, %ebp
setne %cl
orb %al, %cl
jne 0x4903
leaq 0x48(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rdi
callq 0x4daa
movslq (%rbx), %rax
addq %rax, %r14
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
movl %r12d, %edx
callq 0x4e3c
leaq 0x38(%rsp), %rsi
leaq 0x58(%rsp), %rdx
movq (%rsp), %rdi
callq 0x3ffa
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x48ec
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x38(%rsp), %rdi
cmpq %r13, %rdi
je 0x4903
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2150
addl %r12d, (%rbx)
jmp 0x4b2e
testl %r13d, %r13d
setns %al
cmpl $0x2, %r12d
setne %cl
orb %al, %cl
jne 0x494e
leaq 0x3ce6(%rip), %rsi      # 0x8609
leaq 0x10(%rsp), %rdi
callq 0x2050
testl %eax, %eax
je 0x4af6
leaq 0x3cd2(%rip), %rsi      # 0x860e
leaq 0x10(%rsp), %rdi
callq 0x2050
testl %eax, %eax
je 0x4af6
addl $0x4, (%rbx)
jmp 0x4b2e
testl %r13d, %r13d
setns %al
cmpl $0x3, %r12d
setne %cl
orb %al, %cl
jne 0x498b
leaq 0x3c99(%rip), %rsi      # 0x8607
leaq 0x10(%rsp), %rdi
callq 0x2050
testl %eax, %eax
jne 0x498b
movslq (%rbx), %rax
movzbl (%r14,%rax), %eax
movq (%rsp), %rcx
movl %eax, 0x4(%rcx)
incl (%rbx)
jmp 0x4b2e
addl $0x2, (%rbx)
jmp 0x4b2e
movslq (%rbx), %rax
addq %rax, %r14
incl %eax
xorl %ecx, %ecx
xorl %edx, %edx
leal (%rax,%rcx), %esi
movl %esi, (%rbx)
movzbl (%r14,%rcx), %esi
shll $0x8, %edx
orl %esi, %edx
incq %rcx
cmpl $0x4, %ecx
jne 0x49a6
jmp 0x49e5
movslq (%rbx), %rax
addq %rax, %r14
incl %eax
xorl %ecx, %ecx
xorl %edx, %edx
leal (%rax,%rcx), %esi
movl %esi, (%rbx)
movzbl (%r14,%rcx), %esi
shll $0x8, %edx
orl %esi, %edx
incq %rcx
cmpl $0x4, %ecx
jne 0x49cb
shll $0x2, %edx
addl %edx, (%rbx)
jmp 0x4b2e
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 %ebp, %ebp
leal (%rcx,%rdx), %esi
movl %esi, (%rbx)
movzbl (%rax,%rdx), %esi
shll $0x8, %ebp
orl %esi, %ebp
incq %rdx
cmpl $0x4, %edx
jne 0x4a09
movl %ebp, %eax
sarl $0x6, %eax
movq (%rsp), %rcx
movl %eax, 0x14(%rcx)
movl %r12d, %r15d
testl %r13d, %r13d
jns 0x4a6c
leaq 0xc8(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x4daa
leaq 0xb8(%rsp), %rsi
movl %r15d, %edi
callq 0x3c04
movl %eax, %r12d
testl %r13d, %r13d
jns 0x4a92
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4a92
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x2150
testl %ebp, %ebp
je 0x4b2e
movl %r15d, %edx
movl %r15d, %eax
xorl $0x2, %eax
movl %r12d, %ecx
xorl $0x3, %ecx
orl %eax, %ecx
sete %r15b
xorl $0x3, %edx
movl %r12d, %eax
xorl $0x4, %eax
orl %edx, %eax
sete %r13b
movq (%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl 0x34(%rsp), %ecx
movl %r12d, %r8d
callq 0x45f6
testb %r15b, %r15b
je 0x4ae2
movq (%rsp), %rdi
callq 0x44ca
testb %r13b, %r13b
je 0x4af0
movq (%rsp), %rdi
callq 0x45a6
decl %ebp
jne 0x4abe
jmp 0x4b2e
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 0x4b03
movq 0x10(%rsp), %rcx
xorl %edx, %edx
cmpb $0x78, (%rcx)
setne %dl
movq (%rsp), %rcx
movl %eax, (%rcx,%rdx,8)
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4b4a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2150
movl 0xc(%rsp), %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x88(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4bc9
movq 0x88(%rsp), %rsi
jmp 0x4bb6
jmp 0x4bc6
jmp 0x4bc6
jmp 0x4bc6
movq %rax, %rbx
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4ba7
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x4ba7
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r13, %rdi
je 0x4bc9
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x4bc9
jmp 0x4bc6
jmp 0x4bc6
jmp 0x4bc6
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x4be5
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2220
nop