// File: /workspace/github_cpp_makefile_star2_O3/rossy[P]crossc/SPIRV-Cross/spirv_hlsl.cpp
// Function: spirv_cross::CompilerHLSL::to_resource_binding[abi:cxx11](spirv_cross::SPIRVariable const&)
string CompilerHLSL::to_resource_binding(const SPIRVariable &var)
{
	// TODO: Basic implementation, might need special consideration for RW/RO structured buffers,
	// RW/RO images, and so on.

	if (!has_decoration(var.self, DecorationBinding))
		return "";

	const auto &type = get<SPIRType>(var.basetype);
	char space = '\0';

	switch (type.basetype)
	{
	case SPIRType::SampledImage:
		space = 't'; // SRV
		break;

	case SPIRType::Image:
		if (type.image.sampled == 2 && type.image.dim != DimSubpassData)
			space = 'u'; // UAV
		else
			space = 't'; // SRV
		break;

	case SPIRType::Sampler:
		space = 's';
		break;

	case SPIRType::Struct:
	{
		auto storage = type.storage;
		if (storage == StorageClassUniform)
		{
			if (has_decoration(type.self, DecorationBufferBlock))
			{
				Bitset flags = ir.get_buffer_block_flags(var);
				bool is_readonly = flags.get(DecorationNonWritable);
				space = is_readonly ? 't' : 'u'; // UAV
			}
			else if (has_decoration(type.self, DecorationBlock))
				space = 'b'; // Constant buffers
		}
		else if (storage == StorageClassPushConstant)
			space = 'b'; // Constant buffers
		else if (storage == StorageClassStorageBuffer)
			space = 'u'; // UAV

		break;
	}
	default:
		break;
	}

	if (!space)
		return "";

	return to_resource_register(space, get_decoration(var.self, DecorationBinding),
	                            get_decoration(var.self, DecorationDescriptorSet));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movl 0x8(%rdx), %esi
movq %r14, %rdi
movl $0x21, %edx
callq 0x12974
testb %al, %al
je 0x68611
movl 0xc(%r15), %esi
movq %r14, %rdi
callq 0xa3ea
movq %rax, %r12
movl 0xc(%rax), %eax
addl $-0xc, %eax
cmpl $0x3, %eax
ja 0x68611
leaq 0x52bc2(%rip), %rcx     # 0xbb0e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x64(%r12), %eax
cmpl $0xc, %eax
je 0x685f6
movb $0x62, %r13b
cmpl $0x9, %eax
je 0x685bc
cmpl $0x2, %eax
jne 0x68611
movl 0x8(%r12), %esi
movq %r14, %rdi
movl $0x3, %edx
callq 0x12974
testb %al, %al
je 0x685fb
leaq 0x8(%r14), %rsi
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
callq 0x2460e
btl $0x18, (%r12)
setae %r13b
orb $0x74, %r13b
leaq 0x10(%rsp), %rdi
callq 0xd570
jmp 0x685bc
movb $0x74, %r13b
jmp 0x685bc
movb $0x73, %r13b
jmp 0x685bc
cmpl $0x2, 0x8c(%r12)
setne %al
cmpl $0x6, 0x84(%r12)
sete %r13b
orb %al, %r13b
xorb $0x75, %r13b
movl 0x8(%r15), %esi
movq %r14, %rdi
movl $0x21, %edx
callq 0x14e6e
movl %eax, %ebp
movl 0x8(%r15), %esi
movq %r14, %rdi
movl $0x22, %edx
callq 0x14e6e
movzbl %r13b, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movl %eax, %r8d
callq 0x68bf6
jmp 0x6862a
movb $0x75, %r13b
jmp 0x685bc
movl 0x8(%r12), %esi
movq %r14, %rdi
movl $0x2, %edx
callq 0x12974
testb %al, %al
jne 0x685bc
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x4c290(%rip), %rdx     # 0xb48af
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x7be0
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq