// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
movq %rsi, %r15
movq %rdi, %r12
movl $0x0, 0xc(%rsp)
movl %ecx, %ebx
leaq 0x8e19a(%rip), %r14     # 0xb7404
movl %ecx, 0x8(%rsp)
movq 0x20(%r15), %rax
cmpq 0x28(%r15), %rax
je 0x292b5
movl $0x1, %ebp
cmpl $0x5, %ecx
ja 0x29286
movl (%r14,%rbx,4), %ebp
movl 0x9c(%r15), %esi
movq %r12, %rdi
callq 0xa426
movq %rax, %r15
movq 0x20(%rax), %rax
cmpq 0x28(%r15), %rax
jne 0x29286
movl 0xc(%rsp), %eax
cmpl %eax, %ebp
cmoval %ebp, %eax
movl %eax, 0xc(%rsp)
movl 0x8(%rsp), %ecx
jmp 0x2926e
cmpl $0xc, 0xc(%r15)
jne 0x293c4
movq 0x70(%r15), %rax
cmpq 0x68(%r15), %rax
je 0x29415
movl $0x1, %ebp
xorl %r13d, %r13d
xorl %r14d, %r14d
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 %r13, %rdx
jbe 0x294bf
imulq $0xd0, %r13, %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 0xd402
movq 0x68(%r15), %rax
movl (%rax,%r13,4), %esi
movq %r12, %rdi
callq 0xa426
movq %r12, %rdi
movq %rax, %rsi
leaq 0x18(%rsp), %rdx
movl 0x8(%rsp), %ecx
callq 0x29242
movl %eax, %ebx
cmpl %eax, %r14d
cmoval %r14d, %ebx
leaq 0x20(%rsp), %rdi
callq 0xd5b0
movl %ebp, %r13d
movq 0x70(%r15), %rax
subq 0x68(%r15), %rax
sarq $0x2, %rax
incl %ebp
movl %ebx, %r14d
cmpq %r13, %rax
ja 0x292d9
jmp 0x29417
movq %r15, %rsi
callq 0x29170
movl 0x8(%rsp), %r8d
movl %eax, %ebx
movl 0x18(%r15), %eax
movl %r8d, %ecx
andl $-0x2, %ecx
cmpl $0x4, %ecx
jne 0x293eb
cmpl $0x1, %eax
je 0x29493
movl %eax, %edx
xorl $0x1, %edx
movl 0x14(%r15), %ecx
movl %ecx, %esi
xorl $0x1, %esi
orl %edx, %esi
je 0x29493
cmpl $0x4, %ecx
je 0x2940b
cmpl $0x2, %ecx
jne 0x29437
cmpl $0x1, %eax
jne 0x29437
imull %ecx, %ebx
jmp 0x29493
xorl %ebx, %ebx
movl 0x8(%rsp), %ecx
cmpl $0x5, %ecx
ja 0x29499
movl $0x35, %eax
btl %ecx, %eax
jae 0x29499
cmpl $0x11, %ebx
movl $0x10, %eax
cmovbl %eax, %ebx
jmp 0x29499
movl %ecx, %esi
xorl $0x3, %esi
orl %esi, %edx
je 0x29490
movq (%r13), %rdx
testb $0x20, %dl
sete %sil
cmpl $0x2, %eax
setb %dil
orb %sil, %dil
jne 0x2946f
cmpl $0x5, %r8d
ja 0x29468
movl $0x35, %eax
btl %r8d, %eax
jb 0x29490
cmpl $0x3, %ecx
jne 0x29410
jmp 0x29490
testb $0x10, %dl
sete %dl
cmpl $0x2, %ecx
setb %cl
orb %dl, %cl
jne 0x294b1
cmpl $0x5, %r8d
ja 0x294b5
movl $0x35, %ecx
btl %r8d, %ecx
jae 0x294b5
shll $0x2, %ebx
xorl %eax, %eax
testb %al, %al
jne 0x294d0
movl 0xc(%rsp), %eax
cmpl %eax, %ebx
cmoval %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
jmp 0x29495
cmpl $0x3, %eax
je 0x29490
imull %eax, %ebx
jmp 0x29493
leaq 0x8bc53(%rip), %rdi     # 0xb5119
movq %r13, %rsi
xorl %eax, %eax
callq 0x63d0
movl $0x10, %edi
callq 0x6140
movq %rax, %rbx
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x8e82c(%rip), %rsi     # 0xb7d19
leaq 0x8e85c(%rip), %rdx     # 0xb7d50
leaq 0x18(%rsp), %rdi
callq 0x7c64
movb $0x1, %bpl
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x6320
leaq 0xd3883(%rip), %rax     # 0xfcd98
addq $0x10, %rax
movq %rax, (%rbx)
xorl %ebp, %ebp
leaq 0xd385b(%rip), %rsi     # 0xfcd80
movq 0xd4aac(%rip), %rdx     # 0xfdfd8
movq %rbx, %rdi
callq 0x6470
movq %rax, %r14
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x29556
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x29556
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x29572
movq %rbx, %rdi
callq 0x6200
jmp 0x29572
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0xd5b0
movq %r14, %rdi
callq 0x64a0