// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
movl $0x2e, %esi
movq $-0x1, %rdx
callq 0x64f0
leaq 0x1(%rax), %rdx
cmpq $0x2, %rdx
jae 0x32d6f
xorl %ebp, %ebp
jmp 0x32f08
movq %rax, %r15
movq %rsp, %rdi
movq %rbx, %rsi
movq $-0x1, %rcx
callq 0x6290
cmpb $0x1, 0x620(%r14)
jne 0x32e0d
movq 0x8(%rsp), %rdx
cmpq $0x2, %rdx
jb 0x32eeb
addq $-0x2, %rdx
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
movq $-0x1, %rcx
callq 0x6290
leaq 0x85b94(%rip), %rsi     # 0xb8950
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x60a0
movl %eax, %ebp
movq (%r12), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x32de6
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
testl %ebp, %ebp
jne 0x32eeb
movq 0x8(%rsp), %rcx
movq %rcx, %rdx
subq $0x2, %rdx
jb 0x32f17
movq %rdx, 0x8(%rsp)
movq (%rsp), %rax
movb $0x0, (%rax,%rdx)
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x32e44
movq (%rsp), %rcx
xorl %edx, %edx
leaq 0x836a8(%rip), %rsi     # 0xb64cc
cmpq $0x4, %rdx
je 0x32eeb
movb (%rcx,%rdx), %dil
cmpb (%rdx,%rsi), %dil
jne 0x32eeb
incq %rdx
cmpq %rdx, %rax
jne 0x32e24
leaq -0x1(%r15), %r12
movq %rbx, %rdi
movl $0x2e, %esi
movq %r12, %rdx
callq 0x64f0
cmpq $-0x1, %rax
je 0x32eeb
leaq 0x1(%rax), %rcx
movq %r15, %rsi
subq %rcx, %rsi
jbe 0x32eac
movq (%rbx), %rdx
movb 0x1(%rdx,%rax), %dil
leal -0x7b(%rdi), %r8d
cmpb $-0x5, %r8b
jbe 0x32e8a
incq %rax
cmpq %rax, %r12
jne 0x32e71
jmp 0x32eac
xorl %ebp, %ebp
cmpb $0x28, %dil
jne 0x32eed
cmpb $0x0, 0x620(%r14)
je 0x32eed
addq $-0x3, %r15
cmpq %rax, %r15
jne 0x32eed
cmpb $0x29, 0x2(%rdx,%rax)
jne 0x32eeb
movq 0x8(%rsp), %rdx
movb $0x1, %bpl
cmpq %rdx, %rsi
jb 0x32eed
addq %rcx, %rdx
movq 0x8(%rbx), %rcx
cmpq %rdx, %rcx
jb 0x32f2c
movq %rdx, 0x8(%rbx)
movq (%rbx), %rax
movb $0x0, (%rax,%rdx)
cmpb $0x1, 0x620(%r14)
jne 0x32eed
leaq 0x85a6f(%rip), %rsi     # 0xb8950
movq %rbx, %rdi
callq 0x64e0
jmp 0x32eed
xorl %ebp, %ebp
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x32f08
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
movl %ebp, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x87f51(%rip), %rdi     # 0xbae6f
leaq 0x87f81(%rip), %rsi     # 0xbaea6
xorl %eax, %eax
callq 0x63d0
leaq 0x87f3c(%rip), %rdi     # 0xbae6f
leaq 0x87f6c(%rip), %rsi     # 0xbaea6
xorl %eax, %eax
callq 0x63d0
jmp 0x32f45
jmp 0x32f45
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x32f63
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0
nop