// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::to_expression[abi:cxx11](unsigned int)
string CompilerGLSL::to_expression(uint32_t id)
{
	auto itr = invalid_expressions.find(id);
	if (itr != end(invalid_expressions))
		handle_invalid_expression(id);

	if (ir.ids[id].get_type() == TypeExpression)
	{
		// We might have a more complex chain of dependencies.
		// A possible scenario is that we
		//
		// %1 = OpLoad
		// %2 = OpDoSomething %1 %1. here %2 will have a dependency on %1.
		// %3 = OpDoSomethingAgain %2 %2. Here %3 will lose the link to %1 since we don't propagate the dependencies like that.
		// OpStore %1 %foo // Here we can invalidate %1, and hence all expressions which depend on %1. Only %2 will know since it's part of invalid_expressions.
		// %4 = OpDoSomethingAnotherTime %3 %3 // If we forward all expressions we will see %1 expression after store, not before.
		//
		// However, we can propagate up a list of depended expressions when we used %2, so we can check if %2 is invalid when reading %3 after the store,
		// and see that we should not forward reads of the original variable.
		auto &expr = get<SPIRExpression>(id);
		for (uint32_t dep : expr.expression_dependencies)
			if (invalid_expressions.find(dep) != end(invalid_expressions))
				handle_invalid_expression(dep);
	}

	track_expression_read(id);

	switch (ir.ids[id].get_type())
	{
	case TypeExpression:
	{
		auto &e = get<SPIRExpression>(id);
		if (e.base_expression)
			return to_enclosed_expression(e.base_expression) + e.expression;
		else if (e.need_transpose)
		{
			bool is_packed = has_decoration(id, DecorationCPacked);
			return convert_row_major_matrix(e.expression, get<SPIRType>(e.expression_type), is_packed);
		}
		else
		{
			if (force_recompile)
			{
				// During first compilation phase, certain expression patterns can trigger exponential growth of memory.
				// Avoid this by returning dummy expressions during this phase.
				// Do not use empty expressions here, because those are sentinels for other cases.
				return "_";
			}
			else
				return e.expression;
		}
	}

	case TypeConstant:
	{
		auto &c = get<SPIRConstant>(id);
		auto &type = get<SPIRType>(c.constant_type);

		// WorkGroupSize may be a constant.
		auto &dec = ir.meta[c.self].decoration;
		if (dec.builtin)
			return builtin_to_glsl(dec.builtin_type, StorageClassGeneric);
		else if (c.specialization && options.vulkan_semantics)
			return to_name(id);
		else if (c.is_used_as_lut)
			return to_name(id);
		else if (type.basetype == SPIRType::Struct && !backend.can_declare_struct_inline)
			return to_name(id);
		else if (!type.array.empty() && !backend.can_declare_arrays_inline)
			return to_name(id);
		else
			return constant_expression(c);
	}

	case TypeConstantOp:
		if (options.vulkan_semantics)
			return to_name(id);
		else
			return constant_op_expression(get<SPIRConstantOp>(id));

	case TypeVariable:
	{
		auto &var = get<SPIRVariable>(id);
		// If we try to use a loop variable before the loop header, we have to redirect it to the static expression,
		// the variable has not been declared yet.
		if (var.statically_assigned || (var.loop_variable && !var.loop_variable_enable))
			return to_expression(var.static_expression);
		else if (var.deferred_declaration)
		{
			var.deferred_declaration = false;
			return variable_decl(var);
		}
		else if (flattened_structs.count(id))
		{
			return load_flattened_struct(var);
		}
		else
		{
			auto &dec = ir.meta[var.self].decoration;
			if (dec.builtin)
				return builtin_to_glsl(dec.builtin_type, var.storage);
			else
				return to_name(id);
		}
	}

	case TypeCombinedImageSampler:
		// This type should never be taken the expression of directly.
		// The intention is that texture sampling functions will extract the image and samplers
		// separately and take their expressions as needed.
		// GLSL does not use this type because OpSampledImage immediately creates a combined image sampler
		// expression ala sampler2D(texture, sampler).
		SPIRV_CROSS_THROW("Combined image samplers have no default expression representation.");

	case TypeAccessChain:
		// We cannot express this type. They only have meaning in other OpAccessChains, OpStore or OpLoad.
		SPIRV_CROSS_THROW("Access chains have no default expression representation.");

	default:
		return to_name(id);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsp, %rsi
movl %edx, (%rsi)
leaq 0x198(%r14), %r15
movq %r15, %rdi
callq 0x1c722
testq %rax, %rax
je 0x2ba28
movl (%rsp), %esi
movq %r14, %rdi
callq 0x2be24
movl (%rsp), %esi
movq 0x20(%r14), %rax
movq %rsi, %rcx
shlq $0x4, %rcx
cmpl $0x9, 0x8(%rax,%rcx)
jne 0x2ba84
movq %r14, %rdi
callq 0x1704a
movq 0x40(%rax), %r13
movq 0x48(%rax), %rbp
leaq 0x8(%rsp), %r12
cmpq %rbp, %r13
je 0x2ba81
movl (%r13), %eax
movl %eax, 0x8(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x1c722
testq %rax, %rax
je 0x2ba7b
movl 0x8(%rsp), %esi
movq %r14, %rdi
callq 0x2be24
addq $0x4, %r13
jmp 0x2ba52
movl (%rsp), %esi
movq %r14, %rdi
callq 0x2c0f4
movl (%rsp), %edx
movq 0x20(%r14), %rax
movq %rdx, %rcx
shlq $0x4, %rcx
movl 0x8(%rax,%rcx), %eax
addl $-0x2, %eax
cmpl $0xa, %eax
ja 0x2bb84
leaq 0x64c8f(%rip), %rcx     # 0x90740
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
movl %edx, %esi
callq 0x9c0e
movq %rax, %r15
cmpb $0x0, 0x39(%rax)
je 0x2bb92
movl 0x3c(%r15), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2b9f0
jmp 0x2bc71
movq %r14, %rdi
movl %edx, %esi
callq 0x1704a
movq %rax, %r15
movl 0xc(%rax), %edx
testl %edx, %edx
je 0x2bc17
leaq 0x8(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x2beca
addq $0x10, %r15
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x42dd2
leaq 0x8(%rsp), %rdi
jmp 0x2bc6c
movq %r14, %rdi
movl %edx, %esi
callq 0x17bce
movq %rax, %r15
movl 0xc(%rax), %esi
movq %r14, %rdi
callq 0x90a4
movl 0x8(%r15), %edx
movq 0x38(%r14), %rcx
imulq $0x148, %rdx, %rdx      # imm = 0x148
cmpb $0x1, 0xcc(%rcx,%rdx)
jne 0x2bbc7
addq %rdx, %rcx
movl 0xa0(%rcx), %edx
movq (%r14), %rax
pushq $0x8
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq *0xa0(%rax)
jmp 0x2bc71
cmpb $0x1, 0x43e(%r14)
jne 0x2bbfd
movq (%r14), %rax
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x2bbf8
cmpb $0x1, 0x64(%r15)
jne 0x2bba4
cmpb $0x0, 0x65(%r15)
je 0x2bad1
cmpb $0x1, 0x59(%r15)
jne 0x2bca3
movb $0x0, 0x59(%r15)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2619e
jmp 0x2bc71
cmpb $0x1, 0x108(%r15)
jne 0x2bbdb
cmpb $0x1, 0x43e(%r14)
je 0x2bbe9
cmpb $0x1, 0x10a(%r15)
jne 0x2bcc7
movl (%rsp), %edx
movq (%r14), %rax
pushq $0x1
popq %rcx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x38(%rax)
jmp 0x2bc71
movq %r14, %rdi
movl %edx, %esi
callq 0x42df2
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x265a8
jmp 0x2bc71
cmpb $0x1, 0x39(%r15)
jne 0x2bc83
movl (%rsp), %esi
pushq $0xa
popq %rdx
movq %r14, %rdi
callq 0x103d2
movl %eax, %ebp
movq %r15, %rsi
addq $0x10, %rsi
leaq 0x28(%rsp), %rdi
callq 0x63c0
movl 0x30(%r15), %esi
movq %r14, %rdi
callq 0x90a4
movq (%r14), %r9
movzbl %bpl, %r8d
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
callq *0x118(%r9)
leaq 0x28(%rsp), %rdi
callq 0x6548
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x1, 0x1d0(%r14)
jne 0x2bd06
leaq 0x6d2b3(%rip), %rsi     # 0x98f47
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x6100
jmp 0x2bc71
leaq 0x6b0(%r14), %rdi
movq %rsp, %rsi
callq 0x1aeea
testq %rax, %rax
je 0x2bd1a
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2c144
jmp 0x2bc71
cmpl $0xc, 0xc(%rax)
jne 0x2bcdb
cmpb $0x0, 0x626(%r14)
je 0x2bbe9
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
je 0x2bcf3
cmpb $0x0, 0x627(%r14)
je 0x2bbe9
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x271d4
jmp 0x2bc71
addq $0x10, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x63c0
jmp 0x2bc71
movl 0x8(%r15), %ecx
movq 0x38(%r14), %rax
imulq $0x148, %rcx, %rcx      # imm = 0x148
cmpb $0x1, 0xcc(%rax,%rcx)
jne 0x2bbe9
addq %rcx, %rax
movl 0xa0(%rax), %edx
movl 0x10(%r15), %ecx
movq (%r14), %rax
jmp 0x2bb69
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %r14
leaq 0x672f3(%rip), %rsi     # 0x93051
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0xbb03a(%rip), %rsi     # 0xe6dc0
movq 0xbc253(%rip), %rdx     # 0xe7fe0
movq %r14, %rdi
callq 0x6490
jmp 0x2bde0
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %r14
leaq 0x67265(%rip), %rsi     # 0x9300e
leaq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0xbafef(%rip), %rsi     # 0xe6dc0
movq 0xbc208(%rip), %rdx     # 0xe7fe0
movq %r14, %rdi
callq 0x6490
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x2be17
jmp 0x2bdee
jmp 0x2be02
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
jne 0x2be05
jmp 0x2be1c
movq %rax, %rbx
movq %r14, %rdi
callq 0x6200
jmp 0x2be1c
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x64b0