// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::type_to_packed_size(spirv_cross::SPIRType const&, spirv_cross::Bitset const&, spirv_cross::BufferPackingStandard)
uint32_t CompilerGLSL::type_to_packed_size(const SPIRType &type, const Bitset &flags, BufferPackingStandard packing)
{
	if (!type.array.empty())
	{
		return to_array_size_literal(type, uint32_t(type.array.size()) - 1) *
		       type_to_packed_array_stride(type, flags, packing);
	}

	uint32_t size = 0;

	if (type.basetype == SPIRType::Struct)
	{
		uint32_t pad_alignment = 1;

		for (uint32_t i = 0; i < type.member_types.size(); i++)
		{
			auto member_flags = ir.meta[type.self].members.at(i).decoration_flags;
			auto &member_type = get<SPIRType>(type.member_types[i]);

			uint32_t packed_alignment = type_to_packed_alignment(member_type, member_flags, packing);
			uint32_t alignment = max(packed_alignment, pad_alignment);

			// The next member following a struct member is aligned to the base alignment of the struct that came before.
			// GL 4.5 spec, 7.6.2.2.
			if (member_type.basetype == SPIRType::Struct)
				pad_alignment = packed_alignment;
			else
				pad_alignment = 1;

			size = (size + alignment - 1) & ~(alignment - 1);
			size += type_to_packed_size(member_type, member_flags, packing);
		}
	}
	else
	{
		const uint32_t base_alignment = type_to_packed_base_size(type, packing);

		if (type.columns == 1)
			size = type.vecsize * base_alignment;

		if (flags.get(DecorationColMajor) && type.columns > 1)
		{
			if (packing_is_vec4_padded(packing))
				size = type.columns * 4 * base_alignment;
			else if (type.vecsize == 3)
				size = type.columns * 4 * base_alignment;
			else
				size = type.columns * type.vecsize * base_alignment;
		}

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

	return size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
callq 0x8690
testb $0x1, %al
jne 0x5dc66
movq -0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
callq 0x8650
movq -0xa8(%rbp), %rsi
movq -0x98(%rbp), %rdi
movl %eax, %edx
subl $0x1, %edx
callq 0x5df60
movq -0x98(%rbp), %rdi
movl %eax, -0x9c(%rbp)
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
callq 0x5db00
movl %eax, %ecx
movl -0x9c(%rbp), %eax
imull %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x5df49
movl $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0xc, 0xc(%rax)
jne 0x5de0f
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rdi
addq $0x68, %rdi
callq 0x8650
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0x5de0a
movq -0x98(%rbp), %rdi
addq $0x38, %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0xd0, %rdi
movl -0x30(%rbp), %eax
movl %eax, %esi
callq 0x9f820
movq %rax, %rsi
addq $0x60, %rsi
leaq -0x70(%rbp), %rdi
callq 0xef10
movq -0x18(%rbp), %rdi
addq $0x68, %rdi
movl -0x30(%rbp), %eax
movl %eax, %esi
callq 0x8570
movq -0x98(%rbp), %rdi
movl (%rax), %esi
callq 0xea90
movq %rax, -0xb8(%rbp)
jmp 0x5dd19
movq -0x98(%rbp), %rdi
movq -0xb8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rsi
movl -0x24(%rbp), %ecx
leaq -0x70(%rbp), %rdx
callq 0x5d5c0
movl %eax, -0xbc(%rbp)
jmp 0x5dd43
movl -0xbc(%rbp), %eax
movl %eax, -0x88(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x9f7e0
movq %rax, -0xc8(%rbp)
jmp 0x5dd68
movq -0xc8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x78(%rbp), %rax
cmpl $0xc, 0xc(%rax)
jne 0x5dda9
movl -0x88(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x5ddb0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xf250
jmp 0x5df55
movl $0x1, -0x2c(%rbp)
movq -0x98(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x8c(%rbp), %ecx
movl %ecx, %edx
movl %esi, %eax
leal -0x1(%rax,%rdx), %eax
negl %ecx
andl %ecx, %eax
movl %eax, -0x28(%rbp)
movq -0x78(%rbp), %rsi
movl -0x24(%rbp), %ecx
leaq -0x70(%rbp), %rdx
callq 0x5dbd0
movl %eax, -0xcc(%rbp)
jmp 0x5dde7
movl -0xcc(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xf250
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x5dc89
jmp 0x5df43
movq -0x98(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x5d490
movl %eax, -0x90(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x18(%rax)
jne 0x5de43
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
imull -0x90(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movl $0x5, %esi
callq 0xef50
testb $0x1, %al
jne 0x5de57
jmp 0x5dec2
movq -0x18(%rbp), %rax
cmpl $0x1, 0x18(%rax)
jbe 0x5dec2
movl -0x24(%rbp), %edi
callq 0x5da90
testb $0x1, %al
jne 0x5de6f
jmp 0x5de85
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
shll $0x2, %eax
imull -0x90(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x5dec0
movq -0x18(%rbp), %rax
cmpl $0x3, 0x14(%rax)
jne 0x5dea5
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
shll $0x2, %eax
imull -0x90(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x5debe
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x14(%rcx), %eax
imull -0x90(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x5dec0
jmp 0x5dec2
movq -0x20(%rbp), %rdi
movl $0x4, %esi
callq 0xef50
testb $0x1, %al
jne 0x5ded6
jmp 0x5df41
movq -0x18(%rbp), %rax
cmpl $0x1, 0x14(%rax)
jbe 0x5df41
movl -0x24(%rbp), %edi
callq 0x5da90
testb $0x1, %al
jne 0x5deee
jmp 0x5df04
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
shll $0x2, %eax
imull -0x90(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x5df3f
movq -0x18(%rbp), %rax
cmpl $0x3, 0x18(%rax)
jne 0x5df24
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
shll $0x2, %eax
imull -0x90(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x5df3d
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x18(%rcx), %eax
imull -0x90(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x5df3f
jmp 0x5df41
jmp 0x5df43
movl -0x28(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x7640
nop