// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x2e
popq %rsi
pushq $-0x1
popq %rdx
movq %rbx, %rdi
callq 0x6500
leaq 0x1(%rax), %rdx
cmpq $0x2, %rdx
jae 0x2ac29
xorl %ebp, %ebp
jmp 0x2ad7b
movq %rax, %r15
movq %rsp, %rdi
pushq $-0x1
popq %rcx
movq %rbx, %rsi
callq 0x62b0
cmpb $0x1, 0x620(%r14)
jne 0x2aca1
movq 0x8(%rsp), %rdx
cmpq $0x2, %rdx
jb 0x2ad71
addq $-0x2, %rdx
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
pushq $-0x1
popq %rcx
callq 0x62b0
leaq 0x68cc2(%rip), %rsi     # 0x93930
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x17431
movl %eax, %ebp
movq %r12, %rdi
callq 0x6548
testb %bpl, %bpl
je 0x2ad71
movq %rsp, %rdi
movq 0x8(%rdi), %rsi
addq $-0x2, %rsi
pushq $-0x1
popq %rdx
callq 0x6080
movq (%rsp), %rax
movq 0x8(%rsp), %rcx
xorl %edx, %edx
leaq 0x667f9(%rip), %rsi     # 0x914ac
cmpq %rdx, %rcx
je 0x2acd8
cmpq $0x4, %rdx
je 0x2ad71
movb (%rax,%rdx), %dil
leaq 0x1(%rdx), %r8
cmpb (%rdx,%rsi), %dil
movq %r8, %rdx
je 0x2acb3
jmp 0x2ad71
leaq -0x1(%r15), %rdx
pushq $0x2e
popq %rsi
movq %rbx, %rdi
callq 0x6500
cmpq $-0x1, %rax
je 0x2ad71
incq %rax
movq (%rbx), %rcx
movq %rax, %rdx
movq %rdx, %rsi
subq %r15, %rsi
jae 0x2ad38
movb (%rcx,%rdx), %dil
leal -0x7b(%rdi), %r8d
cmpb $-0x5, %r8b
jbe 0x2ad15
incq %rdx
jmp 0x2acfa
xorl %ebp, %ebp
cmpb $0x28, %dil
jne 0x2ad73
cmpb $0x0, 0x620(%r14)
je 0x2ad73
addq $0x3, %rsi
cmpq $0x1, %rsi
jne 0x2ad73
cmpb $0x29, 0x1(%rcx,%rdx)
jne 0x2ad71
subq %rax, %r15
movq 0x8(%rsp), %rsi
movb $0x1, %bpl
cmpq %rsi, %r15
jb 0x2ad73
addq %rax, %rsi
pushq $-0x1
popq %rdx
movq %rbx, %rdi
callq 0x6080
cmpb $0x1, 0x620(%r14)
jne 0x2ad73
leaq 0x68bc9(%rip), %rsi     # 0x93930
movq %rbx, %rdi
callq 0x64d0
jmp 0x2ad73
xorl %ebp, %ebp
movq %rsp, %rdi
callq 0x6548
movl %ebp, %eax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2ad8e
jmp 0x2ad8e
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x64b0
nop