// File: 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:
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, 0x1b8(%rsp)
movq %rsi, 0x1b0(%rsp)
movq %rdx, 0x1a8(%rsp)
movl %ecx, 0x1a4(%rsp)
movl %r8d, 0x1a0(%rsp)
movq 0x1b8(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x2280
cmpl $0x0, 0x1a4(%rsp)
jge 0x8b35
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, 0x1a4(%rsp)
cmpl $0x0, 0x1a4(%rsp)
jne 0x8a4f
movb $0x0, 0x1c7(%rsp)
movl $0x1, 0x174(%rsp)
jmp 0x944c
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movslq (%rdx), %rcx
movl %ecx, %esi
incl %esi
movl %esi, (%rdx)
movzbl (%rax,%rcx), %eax
movl %eax, 0x170(%rsp)
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movslq (%rdx), %rcx
movl %ecx, %esi
incl %esi
movl %esi, (%rdx)
movzbl (%rax,%rcx), %ecx
movl 0x170(%rsp), %eax
shll $0x8, %eax
movl %eax, 0x170(%rsp)
movl 0x170(%rsp), %eax
orl %ecx, %eax
movl %eax, 0x170(%rsp)
movq 0x1b0(%rsp), %rsi
movq 0x1a8(%rsp), %rax
movslq (%rax), %rax
addq %rax, %rsi
movl 0x170(%rsp), %edx
leaq 0x150(%rsp), %rdi
callq 0x9980
jmp 0x8add
leaq 0x178(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x2250
leaq 0x150(%rsp), %rdi
callq 0x2100
movb $0x1, 0x19f(%rsp)
movl 0x170(%rsp), %ecx
movq 0x1a8(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x8b3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x946a
movb $0x0, 0x19f(%rsp)
movl 0x1a4(%rsp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x50(%rsp)
subl $0xb, %eax
ja 0x9439
movq 0x50(%rsp), %rax
leaq 0xa76e(%rip), %rcx      # 0x132d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x3, 0x1a0(%rsp)
jne 0x8bc4
testb $0x1, 0x19f(%rsp)
je 0x8bc4
leaq 0xaa25(%rip), %rsi      # 0x135ab
leaq 0x178(%rsp), %rdi
callq 0x9810
movb %al, 0x4f(%rsp)
jmp 0x8b99
movb 0x4f(%rsp), %al
testb $0x1, %al
jne 0x8ba3
jmp 0x8bc4
movq 0x58(%rsp), %rdi
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rcx
movslq (%rcx), %rcx
movzbl (%rax,%rcx), %esi
callq 0x7a10
movq 0x1a8(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x9439
movq 0x1a8(%rsp), %rax
movl (%rax), %ecx
addl $0x2, %ecx
movl %ecx, (%rax)
jmp 0x9439
cmpl $0x2, 0x1a0(%rsp)
jne 0x8d1c
testb $0x1, 0x19f(%rsp)
je 0x8d1c
leaq 0xa99e(%rip), %rsi      # 0x135ad
leaq 0x178(%rsp), %rdi
callq 0x9810
movb %al, 0x4e(%rsp)
jmp 0x8c22
movb 0x4e(%rsp), %al
testb $0x1, %al
jne 0x8c53
jmp 0x8c2c
leaq 0xa97f(%rip), %rsi      # 0x135b2
leaq 0x178(%rsp), %rdi
callq 0x9810
movb %al, 0x4d(%rsp)
jmp 0x8c46
movb 0x4d(%rsp), %al
testb $0x1, %al
jne 0x8c53
jmp 0x8d1c
movl $0x0, 0x140(%rsp)
movl $0x0, 0x13c(%rsp)
cmpl $0x4, 0x13c(%rsp)
jge 0x8cc5
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl 0x140(%rsp), %ecx
shll $0x8, %ecx
movl %ecx, 0x140(%rsp)
orl 0x140(%rsp), %eax
movl %eax, 0x140(%rsp)
movl 0x13c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x13c(%rsp)
jmp 0x8c69
movl 0x140(%rsp), %eax
movl %eax, 0x3c(%rsp)
xorl %eax, %eax
movl %eax, %esi
leaq 0x178(%rsp), %rdi
callq 0x2350
movq %rax, 0x40(%rsp)
jmp 0x8ce8
movq 0x40(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x78, %eax
jne 0x8d01
movq 0x58(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0x8d0f
movq 0x58(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x30(%rsp)
movl 0x3c(%rsp), %ecx
movq 0x30(%rsp), %rax
movl %ecx, (%rax)
jmp 0x8d2b
movq 0x1a8(%rsp), %rax
movl (%rax), %ecx
addl $0x4, %ecx
movl %ecx, (%rax)
jmp 0x9439
movq 0x1a8(%rsp), %rax
movl (%rax), %ecx
addl $0x8, %ecx
movl %ecx, (%rax)
jmp 0x9439
movq 0x1a8(%rsp), %rax
movl (%rax), %ecx
addl $0x4, %ecx
movl %ecx, (%rax)
jmp 0x9439
movq 0x1a8(%rsp), %rax
movl (%rax), %ecx
addl $0x8, %ecx
movl %ecx, (%rax)
jmp 0x9439
movl $0x0, 0x138(%rsp)
movl $0x0, 0x134(%rsp)
cmpl $0x4, 0x134(%rsp)
jge 0x8dde
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl 0x138(%rsp), %ecx
shll $0x8, %ecx
movl %ecx, 0x138(%rsp)
orl 0x138(%rsp), %eax
movl %eax, 0x138(%rsp)
movl 0x134(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x134(%rsp)
jmp 0x8d82
movl 0x138(%rsp), %ecx
movq 0x1a8(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x9439
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, 0x130(%rsp)
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl 0x130(%rsp), %ecx
shll $0x8, %ecx
movl %ecx, 0x130(%rsp)
orl 0x130(%rsp), %eax
movl %eax, 0x130(%rsp)
cmpl $0x4, 0x1a0(%rsp)
jne 0x8f11
testb $0x1, 0x19f(%rsp)
je 0x8f11
leaq 0xa738(%rip), %rsi      # 0x135b7
leaq 0x178(%rsp), %rdi
callq 0x9810
movb %al, 0x2f(%rsp)
jmp 0x8e92
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x8e9c
jmp 0x8f11
movq 0x1b0(%rsp), %rsi
movq 0x1a8(%rsp), %rax
movslq (%rax), %rax
addq %rax, %rsi
movl 0x130(%rsp), %edx
leaq 0x110(%rsp), %rdi
callq 0x9980
jmp 0x8ec8
movq 0x58(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x7a30
jmp 0x8edc
leaq 0x110(%rsp), %rdi
callq 0x2100
jmp 0x8f11
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0x110(%rsp), %rdi
callq 0x2100
jmp 0x946a
cmpl $0x5, 0x1a0(%rsp)
jne 0x8ff1
testb $0x1, 0x19f(%rsp)
je 0x8ff1
leaq 0xf0(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x20b0
jmp 0x8f44
movq 0x1b0(%rsp), %rsi
movq 0x1a8(%rsp), %rax
movslq (%rax), %rax
addq %rax, %rsi
movl 0x130(%rsp), %edx
leaq 0xd0(%rsp), %rdi
callq 0x9980
jmp 0x8f70
movq 0x58(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
callq 0x7f60
jmp 0x8f8c
leaq 0xd0(%rsp), %rdi
callq 0x2100
leaq 0xf0(%rsp), %rdi
callq 0x2100
jmp 0x8ff1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
jmp 0x8fdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x2100
leaq 0xf0(%rsp), %rdi
callq 0x2100
jmp 0x946a
movl 0x130(%rsp), %ecx
movq 0x1a8(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x9439
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, 0xcf(%rsp)
movl $0x0, 0xc8(%rsp)
movl $0x0, 0xc4(%rsp)
cmpl $0x4, 0xc4(%rsp)
jge 0x90a1
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl 0xc8(%rsp), %ecx
shll $0x8, %ecx
movl %ecx, 0xc8(%rsp)
orl 0xc8(%rsp), %eax
movl %eax, 0xc8(%rsp)
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x9045
movq 0x58(%rsp), %rax
movl 0xc8(%rsp), %ecx
sarl $0x6, %ecx
movl %ecx, 0x14(%rax)
movb 0x19f(%rsp), %al
movb $0x0, 0x9f(%rsp)
testb $0x1, %al
je 0x9111
movl 0x1a0(%rsp), %eax
movl %eax, 0x28(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x20b0
jmp 0x90e8
movl 0x28(%rsp), %edi
movb $0x1, 0x9f(%rsp)
leaq 0xa0(%rsp), %rsi
callq 0x7910
movl %eax, 0x24(%rsp)
jmp 0x9107
movl 0x24(%rsp), %eax
movl %eax, 0x20(%rsp)
jmp 0x911c
movl 0x1a0(%rsp), %eax
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x1c(%rsp)
testb $0x1, 0x9f(%rsp)
jne 0x9130
jmp 0x913d
leaq 0xa0(%rsp), %rdi
callq 0x2100
movl 0x1c(%rsp), %eax
movl %eax, 0xc0(%rsp)
movl 0xc8(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0xc8(%rsp)
cmpl $0x0, %eax
je 0x920b
movq 0x58(%rsp), %rdi
movq 0x1b0(%rsp), %rsi
movq 0x1a8(%rsp), %rdx
movzbl 0xcf(%rsp), %ecx
movl 0xc0(%rsp), %r8d
callq 0x89b0
jmp 0x9190
cmpl $0x2, 0x1a0(%rsp)
jne 0x91e4
cmpl $0x3, 0xc0(%rsp)
jne 0x91e4
movq 0x58(%rsp), %rdi
callq 0x8740
jmp 0x91b0
jmp 0x91e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
testb $0x1, 0x9f(%rsp)
jne 0x91d2
jmp 0x91df
leaq 0xa0(%rsp), %rdi
callq 0x2100
jmp 0x946a
cmpl $0x3, 0x1a0(%rsp)
jne 0x9206
cmpl $0x4, 0xc0(%rsp)
jne 0x9206
movq 0x58(%rsp), %rdi
callq 0x8900
jmp 0x9204
jmp 0x9206
jmp 0x9148
jmp 0x9439
movb 0x19f(%rsp), %al
movb $0x0, 0x77(%rsp)
testb $0x1, %al
je 0x9262
movl 0x1a0(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x20b0
jmp 0x923f
movl 0x18(%rsp), %edi
movb $0x1, 0x77(%rsp)
leaq 0x78(%rsp), %rsi
callq 0x7910
movl %eax, 0x14(%rsp)
jmp 0x9258
movl 0x14(%rsp), %eax
movl %eax, 0x10(%rsp)
jmp 0x926d
movl 0x1a0(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0xc(%rsp)
testb $0x1, 0x77(%rsp)
jne 0x927e
jmp 0x9288
leaq 0x78(%rsp), %rdi
callq 0x2100
movl 0xc(%rsp), %eax
movl %eax, 0x98(%rsp)
movq 0x58(%rsp), %rdi
movq 0x1b0(%rsp), %rsi
movq 0x1a8(%rsp), %rdx
movl 0x98(%rsp), %r8d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x89b0
movb %al, 0xb(%rsp)
jmp 0x92c0
movb 0xb(%rsp), %al
testb $0x1, %al
jne 0x92ca
jmp 0x92f8
jmp 0x9293
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x148(%rsp)
movl %eax, 0x144(%rsp)
testb $0x1, 0x77(%rsp)
jne 0x92e9
jmp 0x92f3
leaq 0x78(%rsp), %rdi
callq 0x2100
jmp 0x946a
jmp 0x9439
movl $0x0, 0x70(%rsp)
movl $0x0, 0x6c(%rsp)
cmpl $0x4, 0x6c(%rsp)
jge 0x9354
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl 0x70(%rsp), %ecx
shll $0x8, %ecx
movl %ecx, 0x70(%rsp)
orl 0x70(%rsp), %eax
movl %eax, 0x70(%rsp)
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x930d
movl 0x70(%rsp), %ecx
shll $0x2, %ecx
movq 0x1a8(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x9439
movl $0x0, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
cmpl $0x4, 0x64(%rsp)
jge 0x93c3
movq 0x1b0(%rsp), %rax
movq 0x1a8(%rsp), %rdx
movl (%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, (%rdx)
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl 0x68(%rsp), %ecx
shll $0x8, %ecx
movl %ecx, 0x68(%rsp)
orl 0x68(%rsp), %eax
movl %eax, 0x68(%rsp)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x937c
cmpl $0x3, 0x1a0(%rsp)
jne 0x9426
testb $0x1, 0x19f(%rsp)
je 0x9426
leaq 0xa1de(%rip), %rsi      # 0x135bc
leaq 0x178(%rsp), %rdi
callq 0x9810
movb %al, 0xa(%rsp)
jmp 0x93f1
movb 0xa(%rsp), %al
testb $0x1, %al
jne 0x93fb
jmp 0x9426
movq 0x58(%rsp), %rdi
movq 0x1b0(%rsp), %rsi
movq 0x1a8(%rsp), %rax
movslq (%rax), %rax
addq %rax, %rsi
movl 0x68(%rsp), %edx
shll $0x3, %edx
callq 0x8710
jmp 0x9424
jmp 0x9426
movl 0x68(%rsp), %ecx
shll $0x3, %ecx
movq 0x1a8(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movb $0x1, 0x1c7(%rsp)
movl $0x1, 0x174(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x2100
movb 0x1c7(%rsp), %al
andb $0x1, %al
addq $0x1c8, %rsp            # imm = 0x1C8
retq
leaq 0x178(%rsp), %rdi
callq 0x2100
movq 0x148(%rsp), %rdi
callq 0x2300
nopw %cs:(%rax,%rax)