// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::flattened_access_chain_vector[abi:cxx11](unsigned int, unsigned int const*, unsigned int, spirv_cross::SPIRType const&, unsigned int, unsigned int, bool)
std::string CompilerGLSL::flattened_access_chain_vector(uint32_t base, const uint32_t *indices, uint32_t count,
                                                        const SPIRType &target_type, uint32_t offset,
                                                        uint32_t matrix_stride, bool need_transpose)
{
	auto result = flattened_access_chain_offset(expression_type(base), indices, count, offset, 16);

	auto buffer_name = to_name(expression_type(base).self);

	if (need_transpose)
	{
		std::string expr;

		if (target_type.vecsize > 1)
		{
			expr += type_to_glsl_constructor(target_type);
			expr += "(";
		}

		for (uint32_t i = 0; i < target_type.vecsize; ++i)
		{
			if (i != 0)
				expr += ", ";

			uint32_t component_offset = result.second + i * matrix_stride;

			assert(component_offset % (target_type.width / 8) == 0);
			uint32_t index = component_offset / (target_type.width / 8);

			expr += buffer_name;
			expr += "[";
			expr += result.first; // this is a series of N1 * k1 + N2 * k2 + ... that is either empty or ends with a +
			expr += convert_to_string(index / 4);
			expr += "]";

			expr += vector_swizzle(1, index % 4);
		}

		if (target_type.vecsize > 1)
		{
			expr += ")";
		}

		return expr;
	}
	else
	{
		assert(result.second % (target_type.width / 8) == 0);
		uint32_t index = result.second / (target_type.width / 8);

		std::string expr;

		expr += buffer_name;
		expr += "[";
		expr += result.first; // this is a series of N1 * k1 + N2 * k2 + ... that is either empty or ends with a +
		expr += convert_to_string(index / 4);
		expr += "]";

		expr += vector_swizzle(target_type.vecsize, index % 4);

		return expr;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x138(%rbp)
movq %rdi, %rax
movq %rax, -0x130(%rbp)
movb 0x20(%rbp), %al
movl 0x18(%rbp), %r10d
movl 0x10(%rbp), %r10d
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
andb $0x1, %al
movb %al, -0x31(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x128(%rbp)
movl -0x14(%rbp), %esi
callq 0x1f760
movq -0x128(%rbp), %rsi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl -0x24(%rbp), %r8d
movl 0x10(%rbp), %r9d
movq %rsp, %rax
movq $0x0, 0x10(%rax)
movq $0x0, 0x8(%rax)
movl $0x10, (%rax)
leaq -0x60(%rbp), %rdi
callq 0x862e0
movq -0x128(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x1f760
movq %rax, -0x120(%rbp)
jmp 0x87e96
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rax
movl 0x8(%rax), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0x80(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0x87ebb
testb $0x1, -0x31(%rbp)
je 0x88185
movq -0x138(%rbp), %rdi
movb $0x0, -0x8d(%rbp)
callq 0x7530
movq -0x30(%rbp), %rax
cmpl $0x1, 0x14(%rax)
jbe 0x87f88
movq -0x128(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x72bf0
jmp 0x87eff
movq -0x138(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x7470
jmp 0x87f14
leaq -0xb0(%rbp), %rdi
callq 0x7708
movq -0x138(%rbp), %rdi
leaq 0xc53ff(%rip), %rsi     # 0x14d32d
callq 0x7340
jmp 0x87f35
jmp 0x87f88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x88343
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x88174
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x7708
jmp 0x88174
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x88128
cmpl $0x0, -0xb4(%rbp)
je 0x87fc5
movq -0x138(%rbp), %rdi
leaq 0xbc5d3(%rip), %rsi     # 0x14458f
callq 0x7340
jmp 0x87fc3
jmp 0x87fc5
movl -0x40(%rbp), %eax
movl -0xb4(%rbp), %ecx
imull 0x18(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
shrl $0x3, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x87ff5
jmp 0x88014
leaq 0xbbbea(%rip), %rdi     # 0x143be6
leaq 0xb9229(%rip), %rsi     # 0x14122c
movl $0x1619, %edx           # imm = 0x1619
leaq 0xbbc07(%rip), %rcx     # 0x143c16
callq 0x7260
movq -0x138(%rbp), %rdi
movl -0xb8(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
shrl $0x3, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0xbc(%rbp)
leaq -0x80(%rbp), %rsi
callq 0x7470
jmp 0x88040
movq -0x138(%rbp), %rdi
leaq 0xc535a(%rip), %rsi     # 0x14d3a8
callq 0x7340
jmp 0x88055
movq -0x138(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x7470
jmp 0x88067
movl -0xbc(%rbp), %eax
shrl $0x2, %eax
movl %eax, -0xe4(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe4(%rbp), %rsi
callq 0xa22d0
jmp 0x8808b
movq -0x138(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x7470
jmp 0x880a0
leaq -0xe0(%rbp), %rdi
callq 0x7708
movq -0x138(%rbp), %rdi
leaq 0xbffeb(%rip), %rsi     # 0x1480a5
callq 0x7340
jmp 0x880c1
movl -0xbc(%rbp), %esi
andl $0x3, %esi
movl $0x1, %edi
callq 0x88360
movq %rax, -0x140(%rbp)
jmp 0x880dd
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdi
callq 0x7340
jmp 0x880f2
jmp 0x880f4
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x87f92
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x7708
jmp 0x88174
movq -0x30(%rbp), %rax
cmpl $0x1, 0x14(%rax)
jbe 0x88149
movq -0x138(%rbp), %rdi
leaq 0xbcdb9(%rip), %rsi     # 0x144ef9
callq 0x7340
jmp 0x88147
jmp 0x88149
movb $0x1, -0x8d(%rbp)
movl $0x1, -0xe8(%rbp)
testb $0x1, -0x8d(%rbp)
jne 0x8816f
movq -0x138(%rbp), %rdi
callq 0x7708
jmp 0x88318
movq -0x138(%rbp), %rdi
callq 0x7708
jmp 0x8833a
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
shrl $0x3, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x0, %edx
jne 0x8819d
jmp 0x881bc
leaq 0xbbb09(%rip), %rdi     # 0x143cad
leaq 0xb9081(%rip), %rsi     # 0x14122c
movl $0x162e, %edx           # imm = 0x162E
leaq 0xbba5f(%rip), %rcx     # 0x143c16
callq 0x7260
movq -0x138(%rbp), %rdi
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x10(%rcx), %ecx
shrl $0x3, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, -0xec(%rbp)
movb $0x0, -0xed(%rbp)
callq 0x7530
movq -0x138(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x7470
jmp 0x881f8
movq -0x138(%rbp), %rdi
leaq 0xc51a2(%rip), %rsi     # 0x14d3a8
callq 0x7340
jmp 0x8820d
movq -0x138(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x7470
jmp 0x8821f
movl -0xec(%rbp), %eax
shrl $0x2, %eax
movl %eax, -0x114(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x114(%rbp), %rsi
callq 0xa22d0
jmp 0x88243
movq -0x138(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x7470
jmp 0x88258
leaq -0x110(%rbp), %rdi
callq 0x7708
movq -0x138(%rbp), %rdi
leaq 0xbfe33(%rip), %rsi     # 0x1480a5
callq 0x7340
jmp 0x88279
movq -0x30(%rbp), %rax
movl 0x14(%rax), %edi
movl -0xec(%rbp), %esi
andl $0x3, %esi
callq 0x88360
movq %rax, -0x148(%rbp)
jmp 0x88297
movq -0x148(%rbp), %rsi
movq -0x138(%rbp), %rdi
callq 0x7340
jmp 0x882ac
movb $0x1, -0xed(%rbp)
movl $0x1, -0xe8(%rbp)
testb $0x1, -0xed(%rbp)
jne 0x88308
jmp 0x882fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x8830a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x7708
jmp 0x8830a
movq -0x138(%rbp), %rdi
callq 0x7708
jmp 0x88318
movq -0x138(%rbp), %rdi
callq 0x7708
jmp 0x8833a
leaq -0x80(%rbp), %rdi
callq 0x7708
leaq -0x60(%rbp), %rdi
callq 0xa4730
movq -0x130(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x80(%rbp), %rdi
callq 0x7708
leaq -0x60(%rbp), %rdi
callq 0xa4730
movq -0x88(%rbp), %rdi
callq 0x7640
nopl (%rax,%rax)