// File: rossy[P]crossc/SPIRV-Cross/spirv_msl.cpp
// Function: spirv_cross::CompilerMSL::OpCodePreprocessor::handle(spv::Op, unsigned int const*, unsigned int)
bool CompilerMSL::OpCodePreprocessor::handle(Op opcode, const uint32_t *args, uint32_t length)
{
	// Since MSL exists in a single execution scope, function prototype declarations are not
	// needed, and clutter the output. If secondary functions are output (either as a SPIR-V
	// function implementation or as indicated by the presence of OpFunctionCall), then set
	// suppress_missing_prototypes to suppress compiler warnings of missing function prototypes.

	// Mark if the input requires the implementation of an SPIR-V function that does not exist in Metal.
	SPVFuncImpl spv_func = get_spv_func_impl(opcode, args);
	if (spv_func != SPVFuncImplNone)
	{
		compiler.spv_function_implementations.insert(spv_func);
		suppress_missing_prototypes = true;
	}

	switch (opcode)
	{

	case OpFunctionCall:
		suppress_missing_prototypes = true;
		break;

	case OpImageWrite:
		uses_resource_write = true;
		break;

	case OpStore:
		check_resource_write(args[0]);
		break;

	case OpAtomicExchange:
	case OpAtomicCompareExchange:
	case OpAtomicCompareExchangeWeak:
	case OpAtomicIIncrement:
	case OpAtomicIDecrement:
	case OpAtomicIAdd:
	case OpAtomicISub:
	case OpAtomicSMin:
	case OpAtomicUMin:
	case OpAtomicSMax:
	case OpAtomicUMax:
	case OpAtomicAnd:
	case OpAtomicOr:
	case OpAtomicXor:
		uses_atomics = true;
		check_resource_write(args[2]);
		break;

	case OpAtomicLoad:
		uses_atomics = true;
		break;

	default:
		break;
	}

	// If it has one, keep track of the instruction's result type, mapped by ID
	uint32_t result_type, result_id;
	if (compiler.instruction_to_result_type(result_type, result_id, opcode, args, length))
		result_types[result_id] = result_type;

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x40(%rbp)
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x10de30
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x10dd5d
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
addq $0x7e0, %rdi            # imm = 0x7E0
leaq -0x20(%rbp), %rsi
callq 0x1170d0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, -0x30(%rbp)
movb %dl, -0x28(%rbp)
movb $0x1, 0x48(%rax)
movl -0xc(%rbp), %eax
movl %eax, -0x44(%rbp)
subl $0x39, %eax
je 0x10dd99
jmp 0x10dd6a
movl -0x44(%rbp), %eax
subl $0x3e, %eax
je 0x10ddad
jmp 0x10dd74
movl -0x44(%rbp), %eax
subl $0x63, %eax
je 0x10dda3
jmp 0x10dd7e
movl -0x44(%rbp), %eax
subl $0xe3, %eax
je 0x10ddd4
jmp 0x10dd8a
movl -0x44(%rbp), %eax
addl $0xffffff1b, %eax       # imm = 0xFFFFFF1B
subl $0xe, %eax
jb 0x10ddbe
jmp 0x10ddde
movq -0x40(%rbp), %rax
movb $0x1, 0x48(%rax)
jmp 0x10dde0
movq -0x40(%rbp), %rax
movb $0x1, 0x4a(%rax)
jmp 0x10dde0
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
callq 0x10e4a0
jmp 0x10dde0
movq -0x40(%rbp), %rdi
movb $0x1, 0x49(%rdi)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x10e4a0
jmp 0x10dde0
movq -0x40(%rbp), %rax
movb $0x1, 0x49(%rax)
jmp 0x10dde0
jmp 0x10dde0
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0xc(%rbp), %ecx
movq -0x18(%rbp), %r8
movl -0x1c(%rbp), %r9d
leaq -0x34(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x291b0
testb $0x1, %al
jne 0x10de06
jmp 0x10de22
movq -0x40(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, -0x48(%rbp)
addq $0x10, %rdi
leaq -0x38(%rbp), %rsi
callq 0x30850
movl -0x48(%rbp), %ecx
movl %ecx, (%rax)
movb $0x1, %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)