// File: /workspace/github_cpp_makefile_star2_O3/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 0x15f76
movl 0x8(%r14), %esi
cmpl $0x9, 0x10(%r14)
je 0x9a36c
movq 0x38(%rbx), %rdx
imulq $0x148, %rsi, %rdi      # imm = 0x148
movl 0xac(%rdx,%rdi), %ecx
movl 0xb0(%rdx,%rdi), %edx
jmp 0x9a373
xorl %edx, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x8f8(%rbx), %rdi
movq 0x900(%rbx), %r8
cmpq %r8, %rdi
je 0x9a3ac
movl 0xb8(%rax), %r9d
movq (%rdi), %rax
cmpl %r9d, (%rax)
jne 0x9a3a3
cmpl %ecx, 0x4(%rax)
jne 0x9a3a3
cmpl %edx, 0x8(%rax)
je 0x9a479
addq $0x8, %rdi
cmpq %r8, %rdi
jne 0x9a38d
movq %rbx, %rdi
movl $0x21, %edx
callq 0x12974
testb %al, %al
je 0x9a3dc
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 0x14e6e
movl 0xc(%r14), %esi
movq %rbx, %rdi
callq 0xa3ea
movq %rax, %r14
movq 0x20(%rax), %rcx
movq 0x28(%rax), %rdx
movq %rdx, %rax
subq %rcx, %rax
shrq $0x2, %rax
movl $0x1, %r15d
testl %eax, %eax
je 0x9a458
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x38(%r14), %rax
movq %r13, %rsi
shrq $0x6, %rsi
movq (%rax,%rsi,8), %rsi
leaq (%rcx,%r12), %rax
btq %r13, %rsi
jb 0x9a43c
movl (%rax), %esi
movq %rbx, %rdi
callq 0x1c036
addq $0x10, %rax
movq 0x20(%r14), %rcx
movq 0x28(%r14), %rdx
imull (%rax), %r15d
incq %r13
movq %rdx, %rax
subq %rcx, %rax
shrq $0x2, %rax
movl %eax, %eax
addq $0x4, %r12
cmpq %rax, %r13
jb 0x9a40d
cmpl $0xc, %ebp
je 0x9a4a7
cmpl $0xd, %ebp
je 0x9a495
cmpl $0xf, %ebp
jne 0x9a491
movl 0x924(%rbx), %eax
addl %eax, %r15d
movl %r15d, 0x924(%rbx)
jmp 0x9a4c1
movb $0x1, 0x18(%rax)
cmpl $0xf, %ebp
je 0x9a4be
cmpl $0xd, %ebp
je 0x9a4b9
cmpl $0xc, %ebp
jne 0x9a491
movl 0xc(%rax), %eax
jmp 0x9a4c1
xorl %eax, %eax
jmp 0x9a4c1
movl 0x920(%rbx), %eax
addl %eax, %r15d
movl %r15d, 0x920(%rbx)
jmp 0x9a4c1
movl 0x91c(%rbx), %eax
addl %eax, %r15d
movl %r15d, 0x91c(%rbx)
jmp 0x9a4c1
movl 0x10(%rax), %eax
jmp 0x9a4c1
movl 0x14(%rax), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq