// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::remove_unity_swizzle(unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool CompilerGLSL::remove_unity_swizzle(uint32_t base, string &op)
{
	auto pos = op.find_last_of('.');
	if (pos == string::npos || pos == 0)
		return false;

	string final_swiz = op.substr(pos + 1, string::npos);

	if (backend.swizzle_is_function)
	{
		if (final_swiz.size() < 2)
			return false;

		if (final_swiz.substr(final_swiz.size() - 2, string::npos) == "()")
			final_swiz.erase(final_swiz.size() - 2, string::npos);
		else
			return false;
	}

	// Check if final swizzle is of form .x, .xy, .xyz, .xyzw or similar.
	// If so, and previous swizzle is of same length,
	// we can drop the final swizzle altogether.
	for (uint32_t i = 0; i < final_swiz.size(); i++)
	{
		static const char expected[] = { 'x', 'y', 'z', 'w' };
		if (i >= 4 || final_swiz[i] != expected[i])
			return false;
	}

	auto &type = expression_type(base);

	// Sanity checking ...
	assert(type.columns == 1 && type.array.empty());

	if (type.vecsize == final_swiz.size())
		op.erase(pos, string::npos);
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x76a0
movq %rax, -0x28(%rbp)
cmpq $-0x1, -0x28(%rbp)
je 0x887f8
cmpq $0x0, -0x28(%rbp)
jne 0x88801
movb $0x0, -0x1(%rbp)
jmp 0x88a79
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
addq $0x1, %rdx
leaq -0x48(%rbp), %rdi
movq $-0x1, %rcx
callq 0x73a0
movq -0x90(%rbp), %rax
testb $0x1, 0x620(%rax)
je 0x88918
leaq -0x48(%rbp), %rdi
callq 0x7290
cmpq $0x2, %rax
jae 0x88850
movb $0x0, -0x1(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x88a63
leaq -0x48(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x7290
movq -0x98(%rbp), %rsi
movq %rax, %rdx
addq $-0x2, %rdx
leaq -0x70(%rbp), %rdi
movq $-0x1, %rcx
callq 0x73a0
jmp 0x88880
leaq 0xba5ad(%rip), %rsi     # 0x142e34
leaq -0x70(%rbp), %rdi
callq 0x2f7c0
movb %al, -0x99(%rbp)
jmp 0x88898
leaq -0x70(%rbp), %rdi
callq 0x7708
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x888ad
jmp 0x88906
leaq -0x48(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x7290
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
addq $-0x2, %rsi
movq $-0x1, %rdx
callq 0x70a0
jmp 0x888d9
jmp 0x88916
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x88a6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x7708
jmp 0x88a6e
movb $0x0, -0x1(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x88a63
jmp 0x88918
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
movq %rax, -0xb0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x7290
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0x88999
cmpl $0x4, -0x80(%rbp)
jae 0x8897c
movl -0x80(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x76d0
movq %rax, -0xb8(%rbp)
jmp 0x8895e
movq -0xb8(%rbp), %rax
movsbl (%rax), %eax
movl -0x80(%rbp), %ecx
movl %ecx, %edx
leaq 0xb7ff4(%rip), %rcx     # 0x140968
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x8898c
movb $0x0, -0x1(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x88a63
jmp 0x8898e
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x8891f
movq -0x90(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x1f760
movq %rax, -0xc0(%rbp)
jmp 0x889b1
movq -0xc0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rcx
xorl %eax, %eax
cmpl $0x1, 0x18(%rcx)
movb %al, -0xc1(%rbp)
jne 0x889ea
movq -0x88(%rbp), %rdi
addq $0x20, %rdi
callq 0x8690
movb %al, -0xc1(%rbp)
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x889f6
jmp 0x889f8
jmp 0x88a17
leaq 0xbb633(%rip), %rdi     # 0x144032
leaq 0xb8826(%rip), %rsi     # 0x14122c
movl $0x179f, %edx           # imm = 0x179F
leaq 0xbb648(%rip), %rcx     # 0x14405a
callq 0x7260
movq -0x88(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0xd0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x7290
movq %rax, %rcx
movq -0xd0(%rbp), %rax
cmpq %rcx, %rax
jne 0x88a58
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq $-0x1, %rdx
callq 0x70a0
jmp 0x88a56
jmp 0x88a58
movb $0x1, -0x1(%rbp)
movl $0x1, -0x4c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x7708
jmp 0x88a79
leaq -0x48(%rbp), %rdi
callq 0x7708
jmp 0x88a87
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xd0, %rsp
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x7640