// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x40, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movl 0x8(%rdx), %esi
movq %r14, %rdi
movl $0x21, %edx
callq 0x1299a
testb %al, %al
je 0x68ec9
movl 0xc(%r15), %esi
movq %r14, %rdi
callq 0xa426
movq %rax, %r12
movl 0xc(%rax), %eax
addl $-0xc, %eax
cmpl $0x3, %eax
ja 0x68e5b
leaq 0x53304(%rip), %rcx     # 0xbc0f4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x64(%r12), %eax
cmpl $0xc, %eax
je 0x68ef7
cmpl $0x9, %eax
je 0x68ef2
cmpl $0x2, %eax
jne 0x68e5b
movl 0x8(%r12), %esi
movq %r14, %rdi
movl $0x3, %edx
callq 0x1299a
testb %al, %al
je 0x68efc
leaq 0x8(%r14), %rsi
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rdx
callq 0x24ca0
btl $0x18, (%r12)
setae %r12b
orb $0x74, %r12b
leaq 0x8(%rsp), %rdi
callq 0xd5b0
jmp 0x68e8a
xorl %r12d, %r12d
jmp 0x68e8a
movb $0x74, %r12b
jmp 0x68e8a
movb $0x73, %r12b
jmp 0x68e8a
cmpl $0x2, 0x8c(%r12)
setne %al
cmpl $0x6, 0x84(%r12)
sete %r12b
orb %al, %r12b
xorb $0x75, %r12b
testb %r12b, %r12b
je 0x68ec9
movl 0x8(%r15), %esi
movq %r14, %rdi
movl $0x21, %edx
callq 0x14ff6
movl %eax, %ebp
movl 0x8(%r15), %esi
movq %r14, %rdi
movl $0x22, %edx
callq 0x14ff6
movzbl %r12b, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %ecx
movl %eax, %r8d
callq 0x694da
jmp 0x68ee2
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
leaq 0x4c9d8(%rip), %rdx     # 0xb58af
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x7c64
movq %rbx, %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movb $0x62, %r12b
jmp 0x68e8a
movb $0x75, %r12b
jmp 0x68e8a
movl 0x8(%r12), %esi
movq %r14, %rdi
movl $0x2, %edx
callq 0x1299a
xorl %ecx, %ecx
testb %al, %al
movl $0x62, %r12d
cmovel %ecx, %r12d
jmp 0x68e8a
nop