// File: /workspace/github_cpp_makefile_star2_O1/rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::optimize_read_modify_write(spirv_cross::SPIRType const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool CompilerGLSL::optimize_read_modify_write(const SPIRType &type, const string &lhs, const string &rhs)
{
	// Do this with strings because we have a very clear pattern we can check for and it avoids
	// adding lots of special cases to the code emission.
	if (rhs.size() < lhs.size() + 3)
		return false;

	// Do not optimize matrices. They are a bit awkward to reason about in general
	// (in which order does operation happen?), and it does not work on MSL anyways.
	if (type.vecsize > 1 && type.columns > 1)
		return false;

	auto index = rhs.find(lhs);
	if (index != 0)
		return false;

	// TODO: Shift operators, but it's not important for now.
	auto op = rhs.find_first_of("+-/*%|&^", lhs.size() + 1);
	if (op != lhs.size() + 1)
		return false;

	// Check that the op is followed by space. This excludes && and ||.
	if (rhs[op + 1] != ' ')
		return false;

	char bop = rhs[op];
	auto expr = rhs.substr(lhs.size() + 3);
	// Try to find increments and decrements. Makes it look neater as += 1, -= 1 is fairly rare to see in real code.
	// Find some common patterns which are equivalent.
	if ((bop == '+' || bop == '-') && (expr == "1" || expr == "uint(1)" || expr == "1u" || expr == "int(1u)"))
		statement(lhs, bop, bop, ";");
	else
		statement(lhs, " ", bop, "= ", expr, ";");
	return true;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r15
movq 0x8(%rdx), %rcx
leaq 0x3(%rcx), %rax
cmpq %rax, 0x8(%r15)
jb 0x44986
movq %rdx, %rbx
movq %rdi, %r14
cmpl $0x2, 0x14(%rsi)
jb 0x44998
cmpl $0x1, 0x18(%rsi)
jbe 0x44998
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq (%rbx), %rsi
xorl %r12d, %r12d
movq %r15, %rdi
xorl %edx, %edx
callq 0x6490
testq %rax, %rax
jne 0x44989
movq 0x8(%rbx), %rdx
incq %rdx
leaq 0x762ac(%rip), %rsi     # 0xbac67
movl $0x8, %ecx
movq %r15, %rdi
callq 0x63e0
movq 0x8(%rbx), %rdx
leaq 0x1(%rdx), %rcx
cmpq %rcx, %rax
jne 0x44986
movq (%r15), %rcx
cmpb $0x20, 0x1(%rcx,%rax)
jne 0x44986
movb (%rcx,%rax), %al
movb %al, 0x17(%rsp)
addq $0x3, %rdx
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x6290
movzbl 0x17(%rsp), %eax
cmpl $0x2d, %eax
je 0x44a0d
cmpl $0x2b, %eax
jne 0x44a61
leaq 0x76470(%rip), %rsi     # 0xbae84
leaq 0x18(%rsp), %rdi
callq 0x60a0
testl %eax, %eax
je 0x44a91
leaq 0x76247(%rip), %rsi     # 0xbac70
leaq 0x18(%rsp), %rdi
callq 0x60a0
testl %eax, %eax
je 0x44a91
leaq 0x7623a(%rip), %rsi     # 0xbac78
leaq 0x18(%rsp), %rdi
callq 0x60a0
testl %eax, %eax
je 0x44a91
leaq 0x76228(%rip), %rsi     # 0xbac7b
leaq 0x18(%rsp), %rdi
callq 0x60a0
testl %eax, %eax
je 0x44a91
leaq 0x7b081(%rip), %rax     # 0xbfae9
movq %rax, (%rsp)
leaq 0x70e3b(%rip), %rdx     # 0xb58ae
leaq 0x7afd9(%rip), %r8      # 0xbfa53
leaq 0x17(%rsp), %rcx
leaq 0x18(%rsp), %r9
movq %r14, %rdi
movq %rbx, %rsi
callq 0x564fc
jmp 0x44aab
leaq 0x7b051(%rip), %r8      # 0xbfae9
leaq 0x17(%rsp), %rcx
movq %r14, %rdi
movq %rbx, %rsi
movq %rcx, %rdx
callq 0x56364
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x44ac6
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x6260
movb $0x1, %r12b
jmp 0x44989
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x44aec
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0