// File: /workspace/github_cpp_makefile_star2_O3/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
movl %ecx, %ebp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r12
movq 0x20(%rsi), %rax
cmpq 0x28(%rsi), %rax
je 0x28c71
movl $0x1, %ebx
cmpl $0x5, %ebp
ja 0x28c53
movl %ebp, %eax
leaq 0x8d7a4(%rip), %rcx     # 0xb63f4
movl (%rcx,%rax,4), %ebx
movl 0x9c(%r15), %esi
movq %r12, %rdi
callq 0xa3ea
movq %rax, %r15
movq 0x20(%rax), %rax
cmpq 0x28(%r15), %rax
jne 0x28c53
jmp 0x28c73
xorl %ebx, %ebx
cmpl $0xc, 0xc(%r15)
jne 0x28d88
movl %ebp, 0xc(%rsp)
movl %ebx, 0x8(%rsp)
movq 0x70(%r15), %rax
cmpq 0x68(%r15), %rax
je 0x28dd4
movl $0x1, %ebp
xorl %ebx, %ebx
xorl %r13d, %r13d
movl 0x8(%r15), %eax
movq 0x38(%r12), %rcx
imulq $0x148, %rax, %rdx      # imm = 0x148
movq 0xd0(%rcx,%rdx), %rax
movq 0xd8(%rcx,%rdx), %rdx
subq %rax, %rdx
sarq $0x4, %rdx
movabsq $0x4ec4ec4ec4ec4ec5, %rcx # imm = 0x4EC4EC4EC4EC4EC5
imulq %rcx, %rdx
cmpq %rbx, %rdx
jbe 0x28e90
imulq $0xd0, %rbx, %rcx
leaq (%rax,%rcx), %rsi
addq $0x68, %rsi
movq -0x8(%rsi), %rax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x20(%rsp)
movq 0x8(%rsi), %rax
movq %rax, 0x28(%rsp)
movq %rcx, 0x30(%rsp)
movq 0x18(%rsi), %rax
movq %rax, 0x38(%rsp)
movups 0x20(%rsi), %xmm0
leaq 0x20(%rsp), %rdi
movups %xmm0, 0x20(%rdi)
movq %rcx, 0x50(%rsp)
movq %rdi, 0x10(%rsp)
leaq 0x10(%rsp), %rdx
callq 0xd3c2
movq 0x68(%r15), %rax
movl (%rax,%rbx,4), %esi
movq %r12, %rdi
callq 0xa3ea
movq %r12, %rdi
movq %rax, %rsi
leaq 0x18(%rsp), %rdx
movl 0xc(%rsp), %ecx
callq 0x28c1a
movl %eax, %r14d
cmpl %eax, %r13d
cmoval %r13d, %r14d
leaq 0x20(%rsp), %rdi
callq 0xd570
movl %ebp, %ebx
movq 0x70(%r15), %rax
subq 0x68(%r15), %rax
sarq $0x2, %rax
incl %ebp
movl %r14d, %r13d
cmpq %rbx, %rax
ja 0x28c9e
jmp 0x28dd7
movq %r15, %rsi
callq 0x28b4c
movl %eax, %r14d
movl 0x18(%r15), %eax
cmpl $0x1, %eax
jne 0x28db8
movl %ebp, %ecx
andl $-0x2, %ecx
cmpl $0x4, %ecx
je 0x28e6d
movl 0x14(%r15), %ecx
cmpl $0x1, %ecx
jne 0x28dbc
jmp 0x28e6d
movl 0x14(%r15), %ecx
cmpl $0x4, %ecx
je 0x28dc6
cmpl $0x2, %ecx
jne 0x28e09
cmpl $0x1, %eax
jne 0x28e01
imull %ecx, %r14d
jmp 0x28e6d
xorl %r14d, %r14d
movl 0xc(%rsp), %ecx
cmpl $0x5, %ecx
ja 0x28e69
movl $0x35, %eax
btl %ecx, %eax
movl 0x8(%rsp), %ebx
jae 0x28e6d
cmpl $0x11, %r14d
movl $0x10, %eax
cmovbl %eax, %r14d
jmp 0x28e6d
cmpl $0x3, %ecx
sete %dl
jmp 0x28e1d
movl %eax, %esi
xorl $0x1, %esi
cmpl $0x3, %ecx
sete %dl
movl %ecx, %edi
xorl $0x3, %edi
orl %esi, %edi
je 0x28e63
movq (%r13), %rsi
testb $0x20, %sil
sete %dil
cmpl $0x2, %eax
setb %r8b
orb %dil, %r8b
jne 0x28e4a
cmpl $0x5, %ebp
ja 0x28e44
movl $0x35, %eax
btl %ebp, %eax
jb 0x28e63
testb %dl, %dl
je 0x28dcb
jmp 0x28e63
cmpl $0x2, %ecx
jb 0x28ea1
andl $0x10, %esi
je 0x28ea1
cmpl $0x5, %ebp
ja 0x28e85
movl $0x35, %ecx
btl %ebp, %ecx
jae 0x28e85
shll $0x2, %r14d
jmp 0x28e6d
movl 0x8(%rsp), %ebx
cmpl %ebx, %r14d
cmoval %r14d, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, %eax
je 0x28e63
imull %eax, %r14d
jmp 0x28e6d
leaq 0x8b282(%rip), %rdi     # 0xb4119
movq %rbx, %rsi
xorl %eax, %eax
callq 0x63d0
movl $0x10, %edi
callq 0x6140
movq %rax, %rbx
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x8de4b(%rip), %rsi     # 0xb6d09
leaq 0x8de7b(%rip), %rdx     # 0xb6d40
leaq 0x18(%rsp), %rdi
callq 0x7be0
movb $0x1, %bpl
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x6320
leaq 0xd2ee2(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%rbx)
xorl %ebp, %ebp
leaq 0xd2eba(%rip), %rsi     # 0xfbdb0
movq 0xd40db(%rip), %rdx     # 0xfcfd8
movq %rbx, %rdi
callq 0x6470
movq %rax, %r14
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x28f1f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
jne 0x28f29
jmp 0x28f40
movq %rax, %r14
movq %rbx, %rdi
callq 0x6200
jmp 0x28f40
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0xd570
movq %r14, %rdi
callq 0x64a0