// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::remove_duplicate_swizzle(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool CompilerGLSL::remove_duplicate_swizzle(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 prevpos = op.find_last_of('.', pos - 1);
	if (prevpos == string::npos)
		return false;

	prevpos++;

	// Make sure there are only swizzles here ...
	for (auto i = prevpos; i < pos; i++)
	{
		if (op[i] < 'w' || op[i] > 'z')
		{
			// If swizzles are foo.xyz() like in C++ backend for example, check for that.
			if (backend.swizzle_is_function && i + 2 == pos && op[i] == '(' && op[i + 1] == ')')
				break;
			return false;
		}
	}

	// If original swizzle is large enough, just carve out the components we need.
	// E.g. foobar.wyx.xy will turn into foobar.wy.
	if (pos - prevpos >= final_swiz.size())
	{
		op.erase(prevpos + final_swiz.size(), string::npos);

		// Add back the function call ...
		if (backend.swizzle_is_function)
			op += "()";
	}
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x18(%rbp), %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x76a0
movq %rax, -0x20(%rbp)
cmpq $-0x1, -0x20(%rbp)
je 0x70275
cmpq $0x0, -0x20(%rbp)
jne 0x7027e
movb $0x0, -0x1(%rbp)
jmp 0x7060e
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
addq $0x1, %rdx
leaq -0x40(%rbp), %rdi
movq $-0x1, %rcx
callq 0x73a0
movq -0x90(%rbp), %rax
testb $0x1, 0x620(%rax)
je 0x70395
leaq -0x40(%rbp), %rdi
callq 0x7290
cmpq $0x2, %rax
jae 0x702cd
movb $0x0, -0x1(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x705f8
leaq -0x40(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x7290
movq -0x98(%rbp), %rsi
movq %rax, %rdx
addq $-0x2, %rdx
leaq -0x68(%rbp), %rdi
movq $-0x1, %rcx
callq 0x73a0
jmp 0x702fd
leaq 0xd2b30(%rip), %rsi     # 0x142e34
leaq -0x68(%rbp), %rdi
callq 0x2f7c0
movb %al, -0x99(%rbp)
jmp 0x70315
leaq -0x68(%rbp), %rdi
callq 0x7708
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0x7032a
jmp 0x70383
leaq -0x40(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x7290
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
addq $-0x2, %rsi
movq $-0x1, %rdx
callq 0x70a0
jmp 0x70356
jmp 0x70393
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x70603
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x7708
jmp 0x70603
movb $0x0, -0x1(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x705f8
jmp 0x70395
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
movq %rax, -0xb0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x7290
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0x70416
cmpl $0x4, -0x78(%rbp)
jae 0x703f9
movl -0x78(%rbp), %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdi
callq 0x76d0
movq %rax, -0xb8(%rbp)
jmp 0x703db
movq -0xb8(%rbp), %rax
movsbl (%rax), %eax
movl -0x78(%rbp), %ecx
movl %ecx, %edx
leaq 0xd0573(%rip), %rcx     # 0x140964
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x70409
movb $0x0, -0x1(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x705f8
jmp 0x7040b
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x7039c
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rdx
subq $0x1, %rdx
movl $0x2e, %esi
callq 0x76a0
movq %rax, -0x80(%rbp)
cmpq $-0x1, -0x80(%rbp)
jne 0x70447
movb $0x0, -0x1(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x705f8
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x70562
movq -0x18(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x76d0
movq %rax, -0xc0(%rbp)
jmp 0x70488
movq -0xc0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x77, %eax
jl 0x704c3
movq -0x18(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x76d0
movq %rax, -0xc8(%rbp)
jmp 0x704b0
movq -0xc8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7a, %eax
jle 0x70549
movq -0x90(%rbp), %rax
testb $0x1, 0x620(%rax)
je 0x70539
movq -0x88(%rbp), %rax
addq $0x2, %rax
cmpq -0x20(%rbp), %rax
jne 0x70539
movq -0x18(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x76d0
movq %rax, -0xd0(%rbp)
jmp 0x704fd
movq -0xd0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x28, %eax
jne 0x70539
movq -0x18(%rbp), %rdi
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x76d0
movq %rax, -0xd8(%rbp)
jmp 0x70528
movq -0xd8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x29, %eax
jne 0x70539
jmp 0x70562
movb $0x0, -0x1(%rbp)
movl $0x1, -0x44(%rbp)
jmp 0x705f8
jmp 0x7054b
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x7045e
movq -0x20(%rbp), %rax
subq -0x80(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x7290
movq %rax, %rcx
movq -0xe0(%rbp), %rax
cmpq %rcx, %rax
jb 0x705ed
movq -0x18(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x7290
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdi
addq %rax, %rsi
movq $-0x1, %rdx
callq 0x70a0
jmp 0x705c7
movq -0x90(%rbp), %rax
testb $0x1, 0x620(%rax)
je 0x705eb
movq -0x18(%rbp), %rdi
leaq 0xd2852(%rip), %rsi     # 0x142e34
callq 0x7340
jmp 0x705e9
jmp 0x705eb
jmp 0x705ed
movb $0x1, -0x1(%rbp)
movl $0x1, -0x44(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x7708
jmp 0x7060e
leaq -0x40(%rbp), %rdi
callq 0x7708
jmp 0x7061c
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xf0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x7640
nopw %cs:(%rax,%rax)