// File: /workspace/github_cpp_makefile_star2_O1/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 0x33467
xorl %ebp, %ebp
jmp 0x33600
movq %rax, %r15
movq %rsp, %rdi
movq %rbx, %rsi
movq $-0x1, %rcx
callq 0x6290
cmpb $0x1, 0x620(%r14)
jne 0x33505
movq 0x8(%rsp), %rdx
cmpq $0x2, %rdx
jb 0x335e3
addq $-0x2, %rdx
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
movq $-0x1, %rcx
callq 0x6290
leaq 0x864ac(%rip), %rsi     # 0xb9960
leaq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x60a0
movl %eax, %ebp
movq (%r12), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x334de
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
testl %ebp, %ebp
jne 0x335e3
movq 0x8(%rsp), %rcx
movq %rcx, %rdx
subq $0x2, %rdx
jb 0x3360f
movq %rdx, 0x8(%rsp)
movq (%rsp), %rax
movb $0x0, (%rax,%rdx)
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x3353c
movq (%rsp), %rcx
xorl %edx, %edx
leaq 0x83fc0(%rip), %rsi     # 0xb74dc
cmpq $0x4, %rdx
je 0x335e3
movb (%rcx,%rdx), %dil
cmpb (%rdx,%rsi), %dil
jne 0x335e3
incq %rdx
cmpq %rdx, %rax
jne 0x3351c
leaq -0x1(%r15), %r12
movq %rbx, %rdi
movl $0x2e, %esi
movq %r12, %rdx
callq 0x64f0
cmpq $-0x1, %rax
je 0x335e3
leaq 0x1(%rax), %rcx
movq %r15, %rsi
subq %rcx, %rsi
jbe 0x335a4
movq (%rbx), %rdx
movb 0x1(%rdx,%rax), %dil
leal -0x7b(%rdi), %r8d
cmpb $-0x5, %r8b
jbe 0x33582
incq %rax
cmpq %rax, %r12
jne 0x33569
jmp 0x335a4
xorl %ebp, %ebp
cmpb $0x28, %dil
jne 0x335e5
cmpb $0x0, 0x620(%r14)
je 0x335e5
addq $-0x3, %r15
cmpq %rax, %r15
jne 0x335e5
cmpb $0x29, 0x2(%rdx,%rax)
jne 0x335e3
movq 0x8(%rsp), %rdx
movb $0x1, %bpl
cmpq %rdx, %rsi
jb 0x335e5
addq %rcx, %rdx
movq 0x8(%rbx), %rcx
cmpq %rdx, %rcx
jb 0x33624
movq %rdx, 0x8(%rbx)
movq (%rbx), %rax
movb $0x0, (%rax,%rdx)
cmpb $0x1, 0x620(%r14)
jne 0x335e5
leaq 0x86387(%rip), %rsi     # 0xb9960
movq %rbx, %rdi
callq 0x64e0
jmp 0x335e5
xorl %ebp, %ebp
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x33600
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 0x88869(%rip), %rdi     # 0xbbe7f
leaq 0x88899(%rip), %rsi     # 0xbbeb6
xorl %eax, %eax
callq 0x63d0
leaq 0x88854(%rip), %rdi     # 0xbbe7f
leaq 0x88884(%rip), %rsi     # 0xbbeb6
xorl %eax, %eax
callq 0x63d0
jmp 0x3363d
jmp 0x3363d
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3365b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0
nop