// File: rossy[P]crossc/SPIRV-Cross/spirv_parser.cpp
// Function: spirv_cross::Parser::parse()
void Parser::parse()
{
	auto &spirv = ir.spirv;

	auto len = spirv.size();
	if (len < 5)
		SPIRV_CROSS_THROW("SPIRV file too small.");

	auto s = spirv.data();

	// Endian-swap if we need to.
	if (s[0] == swap_endian(MagicNumber))
		transform(begin(spirv), end(spirv), begin(spirv), [](uint32_t c) { return swap_endian(c); });

	if (s[0] != MagicNumber || !is_valid_spirv_version(s[1]))
		SPIRV_CROSS_THROW("Invalid SPIRV format.");

	uint32_t bound = s[3];
	ir.set_id_bounds(bound);

	uint32_t offset = 5;

	vector<Instruction> instructions;
	while (offset < len)
	{
		Instruction instr = {};
		instr.op = spirv[offset] & 0xffff;
		instr.count = (spirv[offset] >> 16) & 0xffff;

		if (instr.count == 0)
			SPIRV_CROSS_THROW("SPIR-V instructions cannot consume 0 words. Invalid SPIR-V file.");

		instr.offset = offset + 1;
		instr.length = instr.count - 1;

		offset += instr.count;

		if (offset > spirv.size())
			SPIRV_CROSS_THROW("SPIR-V instruction goes out of bounds.");

		instructions.push_back(instr);
	}

	for (auto &i : instructions)
		parse(i);

	if (current_function)
		SPIRV_CROSS_THROW("Function was not terminated.");
	if (current_block)
		SPIRV_CROSS_THROW("Block was not terminated.");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8650
movq %rax, -0x18(%rbp)
cmpq $0x5, -0x18(%rbp)
jae 0x12ca0e
movb $0x1, -0x4d(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x1b0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x7650
movq -0x1a8(%rbp), %rdx
leaq 0x212d0(%rip), %rsi     # 0x14dc59
leaq -0x38(%rbp), %rdi
callq 0x7520
jmp 0x12c994
movq -0x1b0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x9c50
jmp 0x12c9a6
movq -0x1b0(%rbp), %rdi
movb $0x0, -0x4d(%rbp)
leaq 0x81420(%rip), %rsi     # 0x1addd8
leaq -0x122d2f(%rip), %rdx   # 0x9c90
callq 0x7610
jmp 0x12d0be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12c9ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x7708
leaq -0x39(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x4d(%rbp)
jne 0x12c9fd
jmp 0x12ca09
movq -0x1b0(%rbp), %rdi
callq 0x72c0
jmp 0x12d0b5
movq -0x10(%rbp), %rdi
callq 0x32960
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1b4(%rbp)
movl $0x7230203, %edi        # imm = 0x7230203
callq 0x12d0c0
movl %eax, %ecx
movl -0x1b4(%rbp), %eax
cmpl %ecx, %eax
jne 0x12ca79
movq -0x10(%rbp), %rdi
callq 0x85d0
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8600
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
callq 0x85d0
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x12d100
movq %rax, -0x80(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x7230203, (%rax)      # imm = 0x7230203
jne 0x12ca99
movq -0x58(%rbp), %rax
movl 0x4(%rax), %edi
callq 0x12d180
testb $0x1, %al
jne 0x12cb69
movb $0x1, -0xa2(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x1c8(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x7650
movq -0x1c0(%rbp), %rdx
leaq 0x2119d(%rip), %rsi     # 0x14dc6f
leaq -0xa0(%rbp), %rdi
callq 0x7520
jmp 0x12cae0
movq -0x1c8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x9c50
jmp 0x12caf5
movq -0x1c8(%rbp), %rdi
movb $0x0, -0xa2(%rbp)
leaq 0x812ce(%rip), %rsi     # 0x1addd8
leaq -0x122e81(%rip), %rdx   # 0x9c90
callq 0x7610
jmp 0x12d0be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12cb41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x7708
leaq -0xa1(%rbp), %rdi
callq 0x73d0
testb $0x1, -0xa2(%rbp)
jne 0x12cb58
jmp 0x12cb64
movq -0x1c8(%rbp), %rdi
callq 0x72c0
jmp 0x12d0b5
movq -0x1a0(%rbp), %rdi
movq -0x58(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %esi
callq 0x54090
movl $0x5, -0xac(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x131b40
movl -0xac(%rbp), %eax
cmpq -0x18(%rbp), %rax
jae 0x12ce4b
movw $0x0, -0xd4(%rbp)
movw $0x0, -0xd2(%rbp)
movl $0x0, -0xd0(%rbp)
movl $0x0, -0xcc(%rbp)
movq -0x10(%rbp), %rdi
movl -0xac(%rbp), %eax
movl %eax, %esi
callq 0x8630
movl (%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movw %ax, -0xd4(%rbp)
movq -0x10(%rbp), %rdi
movl -0xac(%rbp), %eax
movl %eax, %esi
callq 0x8630
movl (%rax), %eax
shrl $0x10, %eax
andl $0xffff, %eax           # imm = 0xFFFF
movw %ax, -0xd2(%rbp)
movzwl -0xd2(%rbp), %eax
cmpl $0x0, %eax
jne 0x12ccf5
movb $0x1, -0xfa(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x1d8(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x7650
movq -0x1d0(%rbp), %rdx
leaq 0x21027(%rip), %rsi     # 0x14dc85
leaq -0xf8(%rbp), %rdi
callq 0x7520
jmp 0x12cc6c
movq -0x1d8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x9c50
jmp 0x12cc81
movq -0x1d8(%rbp), %rdi
movb $0x0, -0xfa(%rbp)
leaq 0x81142(%rip), %rsi     # 0x1addd8
leaq -0x12300d(%rip), %rdx   # 0x9c90
callq 0x7610
jmp 0x12d0be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12cccd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x7708
leaq -0xf9(%rbp), %rdi
callq 0x73d0
testb $0x1, -0xfa(%rbp)
jne 0x12cce4
jmp 0x12ccf0
movq -0x1d8(%rbp), %rdi
callq 0x72c0
jmp 0x12d0a9
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
movzwl -0xd2(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xcc(%rbp)
movzwl -0xd2(%rbp), %eax
addl -0xac(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %eax
movq %rax, -0x1e0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x8650
movq %rax, %rcx
movq -0x1e0(%rbp), %rax
cmpq %rcx, %rax
jbe 0x12ce20
movb $0x1, -0x122(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x1f0(%rbp)
leaq -0x121(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x7650
movq -0x1e8(%rbp), %rdx
leaq 0x20f3d(%rip), %rsi     # 0x14dcc6
leaq -0x120(%rbp), %rdi
callq 0x7520
jmp 0x12cd97
movq -0x1f0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x9c50
jmp 0x12cdac
movq -0x1f0(%rbp), %rdi
movb $0x0, -0x122(%rbp)
leaq 0x81017(%rip), %rsi     # 0x1addd8
leaq -0x123138(%rip), %rdx   # 0x9c90
callq 0x7610
jmp 0x12d0be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12cdf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x7708
leaq -0x121(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x122(%rbp)
jne 0x12ce0f
jmp 0x12ce1b
movq -0x1f0(%rbp), %rdi
callq 0x72c0
jmp 0x12d0a9
leaq -0xc8(%rbp), %rdi
leaq -0xd4(%rbp), %rsi
callq 0x131b60
jmp 0x12ce35
jmp 0x12cb9e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12d0a9
leaq -0xc8(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rdi
callq 0xa4cc0
movq %rax, -0x138(%rbp)
movq -0x130(%rbp), %rdi
callq 0xa4cf0
movq %rax, -0x140(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0xa4d20
testb $0x1, %al
jne 0x12ce98
jmp 0x12ced0
leaq -0x138(%rbp), %rdi
callq 0xa4d60
movq -0x1a0(%rbp), %rdi
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rsi
callq 0x12d1e0
jmp 0x12cec0
jmp 0x12cec2
leaq -0x138(%rbp), %rdi
callq 0xa4d80
jmp 0x12ce7f
movq -0x1a0(%rbp), %rax
cmpq $0x0, 0x110(%rax)
je 0x12cfb5
movb $0x1, -0x16a(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x200(%rbp)
leaq -0x169(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x7650
movq -0x1f8(%rbp), %rdx
leaq 0x20dcf(%rip), %rsi     # 0x14dced
leaq -0x168(%rbp), %rdi
callq 0x7520
jmp 0x12cf2c
movq -0x200(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x9c50
jmp 0x12cf41
movq -0x200(%rbp), %rdi
movb $0x0, -0x16a(%rbp)
leaq 0x80e82(%rip), %rsi     # 0x1addd8
leaq -0x1232cd(%rip), %rdx   # 0x9c90
callq 0x7610
jmp 0x12d0be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12cf8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x7708
leaq -0x169(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x16a(%rbp)
jne 0x12cfa4
jmp 0x12cfb0
movq -0x200(%rbp), %rdi
callq 0x72c0
jmp 0x12d0a9
movq -0x1a0(%rbp), %rax
cmpq $0x0, 0x118(%rax)
je 0x12d094
movb $0x1, -0x192(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x210(%rbp)
leaq -0x191(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x7650
movq -0x208(%rbp), %rdx
leaq 0x20d07(%rip), %rsi     # 0x14dd0a
leaq -0x190(%rbp), %rdi
callq 0x7520
jmp 0x12d011
movq -0x210(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x9c50
jmp 0x12d026
movq -0x210(%rbp), %rdi
movb $0x0, -0x192(%rbp)
leaq 0x80d9d(%rip), %rsi     # 0x1addd8
leaq -0x1233b2(%rip), %rdx   # 0x9c90
callq 0x7610
jmp 0x12d0be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x12d06f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x7708
leaq -0x191(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x192(%rbp)
jne 0x12d086
jmp 0x12d092
movq -0x210(%rbp), %rdi
callq 0x72c0
jmp 0x12d0a9
leaq -0xc8(%rbp), %rdi
callq 0x131bd0
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
leaq -0xc8(%rbp), %rdi
callq 0x131bd0
movq -0x48(%rbp), %rdi
callq 0x7640
nop