// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
leaq 0x4(%rsp), %rsi
movl %edx, (%rsi)
leaq 0x198(%rbx), %r15
movq %r15, %rdi
callq 0x21122
testq %rax, %rax
je 0x33fe1
movl 0x4(%rsp), %eax
leaq 0x14(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x228(%rbx), %rdi
leaq 0x18(%rsp), %rdx
movq %rdi, (%rdx)
callq 0x1f510
movb $0x1, 0x1d0(%rbx)
movl 0x4(%rsp), %esi
movq %rbx, %r13
movq 0x20(%rbx), %rax
movq %rsi, %rcx
shlq $0x4, %rcx
cmpl $0x9, 0x8(%rax,%rcx)
jne 0x34062
movq %r13, %rdi
callq 0x1b42a
movq 0x40(%rax), %r14
movq 0x48(%rax), %rbp
cmpq %rbp, %r14
je 0x34062
leaq 0x228(%r13), %r12
leaq 0x10(%rsp), %rbx
movl (%r14), %eax
movl %eax, 0x10(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21122
testq %rax, %rax
je 0x34059
movl 0x10(%rsp), %eax
movl %eax, 0x14(%rsp)
movq %r12, 0x18(%rsp)
movq %r12, %rdi
leaq 0x14(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x1f510
movb $0x1, 0x1d0(%r13)
addq $0x4, %r14
cmpq %rbp, %r14
jne 0x3401b
movl 0x4(%rsp), %esi
movq %r13, %rdi
callq 0x348c0
movl 0x4(%rsp), %edx
movq 0x20(%r13), %rax
movq %rdx, %rcx
shlq $0x4, %rcx
movl 0x8(%rax,%rcx), %eax
addl $-0x2, %eax
cmpl $0xa, %eax
ja 0x341a9
leaq 0x816cc(%rip), %rcx     # 0xb5760
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r13, %rdi
movl %edx, %esi
callq 0xb3ca
movq %rax, %r15
cmpb $0x0, 0x39(%rax)
movq 0x8(%rsp), %r14
je 0x341ba
movl 0x3c(%r15), %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x33f8a
jmp 0x342f8
movq %r13, %rdi
movl %edx, %esi
callq 0x1b42a
movq %rax, %r15
movl 0xc(%rax), %edx
testl %edx, %edx
movq 0x8(%rsp), %r14
je 0x34249
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x34600
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
movq %rbx, %rdi
callq 0x60b0
leaq 0x10(%r14), %rdx
movq %rdx, (%r14)
movq (%rax), %rsi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rsi
je 0x342c0
movq %rsi, (%r14)
movq (%rcx), %rdx
movq %rdx, 0x10(%r14)
jmp 0x342c6
movq %r13, %rdi
movl %edx, %esi
callq 0x1c036
movq %rax, %r15
movl 0xc(%rax), %esi
movq %r13, %rdi
callq 0xa3ea
movl 0x8(%r15), %edx
movq 0x38(%r13), %rcx
imulq $0x148, %rdx, %rdx      # imm = 0x148
cmpb $0x1, 0xcc(%rcx,%rdx)
movq 0x8(%rsp), %r14
jne 0x341ef
addq %rdx, %rcx
movl 0xa0(%rcx), %edx
movq (%r13), %rax
movq %r14, %rdi
movq %r13, %rsi
movl $0x8, %ecx
callq *0xa0(%rax)
jmp 0x342f8
cmpb $0x1, 0x43e(%r13)
movq 0x8(%rsp), %r14
jne 0x3422c
movq (%r13), %rax
jmp 0x341b2
movq (%r13), %rax
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
jmp 0x3421f
cmpb $0x1, 0x64(%r15)
jne 0x341cc
cmpb $0x0, 0x65(%r15)
je 0x340b9
cmpb $0x1, 0x59(%r15)
jne 0x3432c
movb $0x0, 0x59(%r15)
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2c7ac
jmp 0x342f8
cmpb $0x1, 0x108(%r15)
jne 0x34203
cmpb $0x1, 0x43e(%r13)
je 0x34211
cmpb $0x1, 0x10a(%r15)
jne 0x34352
movl 0x4(%rsp), %edx
movq (%r13), %rax
movq %r14, %rdi
movq %r13, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
jmp 0x342f8
movq %r13, %rdi
movl %edx, %esi
callq 0x530d4
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x2cd88
jmp 0x342f8
cmpb $0x1, 0x39(%r15)
jne 0x3430a
movl 0x4(%rsp), %esi
movq %r13, %rdi
movl $0xa, %edx
callq 0x12974
movl %eax, %ebx
leaq 0x48(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rdi
callq 0xe456
movl 0x30(%r15), %esi
movq %r13, %rdi
callq 0xa3ea
movq (%r13), %r9
movzbl %bl, %r8d
leaq 0x38(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rcx
callq *0x118(%r9)
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x342f8
movq 0x48(%rsp), %rsi
jmp 0x342f0
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%r14)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x342f8
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x6260
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x1, 0x1d0(%r13)
jne 0x34391
leaq 0x10(%r14), %rax
movq %rax, (%r14)
movw $0x5f, 0x10(%r14)
movq $0x1, 0x8(%r14)
jmp 0x342f8
leaq 0x6b0(%r13), %rdi
leaq 0x4(%rsp), %rsi
callq 0x1f4b4
testq %rax, %rax
je 0x343b0
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3492a
jmp 0x342f8
cmpl $0xc, 0xc(%rax)
jne 0x34366
cmpb $0x0, 0x626(%r13)
je 0x34211
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
je 0x3437e
cmpb $0x0, 0x627(%r13)
je 0x34211
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2deba
jmp 0x342f8
leaq 0x10(%r14), %rax
movq %rax, (%r14)
movq 0x10(%r15), %rsi
movq 0x18(%r15), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0xe456
jmp 0x342f8
movl 0x8(%r15), %ecx
movq 0x38(%r13), %rax
imulq $0x148, %rcx, %rcx      # imm = 0x148
cmpb $0x1, 0xcc(%rax,%rcx)
jne 0x34211
addq %rcx, %rax
movl 0xa0(%rax), %edx
movl 0x10(%r15), %ecx
movq (%r13), %rax
movq %r14, %rdi
movq %r13, %rsi
jmp 0x34185
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x83c6b(%rip), %rsi     # 0xb8071
leaq 0x83c9c(%rip), %rdx     # 0xb80a9
leaq 0x18(%rsp), %rdi
callq 0x7be0
movb $0x1, %bpl
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0xc799a(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0xc7972(%rip), %rsi     # 0xfbdb0
movq 0xc8b93(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
jmp 0x344b3
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x83bc2(%rip), %rsi     # 0xb802e
leaq 0x83bfd(%rip), %rdx     # 0xb8070
leaq 0x18(%rsp), %rdi
callq 0x7be0
movb $0x1, %bpl
leaq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0xc7934(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0xc790c(%rip), %rsi     # 0xfbdb0
movq 0xc8b2d(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x34517
movq 0x48(%rsp), %rsi
jmp 0x3450f
jmp 0x344cb
jmp 0x344ec
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x344e5
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
jne 0x344ef
jmp 0x34517
movq %rax, %rbx
movq %r14, %rdi
callq 0x6200
jmp 0x34517
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x34517
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0
nop