// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::to_function_name[abi:cxx11](unsigned int, spirv_cross::SPIRType const&, bool, bool, bool, bool, bool, bool, bool, unsigned int)
string CompilerGLSL::to_function_name(uint32_t tex, const SPIRType &imgtype, bool is_fetch, bool is_gather,
                                      bool is_proj, bool has_array_offsets, bool has_offset, bool has_grad, bool,
                                      uint32_t lod)
{
	string fname;

	// textureLod on sampler2DArrayShadow and samplerCubeShadow does not exist in GLSL for some reason.
	// To emulate this, we will have to use textureGrad with a constant gradient of 0.
	// The workaround will assert that the LOD is in fact constant 0, or we cannot emit correct code.
	// This happens for HLSL SampleCmpLevelZero on Texture2DArray and TextureCube.
	bool workaround_lod_array_shadow_as_grad = false;
	if (((imgtype.image.arrayed && imgtype.image.dim == Dim2D) || imgtype.image.dim == DimCube) &&
	    image_is_comparison(imgtype, tex) && lod)
	{
		auto *constant_lod = maybe_get<SPIRConstant>(lod);
		if (!constant_lod || constant_lod->scalar_f32() != 0.0f)
			SPIRV_CROSS_THROW(
			    "textureLod on sampler2DArrayShadow is not constant 0.0. This cannot be expressed in GLSL.");
		workaround_lod_array_shadow_as_grad = true;
	}

	if (is_fetch)
		fname += "texelFetch";
	else
	{
		fname += "texture";

		if (is_gather)
			fname += "Gather";
		if (has_array_offsets)
			fname += "Offsets";
		if (is_proj)
			fname += "Proj";
		if (has_grad || workaround_lod_array_shadow_as_grad)
			fname += "Grad";
		if (!!lod && !workaround_lod_array_shadow_as_grad)
			fname += "Lod";
	}

	if (has_offset)
		fname += "Offset";

	return is_legacy() ? legacy_tex_op(fname, imgtype, lod, tex) : fname;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xe0, %rsp
movl %r8d, %eax
movq %rcx, %r10
movl %edx, %r11d
movq %rsi, %rbx
movq %rdi, %r14
movq %r14, -0xb8(%rbp)
movb %r9b, %r8b
movb %al, %r9b
movq %r14, %rdi
movq %rdi, -0xb0(%rbp)
movl 0x38(%rbp), %eax
movb 0x30(%rbp), %al
movb 0x28(%rbp), %cl
movb 0x20(%rbp), %dl
movb 0x18(%rbp), %sil
movb 0x10(%rbp), %dil
movq %r14, -0x18(%rbp)
movq %rbx, -0x20(%rbp)
movl %r11d, -0x24(%rbp)
movq %r10, -0x30(%rbp)
andb $0x1, %r9b
movb %r9b, -0x31(%rbp)
andb $0x1, %r8b
movb %r8b, -0x32(%rbp)
andb $0x1, %dil
movb %dil, -0x33(%rbp)
andb $0x1, %sil
movb %sil, -0x34(%rbp)
andb $0x1, %dl
movb %dl, -0x35(%rbp)
andb $0x1, %cl
movb %cl, -0x36(%rbp)
andb $0x1, %al
movb %al, -0x37(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x7530
movb $0x0, -0x59(%rbp)
movq -0x30(%rbp), %rax
testb $0x1, 0x89(%rax)
je 0x7c75b
movq -0x30(%rbp), %rax
cmpl $0x1, 0x84(%rax)
je 0x7c76c
movq -0x30(%rbp), %rax
cmpl $0x3, 0x84(%rax)
jne 0x7c8dd
movq -0xa8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x2c890
movb %al, -0xb9(%rbp)
jmp 0x7c787
movb -0xb9(%rbp), %al
testb $0x1, %al
jne 0x7c796
jmp 0x7c8dd
cmpl $0x0, 0x38(%rbp)
je 0x7c8dd
movq -0xa8(%rbp), %rdi
movl 0x38(%rbp), %esi
callq 0xa2eb0
movq %rax, -0xc8(%rbp)
jmp 0x7c7b8
movq -0xc8(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x7c7f8
movq -0x78(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa1ea0
movss %xmm0, -0xcc(%rbp)
jmp 0x7c7e1
movss -0xcc(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x7c7f8
jp 0x7c7f8
jmp 0x7c8d9
movb $0x1, -0x9a(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0xe0(%rbp)
leaq -0x99(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x7650
movq -0xd8(%rbp), %rdx
leaq 0xc61e2(%rip), %rsi     # 0x142a13
leaq -0x98(%rbp), %rdi
callq 0x7520
jmp 0x7c83f
movq -0xe0(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x9c50
jmp 0x7c854
movq -0xe0(%rbp), %rdi
movb $0x0, -0x9a(%rbp)
leaq 0x13156f(%rip), %rsi    # 0x1addd8
leaq -0x72be0(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x7ca3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x7ca2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x7c8b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x7708
leaq -0x99(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x9a(%rbp)
jne 0x7c8c8
jmp 0x7c8d4
movq -0xe0(%rbp), %rdi
callq 0x72c0
jmp 0x7ca2d
movb $0x1, -0x59(%rbp)
testb $0x1, -0x31(%rbp)
je 0x7c8fa
leaq 0xc51ef(%rip), %rsi     # 0x141ad9
leaq -0x58(%rbp), %rdi
callq 0x7340
jmp 0x7c8f5
jmp 0x7c99c
leaq 0xd0303(%rip), %rsi     # 0x14cc04
leaq -0x58(%rbp), %rdi
callq 0x7340
jmp 0x7c90c
testb $0x1, -0x32(%rbp)
je 0x7c926
leaq 0xcba39(%rip), %rsi     # 0x148352
leaq -0x58(%rbp), %rdi
callq 0x7340
jmp 0x7c924
jmp 0x7c926
testb $0x1, -0x34(%rbp)
je 0x7c940
leaq 0xc51f1(%rip), %rsi     # 0x141b24
leaq -0x58(%rbp), %rdi
callq 0x7340
jmp 0x7c93e
jmp 0x7c940
testb $0x1, -0x33(%rbp)
je 0x7c95a
leaq 0xc522e(%rip), %rsi     # 0x141b7b
leaq -0x58(%rbp), %rdi
callq 0x7340
jmp 0x7c958
jmp 0x7c95a
testb $0x1, -0x36(%rbp)
jne 0x7c966
testb $0x1, -0x59(%rbp)
je 0x7c97a
leaq 0xcba3b(%rip), %rsi     # 0x1483a8
leaq -0x58(%rbp), %rdi
callq 0x7340
jmp 0x7c978
jmp 0x7c97a
cmpl $0x0, 0x38(%rbp)
je 0x7c99a
testb $0x1, -0x59(%rbp)
jne 0x7c99a
leaq 0xc51c4(%rip), %rsi     # 0x141b51
leaq -0x58(%rbp), %rdi
callq 0x7340
jmp 0x7c998
jmp 0x7c99a
jmp 0x7c99c
testb $0x1, -0x35(%rbp)
je 0x7c9b6
leaq 0xc519a(%rip), %rsi     # 0x141b43
leaq -0x58(%rbp), %rdi
callq 0x7340
jmp 0x7c9b4
jmp 0x7c9b6
movq -0xa8(%rbp), %rdi
callq 0x9f610
movb %al, -0xe1(%rbp)
jmp 0x7c9ca
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x7c9d6
jmp 0x7c9fd
movq -0xa8(%rbp), %rsi
movq -0xb8(%rbp), %rdi
movq -0x30(%rbp), %rcx
movl 0x38(%rbp), %r8d
movl -0x24(%rbp), %r9d
leaq -0x58(%rbp), %rdx
callq 0x79f10
jmp 0x7c9fb
jmp 0x7ca11
movq -0xb8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x7170
jmp 0x7ca0f
jmp 0x7ca11
leaq -0x58(%rbp), %rdi
callq 0x7708
movq -0xb0(%rbp), %rax
addq $0xe0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x7708
movq -0x68(%rbp), %rdi
callq 0x7640
nop