// File: rossy[P]crossc/SPIRV-Cross/spirv_msl.cpp
// Function: spirv_cross::CompilerMSL::align_struct(spirv_cross::SPIRType&)
void CompilerMSL::align_struct(SPIRType &ib_type)
{
	uint32_t &ib_type_id = ib_type.self;

	// Sort the members of the interface structure by their offset.
	// They should already be sorted per SPIR-V spec anyway.
	MemberSorter member_sorter(ib_type, ir.meta[ib_type_id], MemberSorter::Offset);
	member_sorter.sort();

	uint32_t curr_offset;
	uint32_t mbr_cnt = uint32_t(ib_type.member_types.size());

	// Test the alignment of each member, and if a member should be closer to the previous
	// member than the default spacing expects, it is likely that the previous member is in
	// a packed format. If so, and the previous member is packable, pack it.
	// For example...this applies to any 3-element vector that is followed by a scalar.
	curr_offset = 0;
	for (uint32_t mbr_idx = 0; mbr_idx < mbr_cnt; mbr_idx++)
	{
		if (is_member_packable(ib_type, mbr_idx))
			set_member_decoration(ib_type_id, mbr_idx, DecorationCPacked);

		// Align current offset to the current member's default alignment.
		size_t align_mask = get_declared_struct_member_alignment(ib_type, mbr_idx) - 1;
		curr_offset = uint32_t((curr_offset + align_mask) & ~align_mask);

		// Fetch the member offset as declared in the SPIRV.
		uint32_t mbr_offset = get_member_decoration(ib_type_id, mbr_idx, DecorationOffset);
		if (mbr_offset > curr_offset)
		{
			// Since MSL and SPIR-V have slightly different struct member alignment and
			// size rules, we'll pad to standard C-packing rules. If the member is farther
			// away than C-packing, expects, add an inert padding member before the the member.
			MSLStructMemberKey key = get_struct_member_key(ib_type_id, mbr_idx);
			struct_member_padding[key] = mbr_offset - curr_offset;
		}

		// Increment the current offset to be positioned immediately after the current member.
		curr_offset = mbr_offset + uint32_t(get_declared_struct_member_size(ib_type, mbr_idx));
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x68(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, %esi
callq 0xead0
movq -0x60(%rbp), %rsi
movq %rax, %rdx
leaq -0x30(%rbp), %rdi
movl $0x2, %ecx
callq 0x10e6b0
leaq -0x30(%rbp), %rdi
callq 0xfa680
movq -0x10(%rbp), %rdi
addq $0x68, %rdi
callq 0x8650
movl %eax, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0xfaaa0
movq -0x68(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x3c(%rbp), %edx
callq 0xfaab0
testb $0x1, %al
jne 0xfa9cf
jmp 0xfa9e9
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
movl -0x3c(%rbp), %edx
movl $0xa, %ecx
xorl %r8d, %r8d
callq 0x22f50
movq -0x68(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x3c(%rbp), %edx
callq 0xfacc0
movq -0x68(%rbp), %rdi
subq $0x1, %rax
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
addq -0x48(%rbp), %rax
movq -0x48(%rbp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %esi
movl -0x3c(%rbp), %edx
movl $0x23, %ecx
callq 0x231b0
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jbe 0xfaa70
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
movl -0x3c(%rbp), %edx
callq 0xfaeb0
movq -0x68(%rbp), %rdi
movq %rax, -0x58(%rbp)
movl -0x4c(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x6c(%rbp)
addq $0x848, %rdi            # imm = 0x848
leaq -0x58(%rbp), %rsi
callq 0x1140d0
movl -0x6c(%rbp), %ecx
movl %ecx, (%rax)
movq -0x68(%rbp), %rdi
movl -0x4c(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rsi
movl -0x3c(%rbp), %edx
movq (%rdi), %rax
callq *0x30(%rax)
movq %rax, %rcx
movl -0x70(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xfa9ad
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)