// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_hlsl.cpp
// Function: spirv_cross::CompilerHLSL::read_access_chain[abi:cxx11](spirv_cross::SPIRAccessChain const&)
string CompilerHLSL::read_access_chain(const SPIRAccessChain &chain)
{
	auto &type = get<SPIRType>(chain.basetype);

	SPIRType target_type;
	target_type.basetype = SPIRType::UInt;
	target_type.vecsize = type.vecsize;
	target_type.columns = type.columns;

	if (type.basetype == SPIRType::Struct)
		SPIRV_CROSS_THROW("Reading structs from ByteAddressBuffer not yet supported.");

	if (type.width != 32)
		SPIRV_CROSS_THROW("Reading types other than 32-bit from ByteAddressBuffer not yet supported.");

	if (!type.array.empty())
		SPIRV_CROSS_THROW("Reading arrays from ByteAddressBuffer not yet supported.");

	string load_expr;

	// Load a vector or scalar.
	if (type.columns == 1 && !chain.row_major_matrix)
	{
		const char *load_op = nullptr;
		switch (type.vecsize)
		{
		case 1:
			load_op = "Load";
			break;
		case 2:
			load_op = "Load2";
			break;
		case 3:
			load_op = "Load3";
			break;
		case 4:
			load_op = "Load4";
			break;
		default:
			SPIRV_CROSS_THROW("Unknown vector size.");
		}

		load_expr = join(chain.base, ".", load_op, "(", chain.dynamic_index, chain.static_index, ")");
	}
	else if (type.columns == 1)
	{
		// Strided load since we are loading a column from a row-major matrix.
		if (type.vecsize > 1)
		{
			load_expr = type_to_glsl(target_type);
			load_expr += "(";
		}

		for (uint32_t r = 0; r < type.vecsize; r++)
		{
			load_expr +=
			    join(chain.base, ".Load(", chain.dynamic_index, chain.static_index + r * chain.matrix_stride, ")");
			if (r + 1 < type.vecsize)
				load_expr += ", ";
		}

		if (type.vecsize > 1)
			load_expr += ")";
	}
	else if (!chain.row_major_matrix)
	{
		// Load a matrix, column-major, the easy case.
		const char *load_op = nullptr;
		switch (type.vecsize)
		{
		case 1:
			load_op = "Load";
			break;
		case 2:
			load_op = "Load2";
			break;
		case 3:
			load_op = "Load3";
			break;
		case 4:
			load_op = "Load4";
			break;
		default:
			SPIRV_CROSS_THROW("Unknown vector size.");
		}

		// Note, this loading style in HLSL is *actually* row-major, but we always treat matrices as transposed in this backend,
		// so row-major is technically column-major ...
		load_expr = type_to_glsl(target_type);
		load_expr += "(";
		for (uint32_t c = 0; c < type.columns; c++)
		{
			load_expr += join(chain.base, ".", load_op, "(", chain.dynamic_index,
			                  chain.static_index + c * chain.matrix_stride, ")");
			if (c + 1 < type.columns)
				load_expr += ", ";
		}
		load_expr += ")";
	}
	else
	{
		// Pick out elements one by one ... Hopefully compilers are smart enough to recognize this pattern
		// considering HLSL is "row-major decl", but "column-major" memory layout (basically implicit transpose model, ugh) ...

		load_expr = type_to_glsl(target_type);
		load_expr += "(";
		for (uint32_t c = 0; c < type.columns; c++)
		{
			for (uint32_t r = 0; r < type.vecsize; r++)
			{
				load_expr += join(chain.base, ".Load(", chain.dynamic_index,
				                  chain.static_index + c * (type.width / 8) + r * chain.matrix_stride, ")");

				if ((r + 1 < type.vecsize) || (c + 1 < type.columns))
					load_expr += ", ";
			}
		}
		load_expr += ")";
	}

	auto bitcast_op = bitcast_glsl_op(type, target_type);
	if (!bitcast_op.empty())
		load_expr = join(bitcast_op, "(", load_expr, ")");

	return load_expr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %rbx
movq %rdi, %r14
movq %rdx, 0x18(%rsp)
movl 0xc(%rdx), %esi
movq %rbx, %rdi
callq 0x90a4
leaq 0x140(%rsp), %rdx
andl $0x0, -0xc8(%rdx)
leaq 0x8ed61(%rip), %rcx     # 0xe73f0
addq $0x10, %rcx
movq %rcx, -0xd0(%rdx)
andl $0x0, -0xc0(%rdx)
andq $0x0, -0x88(%rdx)
andl $0x0, -0x80(%rdx)
andq $0x0, -0x78(%rdx)
movq %rax, %r15
movb $0x0, -0x70(%rdx)
xorps %xmm0, %xmm0
movups %xmm0, -0xb0(%rdx)
movups %xmm0, -0xa0(%rdx)
andl $0x0, -0x90(%rdx)
movl $0x8, -0x6c(%rdx)
andq $0x0, -0x58(%rdx)
movups %xmm0, -0x68(%rdx)
andq $0x0, -0x38(%rdx)
movq %rdx, -0x30(%rdx)
movq $0x1, -0x28(%rdx)
movups %xmm0, -0x20(%rdx)
movl $0x3f800000, -0x10(%rdx) # imm = 0x3F800000
movups %xmm0, -0x8(%rdx)
movl $0x5, -0xc4(%rdx)
movl 0x14(%rax), %eax
movl %eax, -0xbc(%rdx)
movl 0x18(%r15), %ecx
movl %ecx, -0xb8(%rdx)
cmpl $0xc, 0xc(%r15)
je 0x58be3
cmpl $0x20, 0x10(%r15)
jne 0x58c31
movq 0x20(%r15), %rdx
cmpq 0x28(%r15), %rdx
jne 0x58c7f
leaq 0x10(%r14), %rdx
movq %rdx, (%r14)
andq $0x0, 0x8(%r14)
movb $0x0, 0x10(%r14)
movq 0x18(%rsp), %rdx
movb 0x64(%rdx), %dl
cmpl $0x1, %ecx
movq %r15, 0x10(%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x68(%rsp)
jne 0x5885c
testb %dl, %dl
je 0x58965
cmpl $0x2, %eax
jb 0x587c6
movq 0x68(%rsp), %rsi
movq (%rsi), %rax
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rdx
xorl %ecx, %ecx
callq *0x98(%rax)
leaq 0x20(%rsp), %rbx
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6320
movq %rbx, %rdi
callq 0x6548
leaq 0x4546b(%rip), %rsi     # 0x9dc29
movq %r14, %rdi
callq 0x64d0
movq 0x18(%rsp), %rax
leaq 0x18(%rax), %rbx
leaq 0x38(%rax), %r14
xorl %r15d, %r15d
leaq 0x3d218(%rip), %r13     # 0x959f5
leaq 0x20(%rsp), %rbp
leaq 0x48(%rsp), %r12
movq 0x10(%rsp), %rax
movl 0x14(%rax), %eax
cmpl %eax, %r15d
jae 0x589b0
movq 0x18(%rsp), %rcx
movl 0x60(%rcx), %eax
imull %r15d, %eax
addl 0x58(%rcx), %eax
movl %eax, 0x48(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x40b3b(%rip), %rdx     # 0x99353
movq %r14, %rcx
movq %r12, %r8
movq %r13, %r9
callq 0x62d43
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x64f0
movq %rbp, %rdi
callq 0x6548
incl %r15d
movq 0x10(%rsp), %rax
cmpl 0x14(%rax), %r15d
jae 0x587e7
movq 0x8(%rsp), %rdi
leaq 0x3c836(%rip), %rsi     # 0x9508b
callq 0x64d0
jmp 0x587e7
testb %dl, %dl
je 0x58989
movq (%rbx), %rax
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %rbx, %rsi
xorl %ecx, %ecx
callq *0x98(%rax)
leaq 0x20(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6320
movq %rbx, %rdi
callq 0x6548
leaq 0x4538e(%rip), %rsi     # 0x9dc29
movq %r14, %rdi
callq 0x64d0
movq 0x18(%rsp), %rax
leaq 0x18(%rax), %r13
leaq 0x38(%rax), %rbp
xorl %ebx, %ebx
leaq 0x20(%rsp), %r12
cmpl 0x18(%r15), %ebx
jae 0x589be
leal 0x1(%rbx), %r14d
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
cmpl 0x14(%rax), %r15d
jae 0x5895a
movl 0x10(%rax), %eax
shrl $0x3, %eax
imull %ebx, %eax
movq 0x18(%rsp), %rcx
addl 0x58(%rcx), %eax
movl 0x60(%rcx), %ecx
imull %r15d, %ecx
addl %eax, %ecx
movl %ecx, 0x48(%rsp)
movq %r12, %rdi
movq %r13, %rsi
leaq 0x40a51(%rip), %rdx     # 0x99353
movq %rbp, %rcx
leaq 0x48(%rsp), %r8
leaq 0x3d0e4(%rip), %r9      # 0x959f5
callq 0x62d43
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x64f0
movq %r12, %rdi
callq 0x6548
incl %r15d
movq 0x10(%rsp), %rax
cmpl 0x14(%rax), %r15d
jb 0x58944
movq 0x10(%rsp), %rax
cmpl 0x18(%rax), %r14d
jae 0x588c8
movq 0x8(%rsp), %rdi
leaq 0x3c73b(%rip), %rsi     # 0x9508b
callq 0x64d0
jmp 0x588c8
movl %r14d, %ebx
movq %rax, %r15
jmp 0x588b7
decl %eax
cmpl $0x3, %eax
ja 0x58ccd
leaq 0x3d891(%rip), %rcx     # 0x96208
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x4031b(%rip), %rax     # 0x98ca2
jmp 0x589ff
decl %eax
cmpl $0x3, %eax
ja 0x58d18
leaq 0x3d85d(%rip), %rcx     # 0x961f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x402f7(%rip), %rax     # 0x98ca2
jmp 0x58a62
cmpl $0x1, %eax
movq 0x10(%rsp), %r15
jbe 0x58b5a
leaq 0x3d030(%rip), %rsi     # 0x959f5
movq 0x8(%rsp), %rdi
callq 0x64d0
jmp 0x58b5a
leaq 0x40957(%rip), %rax     # 0x99332
jmp 0x589ff
leaq 0x4094e(%rip), %rax     # 0x99332
jmp 0x58a62
leaq 0x4094b(%rip), %rax     # 0x99338
jmp 0x589ff
leaq 0x40942(%rip), %rax     # 0x99338
jmp 0x58a62
leaq 0x4092d(%rip), %rax     # 0x9932c
movq %rax, 0x48(%rsp)
movq 0x18(%rsp), %r10
leaq 0x18(%r10), %rsi
leaq 0x38(%r10), %r9
addq $0x58, %r10
leaq 0x3cfd9(%rip), %rax     # 0x959f5
leaq 0x3ce06(%rip), %rdx     # 0x95829
leaq 0x451ff(%rip), %r8      # 0x9dc29
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rcx
pushq %rax
pushq %r10
callq 0x62cab
popq %rax
popq %rcx
leaq 0x20(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6320
movq %rbx, %rdi
callq 0x6548
jmp 0x58b5a
leaq 0x408ca(%rip), %rax     # 0x9932c
movq %rax, 0x48(%rsp)
movq (%rbx), %rax
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %rbx, %rsi
xorl %ecx, %ecx
callq *0x98(%rax)
leaq 0x20(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6320
movq %rbx, %rdi
callq 0x6548
leaq 0x4518b(%rip), %rsi     # 0x9dc29
movq %r14, %rdi
callq 0x64d0
movq 0x18(%rsp), %rax
leaq 0x18(%rax), %rbx
leaq 0x38(%rax), %r14
xorl %r13d, %r13d
leaq 0x44(%rsp), %r15
leaq 0x20(%rsp), %rbp
leaq 0x48(%rsp), %r12
movq 0x10(%rsp), %rax
cmpl 0x18(%rax), %r13d
jae 0x58b44
movq 0x18(%rsp), %rcx
movl 0x60(%rcx), %eax
imull %r13d, %eax
addl 0x58(%rcx), %eax
movl %eax, 0x44(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x3cd39(%rip), %rdx     # 0x95829
movq %r12, %rcx
leaq 0x4512f(%rip), %r8      # 0x9dc29
movq %r14, %r9
leaq 0x3cef1(%rip), %rax     # 0x959f5
pushq %rax
pushq %r15
callq 0x62dcf
popq %rax
popq %rcx
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x64f0
movq %rbp, %rdi
callq 0x6548
incl %r13d
movq 0x10(%rsp), %rax
cmpl 0x18(%rax), %r13d
jae 0x58ac5
movq 0x8(%rsp), %rdi
leaq 0x3c54e(%rip), %rsi     # 0x9508b
callq 0x64d0
jmp 0x58ac5
leaq 0x3ceaa(%rip), %rsi     # 0x959f5
movq 0x8(%rsp), %rdi
callq 0x64d0
movq 0x10(%rsp), %r15
movq 0x68(%rsp), %rsi
movq (%rsi), %rax
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rcx
movq %r15, %rdx
callq *0x168(%rax)
cmpq $0x0, 0x28(%rsp)
movq 0x8(%rsp), %r14
je 0x58bba
leaq 0x450a0(%rip), %rdx     # 0x9dc29
leaq 0x3ce65(%rip), %r8      # 0x959f5
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r14, %rcx
callq 0x62e67
leaq 0x48(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6320
movq %rbx, %rdi
callq 0x6548
leaq 0x20(%rsp), %rdi
callq 0x6548
leaq 0x70(%rsp), %rdi
callq 0x17a3e
movq %r14, %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %rbx
leaq 0x4067a(%rip), %rsi     # 0x9926f
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0x8e1a3(%rip), %rsi     # 0xe6dc0
movq 0x8f3bc(%rip), %rdx     # 0xe7fe0
movq %rbx, %rdi
callq 0x6490
jmp 0x58d61
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %rbx
leaq 0x40666(%rip), %rsi     # 0x992a9
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0x8e155(%rip), %rsi     # 0xe6dc0
movq 0x8f36e(%rip), %rdx     # 0xe7fe0
movq %rbx, %rdi
callq 0x6490
jmp 0x58d61
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %rbx
leaq 0x40662(%rip), %rsi     # 0x992f3
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0x8e107(%rip), %rsi     # 0xe6dc0
movq 0x8f320(%rip), %rdx     # 0xe7fe0
movq %rbx, %rdi
callq 0x6490
jmp 0x58d61
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %rbx
leaq 0x4065f(%rip), %rsi     # 0x9933e
leaq 0x20(%rsp), %rdi
leaq 0x44(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0x8e0b9(%rip), %rsi     # 0xe6dc0
movq 0x8f2d2(%rip), %rdx     # 0xe7fe0
movq %rbx, %rdi
callq 0x6490
jmp 0x58d61
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %rbx
leaq 0x40614(%rip), %rsi     # 0x9933e
leaq 0x20(%rsp), %rdi
leaq 0x44(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0x8e06e(%rip), %rsi     # 0xe6dc0
movq 0x8f287(%rip), %rdx     # 0xe7fe0
movq %rbx, %rdi
callq 0x6490
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
je 0x58e25
jmp 0x58d98
movq %rax, %r14
jmp 0x58d98
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
jne 0x58d98
jmp 0x58e25
movq %rax, %r14
movq %rbx, %rdi
callq 0x6200
jmp 0x58e25
jmp 0x58e22
jmp 0x58e22
jmp 0x58e22
jmp 0x58e22
jmp 0x58e22
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
je 0x58e2f
jmp 0x58df5
jmp 0x58dd9
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
je 0x58e2f
jmp 0x58df5
movq %rax, %r14
jmp 0x58df5
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
jne 0x58df5
jmp 0x58e2f
movq %rax, %r14
movq %rbx, %rdi
callq 0x6200
jmp 0x58e2f
jmp 0x58e13
jmp 0x58e22
jmp 0x58e22
jmp 0x58e22
jmp 0x58e22
jmp 0x58e13
jmp 0x58e22
jmp 0x58e13
jmp 0x58e22
jmp 0x58e22
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x6548
jmp 0x58e25
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x6548
leaq 0x70(%rsp), %rdi
callq 0x17a3e
movq %r14, %rdi
callq 0x64b0
nop