// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::type_to_packed_alignment(spirv_cross::SPIRType const&, spirv_cross::Bitset const&, spirv_cross::BufferPackingStandard)
uint32_t CompilerGLSL::type_to_packed_alignment(const SPIRType &type, const Bitset &flags,
                                                BufferPackingStandard packing)
{
	if (!type.array.empty())
	{
		uint32_t minimum_alignment = 1;
		if (packing_is_vec4_padded(packing))
			minimum_alignment = 16;

		auto *tmp = &get<SPIRType>(type.parent_type);
		while (!tmp->array.empty())
			tmp = &get<SPIRType>(tmp->parent_type);

		// Get the alignment of the base type, then maybe round up.
		return max(minimum_alignment, type_to_packed_alignment(*tmp, flags, packing));
	}

	if (type.basetype == SPIRType::Struct)
	{
		// Rule 9. Structs alignments are maximum alignment of its members.
		uint32_t alignment = 0;
		for (uint32_t i = 0; i < type.member_types.size(); i++)
		{
			auto member_flags = ir.meta[type.self].members.at(i).decoration_flags;
			alignment =
			    max(alignment, type_to_packed_alignment(get<SPIRType>(type.member_types[i]), member_flags, packing));
		}

		// In std140, struct alignment is rounded up to 16.
		if (packing_is_vec4_padded(packing))
			alignment = max(alignment, 16u);

		return alignment;
	}
	else
	{
		const uint32_t base_alignment = type_to_packed_base_size(type, packing);

		// Vectors are *not* aligned in HLSL, but there's an extra rule where vectors cannot straddle
		// a vec4, this is handled outside since that part knows our current offset.
		if (type.columns == 1 && packing_is_hlsl(packing))
			return base_alignment;

		// From 7.6.2.2 in GL 4.5 core spec.
		// Rule 1
		if (type.vecsize == 1 && type.columns == 1)
			return base_alignment;

		// Rule 2
		if ((type.vecsize == 2 || type.vecsize == 4) && type.columns == 1)
			return type.vecsize * base_alignment;

		// Rule 3
		if (type.vecsize == 3 && type.columns == 1)
			return 4 * base_alignment;

		// Rule 4 implied. Alignment does not change in std430.

		// Rule 5. Column-major matrices are stored as arrays of
		// vectors.
		if (flags.get(DecorationColMajor) && type.columns > 1)
		{
			if (packing_is_vec4_padded(packing))
				return 4 * base_alignment;
			else if (type.vecsize == 3)
				return 4 * base_alignment;
			else
				return type.vecsize * base_alignment;
		}

		// Rule 6 implied.

		// Rule 7.
		if (flags.get(DecorationRowMajor) && type.vecsize > 1)
		{
			if (packing_is_vec4_padded(packing))
				return 4 * base_alignment;
			else if (type.columns == 3)
				return 4 * base_alignment;
			else
				return type.columns * base_alignment;
		}

		// Rule 8 implied.
	}

	SPIRV_CROSS_THROW("Did not find suitable rule for type. Bogus decorations?");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r12
movq 0x20(%rsi), %rdx
movq 0x28(%rsi), %rax
movl %ecx, %r14d
movl %ecx, %ecx
movq %rcx, 0x8(%rsp)
xorl %ebx, %ebx
pushq $0x1
popq %rbp
cmpq %rax, %rdx
je 0x235ca
movl %ebp, %r13d
cmpl $0x5, %r14d
ja 0x235a2
movq 0x8(%rsp), %rax
leaq 0x6de36(%rip), %rcx     # 0x913d4
movl (%rcx,%rax,4), %r13d
movl 0x9c(%r15), %esi
movq %r12, %rdi
callq 0x90a4
movq %rax, %r15
movq 0x20(%rax), %rax
cmpq 0x28(%r15), %rax
jne 0x235a2
cmpl %ebx, %r13d
cmoval %r13d, %ebx
movq %rax, %rdx
jmp 0x23584
cmpl $0xc, 0xc(%r15)
jne 0x2366a
xorl %ebp, %ebp
leaq 0x18(%rsp), %rdx
xorl %r13d, %r13d
movl %r14d, 0x8(%rsp)
movl %r13d, %r13d
movq 0x70(%r15), %rax
subq 0x68(%r15), %rax
sarq $0x2, %rax
cmpq %r13, %rax
jbe 0x2369a
movl 0x8(%r15), %eax
movq 0x38(%r12), %rcx
imulq $0x148, %rax, %rax      # imm = 0x148
movq %rdx, %r14
leaq (%rcx,%rax), %rdi
addq $0xd0, %rdi
movq %r13, %rsi
callq 0x41c9e
leaq 0x60(%rax), %rsi
movq %r14, %rdi
callq 0x934a
movq 0x68(%r15), %rax
movl (%rax,%r13,4), %esi
movq %r12, %rdi
callq 0x90a4
movq %r12, %rdi
movq %rax, %rsi
movq %r14, %rdx
movl 0x8(%rsp), %ecx
callq 0x23554
cmpl %eax, %ebp
cmovbel %eax, %ebp
leaq 0x20(%rsp), %rdi
callq 0xb51c
incl %r13d
movq %r14, %rdx
jmp 0x235e4
movq %r15, %rsi
callq 0x234b2
movl %eax, %ebp
movl 0x18(%r15), %eax
cmpl $0x1, %eax
jne 0x236c1
movl %r14d, %ecx
andl $-0x2, %ecx
cmpl $0x4, %ecx
je 0x23742
movl 0x14(%r15), %ecx
cmpl $0x1, %ecx
jne 0x236c5
jmp 0x23742
movl 0x8(%rsp), %ecx
cmpl $0x5, %ecx
ja 0x23742
pushq $0x35
popq %rax
btl %ecx, %eax
jae 0x23742
cmpl $0x11, %ebp
pushq $0x10
popq %rax
cmovbl %eax, %ebp
jmp 0x23742
movl 0x14(%r15), %ecx
cmpl $0x4, %ecx
je 0x236cf
cmpl $0x2, %ecx
jne 0x236e1
cmpl $0x1, %eax
jne 0x236d9
imull %ecx, %ebp
jmp 0x23742
cmpl $0x3, %ecx
sete %dl
jmp 0x236f5
movl %eax, %esi
xorl $0x1, %esi
cmpl $0x3, %ecx
sete %dl
movl %ecx, %edi
xorl $0x3, %edi
orl %esi, %edi
je 0x2373f
movq 0x10(%rsp), %rsi
movq (%rsi), %rsi
testb $0x20, %sil
sete %dil
cmpl $0x2, %eax
setb %r8b
orb %dil, %r8b
jne 0x23726
cmpl $0x5, %r14d
ja 0x23720
pushq $0x35
popq %rax
btl %r14d, %eax
jb 0x2373f
testb %dl, %dl
je 0x236d4
jmp 0x2373f
cmpl $0x2, %ecx
jb 0x23762
andl $0x10, %esi
je 0x23762
cmpl $0x5, %r14d
ja 0x23758
pushq $0x35
popq %rcx
btl %r14d, %ecx
jae 0x23758
shll $0x2, %ebp
cmpl %ebx, %ebp
cmoval %ebp, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %eax
je 0x2373f
imull %eax, %ebp
jmp 0x23742
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %rbx
leaq 0x6e575(%rip), %rsi     # 0x91ce9
leaq 0x18(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0xc3624(%rip), %rsi     # 0xe6dc0
movq 0xc483d(%rip), %rdx     # 0xe7fe0
movq %rbx, %rdi
callq 0x6490
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
jne 0x237c2
jmp 0x237d9
movq %rax, %r14
movq %rbx, %rdi
callq 0x6200
jmp 0x237d9
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0xb51c
movq %r14, %rdi
callq 0x64b0
nop