// File: /workspace/github_cpp_makefile_star2_O1/rossy[P]crossc/SPIRV-Cross/spirv_msl.cpp
// Function: spirv_cross::CompilerMSL::get_metal_resource_index(spirv_cross::SPIRVariable&, spirv_cross::SPIRType::BaseType)
uint32_t CompilerMSL::get_metal_resource_index(SPIRVariable &var, SPIRType::BaseType basetype)
{
	auto &execution = get_entry_point();
	auto &var_dec = ir.meta[var.self].decoration;
	uint32_t var_desc_set = (var.storage == StorageClassPushConstant) ? kPushConstDescSet : var_dec.set;
	uint32_t var_binding = (var.storage == StorageClassPushConstant) ? kPushConstBinding : var_dec.binding;

	// If a matching binding has been specified, find and use it
	for (auto p_res_bind : resource_bindings)
	{
		if (p_res_bind->stage == execution.model && p_res_bind->desc_set == var_desc_set &&
		    p_res_bind->binding == var_binding)
		{

			p_res_bind->used_by_shader = true;
			switch (basetype)
			{
			case SPIRType::Struct:
				return p_res_bind->msl_buffer;
			case SPIRType::Image:
				return p_res_bind->msl_texture;
			case SPIRType::Sampler:
				return p_res_bind->msl_sampler;
			default:
				return 0;
			}
		}
	}

	// If there is no explicit mapping of bindings to MSL, use the declared binding.
	if (has_decoration(var.self, DecorationBinding))
		return get_decoration(var.self, DecorationBinding);

	uint32_t binding_stride = 1;
	auto &type = get<SPIRType>(var.basetype);
	for (uint32_t i = 0; i < uint32_t(type.array.size()); i++)
		binding_stride *= type.array_size_literal[i] ? type.array[i] : get<SPIRConstant>(type.array[i]).scalar();

	// If a binding has not been specified, revert to incrementing resource indices
	uint32_t resource_index;
	switch (basetype)
	{
	case SPIRType::Struct:
		resource_index = next_metal_resource_index.msl_buffer;
		next_metal_resource_index.msl_buffer += binding_stride;
		break;
	case SPIRType::Image:
		resource_index = next_metal_resource_index.msl_texture;
		next_metal_resource_index.msl_texture += binding_stride;
		break;
	case SPIRType::Sampler:
		resource_index = next_metal_resource_index.msl_sampler;
		next_metal_resource_index.msl_sampler += binding_stride;
		break;
	default:
		resource_index = 0;
		break;
	}
	return resource_index;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x16254
movl 0x8(%r14), %esi
cmpl $0x9, 0x10(%r14)
je 0x9b01a
movq 0x38(%rbx), %rdx
imulq $0x148, %rsi, %rdi      # imm = 0x148
movl 0xac(%rdx,%rdi), %ecx
movl 0xb0(%rdx,%rdi), %edx
jmp 0x9b021
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x8f8(%rbx), %r8
movq 0x900(%rbx), %r9
cmpq %r9, %r8
sete %dil
je 0x9b0a1
movl 0xb8(%rax), %r10d
movl %ebp, %r11d
movq (%r8), %r15
movb $0x1, %r12b
cmpl %r10d, (%r15)
jne 0x9b08d
cmpl %ecx, 0x4(%r15)
jne 0x9b08d
cmpl %edx, 0x8(%r15)
jne 0x9b08d
movb $0x1, 0x18(%r15)
cmpl $0xc, %ebp
je 0x9b083
cmpl $0xf, %ebp
je 0x9b07c
xorl %r12d, %r12d
movl $0x0, %eax
cmpl $0xd, %ebp
jne 0x9b08d
movl $0x10, %eax
jmp 0x9b086
movl $0x14, %eax
jmp 0x9b086
movq %r11, %rax
movl (%r15,%rax), %eax
xorl %r12d, %r12d
testb %r12b, %r12b
je 0x9b0a1
addq $0x8, %r8
cmpq %r9, %r8
sete %dil
jne 0x9b042
jmp 0x9b0a1
testb $0x1, %dil
je 0x9b195
movq %rbx, %rdi
movl $0x21, %edx
callq 0x1299a
testb %al, %al
je 0x9b0db
movl 0x8(%r14), %esi
movq %rbx, %rdi
movl $0x21, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x14ff6
movl 0xc(%r14), %esi
movq %rbx, %rdi
callq 0xa426
movq %rax, %r14
movq 0x20(%rax), %rax
movq 0x28(%r14), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movl $0x1, %r15d
testl %ecx, %ecx
je 0x9b150
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x38(%r14), %rcx
movq %r13, %rdx
shrq $0x6, %rdx
movq (%rcx,%rdx,8), %rcx
addq %r12, %rax
btq %r13, %rcx
jb 0x9b12f
movl (%rax), %esi
movq %rbx, %rdi
callq 0x1c66e
addq $0x10, %rax
imull (%rax), %r15d
incq %r13
movq 0x20(%r14), %rax
movq 0x28(%r14), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movl %ecx, %ecx
addq $0x4, %r12
cmpq %rcx, %r13
jb 0x9b109
cmpl $0xc, %ebp
je 0x9b185
cmpl $0xd, %ebp
je 0x9b173
xorl %eax, %eax
cmpl $0xf, %ebp
jne 0x9b195
movl 0x924(%rbx), %eax
addl %eax, %r15d
movl %r15d, 0x924(%rbx)
jmp 0x9b195
movl 0x920(%rbx), %eax
addl %eax, %r15d
movl %r15d, 0x920(%rbx)
jmp 0x9b195
movl 0x91c(%rbx), %eax
addl %eax, %r15d
movl %r15d, 0x91c(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq