// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::enclose_expression(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
string CompilerGLSL::enclose_expression(const string &expr)
{
	bool need_parens = false;

	// If the expression starts with a unary we need to enclose to deal with cases where we have back-to-back
	// unary expressions.
	if (!expr.empty())
	{
		auto c = expr.front();
		if (c == '-' || c == '+' || c == '!' || c == '~')
			need_parens = true;
	}

	if (!need_parens)
	{
		uint32_t paren_count = 0;
		for (auto c : expr)
		{
			if (c == '(' || c == '[')
				paren_count++;
			else if (c == ')' || c == ']')
			{
				assert(paren_count);
				paren_count--;
			}
			else if (c == ' ' && paren_count == 0)
			{
				need_parens = true;
				break;
			}
		}
		assert(paren_count == 0);
	}

	// If this expression contains any spaces which are not enclosed by parentheses,
	// we need to enclose it so we can treat the whole string as an expression.
	// This happens when two expressions have been part of a binary op earlier.
	if (need_parens)
		return join('(', expr, ')');
	else
		return expr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x50(%rbp)
movq %rdi, %rax
movq %rax, -0x48(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movq -0x18(%rbp), %rdi
callq 0x75f0
testb $0x1, %al
jne 0x6ffb8
movq -0x18(%rbp), %rdi
callq 0x7450
movb (%rax), %al
movb %al, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
cmpl $0x2d, %eax
je 0x6ffb2
movsbl -0x1a(%rbp), %eax
cmpl $0x2b, %eax
je 0x6ffb2
movsbl -0x1a(%rbp), %eax
cmpl $0x21, %eax
je 0x6ffb2
movsbl -0x1a(%rbp), %eax
cmpl $0x7e, %eax
jne 0x6ffb6
movb $0x1, -0x19(%rbp)
jmp 0x6ffb8
testb $0x1, -0x19(%rbp)
jne 0x700c2
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x7330
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x7680
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x9e140
testb $0x1, %al
jne 0x70001
jmp 0x70099
leaq -0x30(%rbp), %rdi
callq 0x9e180
movb (%rax), %al
movb %al, -0x39(%rbp)
movsbl -0x39(%rbp), %eax
cmpl $0x28, %eax
je 0x70021
movsbl -0x39(%rbp), %eax
cmpl $0x5b, %eax
jne 0x7002c
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x70089
movsbl -0x39(%rbp), %eax
cmpl $0x29, %eax
je 0x7003e
movsbl -0x39(%rbp), %eax
cmpl $0x5d, %eax
jne 0x70070
cmpl $0x0, -0x20(%rbp)
je 0x70046
jmp 0x70065
leaq 0xd2463(%rip), %rdi     # 0x1424b0
leaq 0xd11d8(%rip), %rsi     # 0x14122c
movl $0x949, %edx            # imm = 0x949
leaq 0xd245c(%rip), %rcx     # 0x1424bc
callq 0x7260
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x70087
movsbl -0x39(%rbp), %eax
cmpl $0x20, %eax
jne 0x70085
cmpl $0x0, -0x20(%rbp)
jne 0x70085
movb $0x1, -0x19(%rbp)
jmp 0x70099
jmp 0x70087
jmp 0x70089
jmp 0x7008b
leaq -0x30(%rbp), %rdi
callq 0x9e1a0
jmp 0x6ffeb
cmpl $0x0, -0x20(%rbp)
jne 0x700a1
jmp 0x700c0
leaq 0xd2459(%rip), %rdi     # 0x142501
leaq 0xd117d(%rip), %rsi     # 0x14122c
movl $0x952, %edx            # imm = 0x952
leaq 0xd2401(%rip), %rcx     # 0x1424bc
callq 0x7260
jmp 0x700c2
testb $0x1, -0x19(%rbp)
je 0x700e7
movq -0x50(%rbp), %rdi
movb $0x28, -0x3a(%rbp)
movq -0x18(%rbp), %rdx
movb $0x29, -0x3b(%rbp)
leaq -0x3a(%rbp), %rsi
leaq -0x3b(%rbp), %rcx
callq 0xa12f0
jmp 0x700f4
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x7170
movq -0x48(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop