// File: rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::get_declared_struct_member_size(spirv_cross::SPIRType const&, unsigned int) const
size_t Compiler::get_declared_struct_member_size(const SPIRType &struct_type, uint32_t index) const
{
	if (struct_type.member_types.empty())
		SPIRV_CROSS_THROW("Declared struct in block cannot be empty.");

	auto &flags = get_member_decoration_bitset(struct_type.self, index);
	auto &type = get<SPIRType>(struct_type.member_types[index]);

	switch (type.basetype)
	{
	case SPIRType::Unknown:
	case SPIRType::Void:
	case SPIRType::Boolean: // Bools are purely logical, and cannot be used for externally visible types.
	case SPIRType::AtomicCounter:
	case SPIRType::Image:
	case SPIRType::SampledImage:
	case SPIRType::Sampler:
		SPIRV_CROSS_THROW("Querying size for object with opaque size.");

	default:
		break;
	}

	if (!type.array.empty())
	{
		// For arrays, we can use ArrayStride to get an easy check.
		bool array_size_literal = type.array_size_literal.back();
		uint32_t array_size = array_size_literal ? type.array.back() : get<SPIRConstant>(type.array.back()).scalar();
		return type_struct_member_array_stride(struct_type, index) * array_size;
	}
	else if (type.basetype == SPIRType::Struct)
	{
		return get_declared_struct_size(type);
	}
	else
	{
		unsigned vecsize = type.vecsize;
		unsigned columns = type.columns;

		// Vectors.
		if (columns == 1)
		{
			size_t component_size = type.width / 8;
			return vecsize * component_size;
		}
		else
		{
			uint32_t matrix_stride = type_struct_member_matrix_stride(struct_type, index);

			// Per SPIR-V spec, matrices must be tightly packed and aligned up for vec3 accesses.
			if (flags.get(DecorationRowMajor))
				return matrix_stride * vecsize;
			else if (flags.get(DecorationColMajor))
				return matrix_stride * columns;
			else
				SPIRV_CROSS_THROW("Either row-major or column-major must be declared for matrices.");
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rdi
addq $0x68, %rdi
callq 0x8690
testb $0x1, %al
jne 0x246c7
jmp 0x2477f
movb $0x1, -0x55(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0xe8(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x7650
movq -0xe0(%rbp), %rdx
leaq 0x11af5a(%rip), %rsi    # 0x13f654
leaq -0x40(%rbp), %rdi
callq 0x7520
jmp 0x24705
movq -0xe8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x9c50
jmp 0x24717
movq -0xe8(%rbp), %rdi
movb $0x0, -0x55(%rbp)
leaq 0x1896af(%rip), %rsi    # 0x1addd8
leaq -0x1aaa0(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x24b2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2475d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x7708
leaq -0x41(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x55(%rbp)
jne 0x2476e
jmp 0x2477a
movq -0xe8(%rbp), %rdi
callq 0x72c0
jmp 0x24b24
movq -0xd8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x1c(%rbp), %edx
callq 0x23220
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
addq $0x68, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x8570
movq -0xd8(%rbp), %rdi
movl (%rax), %esi
callq 0x2e6b0
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xec(%rbp)
subl $0x3, %eax
jb 0x247f2
jmp 0x247d1
movl -0xec(%rbp), %eax
subl $0x8, %eax
je 0x247f2
jmp 0x247de
movl -0xec(%rbp), %eax
addl $-0xd, %eax
subl $0x2, %eax
ja 0x248c2
jmp 0x247f2
movb $0x1, -0x8a(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x100(%rbp)
leaq -0x89(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x7650
movq -0xf8(%rbp), %rdx
leaq 0x11ae53(%rip), %rsi    # 0x13f67e
leaq -0x88(%rbp), %rdi
callq 0x7520
jmp 0x24839
movq -0x100(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x9c50
jmp 0x2484e
movq -0x100(%rbp), %rdi
movb $0x0, -0x8a(%rbp)
leaq 0x189575(%rip), %rsi    # 0x1addd8
leaq -0x1abda(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x24b2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2489a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x7708
leaq -0x89(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x8a(%rbp)
jne 0x248b1
jmp 0x248bd
movq -0x100(%rbp), %rdi
callq 0x72c0
jmp 0x24b24
jmp 0x248c4
movq -0x68(%rbp), %rdi
addq $0x20, %rdi
callq 0x8690
testb $0x1, %al
jne 0x2496c
movq -0x68(%rbp), %rdi
addq $0x38, %rdi
callq 0x2fe70
andb $0x1, %al
movb %al, -0x8b(%rbp)
testb $0x1, -0x8b(%rbp)
je 0x2490e
movq -0x68(%rbp), %rdi
addq $0x20, %rdi
callq 0x2fe30
movl (%rax), %eax
movl %eax, -0x104(%rbp)
jmp 0x2493b
movq -0x68(%rbp), %rdi
addq $0x20, %rdi
callq 0x2fe30
movq -0xd8(%rbp), %rdi
movl (%rax), %esi
callq 0x2e950
movq %rax, %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x2f560
movl %eax, -0x104(%rbp)
movq -0xd8(%rbp), %rdi
movl -0x104(%rbp), %eax
movl %eax, -0x90(%rbp)
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x24170
imull -0x90(%rbp), %eax
movl %eax, %eax
movq %rax, -0x8(%rbp)
jmp 0x24b17
movq -0x68(%rbp), %rax
cmpl $0xc, 0xc(%rax)
jne 0x2498f
movq -0xd8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x243b0
movq %rax, -0x8(%rbp)
jmp 0x24b17
movq -0x68(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x94(%rbp)
movq -0x68(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x98(%rbp)
cmpl $0x1, -0x98(%rbp)
jne 0x249dc
movq -0x68(%rbp), %rax
movl 0x10(%rax), %eax
shrl $0x3, %eax
movl %eax, %eax
movq %rax, -0xa0(%rbp)
movl -0x94(%rbp), %eax
imulq -0xa0(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x24b17
movq -0xd8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x24290
movl %eax, -0xa4(%rbp)
movq -0x60(%rbp), %rdi
movl $0x4, %esi
callq 0xef50
testb $0x1, %al
jne 0x24a09
jmp 0x24a21
movl -0xa4(%rbp), %eax
imull -0x94(%rbp), %eax
movl %eax, %eax
movq %rax, -0x8(%rbp)
jmp 0x24b17
movq -0x60(%rbp), %rdi
movl $0x5, %esi
callq 0xef50
testb $0x1, %al
jne 0x24a35
jmp 0x24a4d
movl -0xa4(%rbp), %eax
imull -0x98(%rbp), %eax
movl %eax, %eax
movq %rax, -0x8(%rbp)
jmp 0x24b17
movb $0x1, -0xca(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x118(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x7650
movq -0x110(%rbp), %rdx
leaq 0x11ac23(%rip), %rsi    # 0x13f6a9
leaq -0xc8(%rbp), %rdi
callq 0x7520
jmp 0x24a94
movq -0x118(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x9c50
jmp 0x24aa9
movq -0x118(%rbp), %rdi
movb $0x0, -0xca(%rbp)
leaq 0x18931a(%rip), %rsi    # 0x1addd8
leaq -0x1ae35(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x24b2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x24af2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x7708
leaq -0xc9(%rbp), %rdi
callq 0x73d0
testb $0x1, -0xca(%rbp)
jne 0x24b09
jmp 0x24b15
movq -0x118(%rbp), %rdi
callq 0x72c0
jmp 0x24b24
movq -0x8(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x7640
nopl (%rax)