// File: /workspace/github_cpp_makefile_star2_O2/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 0x12fa4
movl 0x8(%r14), %esi
cmpl $0x9, 0x10(%r14)
je 0x7a1e0
movq 0x38(%rbx), %rdx
imulq $0x148, %rsi, %rdi      # imm = 0x148
movl 0xac(%rdx,%rdi), %ecx
movl 0xb0(%rdx,%rdi), %edx
jmp 0x7a1e5
xorl %edx, %edx
pushq $-0x1
popq %rcx
movq 0x8f8(%rbx), %rdi
movq 0x900(%rbx), %r8
movl 0xb8(%rax), %r9d
cmpq %r8, %rdi
je 0x7a21b
movq (%rdi), %rax
cmpl %r9d, (%rax)
jne 0x7a215
cmpl %ecx, 0x4(%rax)
jne 0x7a215
cmpl %edx, 0x8(%rax)
je 0x7a2d7
addq $0x8, %rdi
jmp 0x7a1fa
pushq $0x21
popq %rdx
movq %rbx, %rdi
callq 0x103d2
testb %al, %al
je 0x7a247
movl 0x8(%r14), %esi
pushq $0x21
popq %rdx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12174
movl %ebp, 0x4(%rsp)
movl 0xc(%r14), %esi
movq %rbx, %rdi
callq 0x90a4
movq %rax, %r14
movq %rax, %r15
addq $0x38, %r15
pushq $0x1
popq %r13
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x28(%r14), %rax
subq 0x20(%r14), %rax
shrq $0x2, %rax
movl %eax, %eax
cmpq %rax, %r12
jae 0x7a2b2
movq %r15, %rdi
movq %r12, %rsi
callq 0x820ee
movq %rax, %rcx
movq 0x20(%r14), %rax
addq %rbp, %rax
testq %rdx, (%rcx)
jne 0x7a2a5
movl (%rax), %esi
movq %rbx, %rdi
callq 0x17bce
addq $0x10, %rax
imull (%rax), %r13d
incq %r12
addq $0x4, %rbp
jmp 0x7a26a
movl 0x4(%rsp), %eax
cmpl $0xc, %eax
je 0x7a305
cmpl $0xd, %eax
je 0x7a2f3
cmpl $0xf, %eax
jne 0x7a2ef
movl 0x924(%rbx), %eax
addl %eax, %r13d
movl %r13d, 0x924(%rbx)
jmp 0x7a31f
movb $0x1, 0x18(%rax)
cmpl $0xf, %ebp
je 0x7a31c
cmpl $0xd, %ebp
je 0x7a317
cmpl $0xc, %ebp
jne 0x7a2ef
movl 0xc(%rax), %eax
jmp 0x7a31f
xorl %eax, %eax
jmp 0x7a31f
movl 0x920(%rbx), %eax
addl %eax, %r13d
movl %r13d, 0x920(%rbx)
jmp 0x7a31f
movl 0x91c(%rbx), %eax
addl %eax, %r13d
movl %r13d, 0x91c(%rbx)
jmp 0x7a31f
movl 0x10(%rax), %eax
jmp 0x7a31f
movl 0x14(%rax), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq