// File: rossy[P]crossc/SPIRV-Cross/spirv_cross.cpp
// Function: spirv_cross::Compiler::fixup_type_alias()
void Compiler::fixup_type_alias()
{
	// Due to how some backends work, the "master" type of type_alias must be a block-like type if it exists.
	// FIXME: Multiple alias types which are both block-like will be awkward, for now, it's best to just drop the type
	// alias if the slave type is a block type.
	for (auto &id : ir.ids)
	{
		if (id.get_type() != TypeType)
			continue;

		auto &type = id.get<SPIRType>();

		if (type.type_alias && type_is_block_like(type))
		{
			// Become the master.
			for (auto &other_id : ir.ids)
			{
				if (other_id.get_type() != TypeType)
					continue;
				if (other_id.get_id() == type.self)
					continue;

				auto &other_type = other_id.get<SPIRType>();
				if (other_type.type_alias == type.type_alias)
					other_type.type_alias = type.self;
			}

			get<SPIRType>(type.type_alias).type_alias = id.get_id();
			type.type_alias = 0;
		}
	}

	for (auto &id : ir.ids)
	{
		if (id.get_type() != TypeType)
			continue;

		auto &type = id.get<SPIRType>();
		if (type.type_alias && type_is_block_like(type))
		{
			// This is not allowed, drop the type_alias.
			type.type_alias = 0;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
addq $0x8, %rax
addq $0x18, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0xf940
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0xf970
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0xf9a0
testb $0x1, %al
jne 0x22026
jmp 0x22181
leaq -0x18(%rbp), %rdi
callq 0xf9e0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0xfa00
cmpl $0x1, %eax
je 0x22046
jmp 0x22173
movq -0x28(%rbp), %rdi
callq 0xfa20
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x98(%rax)
je 0x22171
movq -0x88(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x21ec0
testb $0x1, %al
jne 0x2207d
jmp 0x22171
movq -0x88(%rbp), %rax
addq $0x8, %rax
addq $0x18, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0xf940
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0xf970
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xf9a0
testb $0x1, %al
jne 0x220bd
jmp 0x22132
leaq -0x40(%rbp), %rdi
callq 0xf9e0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0xfa00
cmpl $0x1, %eax
je 0x220da
jmp 0x22124
movq -0x50(%rbp), %rdi
callq 0x2f2b0
movq -0x30(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jne 0x220ee
jmp 0x22124
movq -0x50(%rbp), %rdi
callq 0xfa20
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl 0x98(%rax), %eax
movq -0x30(%rbp), %rcx
cmpl 0x98(%rcx), %eax
jne 0x22122
movq -0x30(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x98(%rax)
jmp 0x22124
leaq -0x40(%rbp), %rdi
callq 0xfbd0
jmp 0x220aa
movq -0x28(%rbp), %rdi
callq 0x2f2b0
movq -0x88(%rbp), %rdi
movl %eax, -0x8c(%rbp)
movq -0x30(%rbp), %rax
movl 0x98(%rax), %esi
callq 0xea90
movl -0x8c(%rbp), %ecx
movl %ecx, 0x98(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x98(%rax)
jmp 0x22173
leaq -0x18(%rbp), %rdi
callq 0xfbd0
jmp 0x22010
movq -0x88(%rbp), %rax
addq $0x8, %rax
addq $0x18, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0xf940
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
callq 0xf970
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xf9a0
testb $0x1, %al
jne 0x221c1
jmp 0x22229
leaq -0x68(%rbp), %rdi
callq 0xf9e0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
callq 0xfa00
cmpl $0x1, %eax
je 0x221de
jmp 0x2221e
movq -0x78(%rbp), %rdi
callq 0xfa20
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpl $0x0, 0x98(%rax)
je 0x2221c
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x21ec0
testb $0x1, %al
jne 0x2220e
jmp 0x2221c
movq -0x80(%rbp), %rax
movl $0x0, 0x98(%rax)
jmp 0x2221e
leaq -0x68(%rbp), %rdi
callq 0xfbd0
jmp 0x221ae
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)