// File: /workspace/github_cpp_makefile_star2_O3/rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::emit_texture_op(spirv_cross::Instruction const&)
void CompilerGLSL::emit_texture_op(const Instruction &i)
{
	auto *ops = stream(i);
	auto op = static_cast<Op>(i.op);
	uint32_t length = i.length;

	vector<uint32_t> inherited_expressions;

	uint32_t result_type = ops[0];
	uint32_t id = ops[1];
	uint32_t img = ops[2];
	uint32_t coord = ops[3];
	uint32_t dref = 0;
	uint32_t comp = 0;
	bool gather = false;
	bool proj = false;
	bool fetch = false;
	const uint32_t *opt = nullptr;

	inherited_expressions.push_back(coord);

	switch (op)
	{
	case OpImageSampleDrefImplicitLod:
	case OpImageSampleDrefExplicitLod:
		dref = ops[4];
		opt = &ops[5];
		length -= 5;
		break;

	case OpImageSampleProjDrefImplicitLod:
	case OpImageSampleProjDrefExplicitLod:
		dref = ops[4];
		opt = &ops[5];
		length -= 5;
		proj = true;
		break;

	case OpImageDrefGather:
		dref = ops[4];
		opt = &ops[5];
		length -= 5;
		gather = true;
		break;

	case OpImageGather:
		comp = ops[4];
		opt = &ops[5];
		length -= 5;
		gather = true;
		break;

	case OpImageFetch:
	case OpImageRead: // Reads == fetches in Metal (other langs will not get here)
		opt = &ops[4];
		length -= 4;
		fetch = true;
		break;

	case OpImageSampleProjImplicitLod:
	case OpImageSampleProjExplicitLod:
		opt = &ops[4];
		length -= 4;
		proj = true;
		break;

	default:
		opt = &ops[4];
		length -= 4;
		break;
	}

	// Bypass pointers because we need the real image struct
	auto &type = expression_type(img);
	auto &imgtype = get<SPIRType>(type.self);

	uint32_t coord_components = 0;
	switch (imgtype.image.dim)
	{
	case spv::Dim1D:
		coord_components = 1;
		break;
	case spv::Dim2D:
		coord_components = 2;
		break;
	case spv::Dim3D:
		coord_components = 3;
		break;
	case spv::DimCube:
		coord_components = 3;
		break;
	case spv::DimBuffer:
		coord_components = 1;
		break;
	default:
		coord_components = 2;
		break;
	}

	if (dref)
		inherited_expressions.push_back(dref);

	if (proj)
		coord_components++;
	if (imgtype.image.arrayed)
		coord_components++;

	uint32_t bias = 0;
	uint32_t lod = 0;
	uint32_t grad_x = 0;
	uint32_t grad_y = 0;
	uint32_t coffset = 0;
	uint32_t offset = 0;
	uint32_t coffsets = 0;
	uint32_t sample = 0;
	uint32_t flags = 0;

	if (length)
	{
		flags = *opt++;
		length--;
	}

	auto test = [&](uint32_t &v, uint32_t flag) {
		if (length && (flags & flag))
		{
			v = *opt++;
			inherited_expressions.push_back(v);
			length--;
		}
	};

	test(bias, ImageOperandsBiasMask);
	test(lod, ImageOperandsLodMask);
	test(grad_x, ImageOperandsGradMask);
	test(grad_y, ImageOperandsGradMask);
	test(coffset, ImageOperandsConstOffsetMask);
	test(offset, ImageOperandsOffsetMask);
	test(coffsets, ImageOperandsConstOffsetsMask);
	test(sample, ImageOperandsSampleMask);

	string expr;
	bool forward = false;
	expr += to_function_name(img, imgtype, !!fetch, !!gather, !!proj, !!coffsets, (!!coffset || !!offset),
	                         (!!grad_x || !!grad_y), !!dref, lod);
	expr += "(";
	expr += to_function_args(img, imgtype, fetch, gather, proj, coord, coord_components, dref, grad_x, grad_y, lod,
	                         coffset, offset, bias, comp, sample, &forward);
	expr += ")";

	// texture(samplerXShadow) returns float. shadowX() returns vec4. Swizzle here.
	if (is_legacy() && image_is_comparison(imgtype, img))
		expr += ".r";

	emit_op(result_type, id, expr, forward);
	for (auto &inherit : inherited_expressions)
		inherit_expression_dependencies(id, inherit);

	switch (op)
	{
	case OpImageSampleDrefImplicitLod:
	case OpImageSampleImplicitLod:
	case OpImageSampleProjImplicitLod:
	case OpImageSampleProjDrefImplicitLod:
		register_control_dependent_expression(id);
		break;

	default:
		break;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x1b2ac
movq %rax, %r13
movzwl (%r14), %r15d
movl 0x8(%r14), %r14d
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movl (%rax), %eax
movl %eax, 0xa8(%rsp)
movl 0x4(%r13), %ebp
movl 0x8(%r13), %eax
movl %eax, 0x38(%rsp)
movl 0xc(%r13), %eax
leaq 0xac(%rsp), %rdx
movl %eax, (%rdx)
movl $0x0, 0xc(%rsp)
movq $0x0, 0x58(%rsp)
xorl %esi, %esi
callq 0x797e
movl $0xfffffffc, %r12d      # imm = 0xFFFFFFFC
movl $0x10, %eax
movq %rax, 0x50(%rsp)
leal -0x59(%r15), %eax
cmpl $0x9, %eax
ja 0x3bfb5
leaq 0x798ef(%rip), %rcx     # 0xb57f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x10(%r13), %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movl $0xfffffffb, %r12d      # imm = 0xFFFFFFFB
movl $0x14, %eax
movq %rax, 0x50(%rsp)
jmp 0x3bfbd
movl 0x10(%r13), %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movb $0x1, %al
movq %rax, 0x28(%rsp)
movl $0xfffffffb, %r12d      # imm = 0xFFFFFFFB
movl $0x14, %eax
movq %rax, 0x50(%rsp)
jmp 0x3bfc6
movb $0x1, %al
movl %eax, 0x8(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
jmp 0x3bfd8
movl $0x0, 0x8(%rsp)
movb $0x1, %al
movq %rax, 0x28(%rsp)
jmp 0x3bfc6
movl 0x10(%r13), %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movb $0x1, %al
movq %rax, 0x30(%rsp)
movl $0xfffffffb, %r12d      # imm = 0xFFFFFFFB
movl $0x14, %eax
movq %rax, 0x50(%rsp)
movq $0x0, 0x28(%rsp)
jmp 0x3bfcf
movl $0x0, 0x8(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x58(%rsp)
movq %rbx, %rdi
movl 0x38(%rsp), %esi
callq 0x12a72
movl %ebp, 0xa4(%rsp)
movl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0xa3ea
movq %rax, 0x70(%rsp)
movl 0x84(%rax), %eax
movl $0x2, %ebp
cmpq $0x6, %rax
jae 0x3c016
leaq 0x7a451(%rip), %rcx     # 0xb6464
movl (%rcx,%rax,4), %ebp
movl 0xc(%rsp), %eax
testl %eax, %eax
je 0x3c046
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c037
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c046
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x797e
movq %r15, 0xd0(%rsp)
xorl %eax, %eax
movq 0x70(%rsp), %rcx
movzbl 0x89(%rcx), %ecx
movl %ecx, 0x78(%rsp)
movl %eax, 0x6c(%rsp)
movl %eax, 0x4c(%rsp)
movl %eax, 0x48(%rsp)
movl %eax, 0x44(%rsp)
movl %eax, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
movl %eax, 0x68(%rsp)
movl %eax, 0x64(%rsp)
addl %r12d, %r14d
je 0x3c2da
movl %r14d, %r12d
decl %r12d
je 0x3c2da
addq 0x50(%rsp), %r13
movl (%r13), %r15d
testb $0x1, %r15b
jne 0x3c0aa
addq $0x4, %r13
jmp 0x3c121
movl 0x4(%r13), %eax
movl %eax, 0x6c(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c101
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c110
movl 0x10(%r13), %eax
movq %rax, 0x58(%rsp)
movb $0x1, %al
movq %rax, 0x30(%rsp)
movl $0xfffffffb, %r12d      # imm = 0xFFFFFFFB
movl $0x14, %eax
movq %rax, 0x50(%rsp)
movl $0x0, 0x8(%rsp)
movq $0x0, 0x28(%rsp)
jmp 0x3bfd8
leaq 0x10(%rsp), %rdi
leaq 0x6c(%rsp), %rdx
callq 0x797e
addl $-0x2, %r14d
je 0x3c2da
addq $0x8, %r13
movl %r14d, %r12d
testb $0x2, %r15b
je 0x3c164
movl (%r13), %eax
movl %eax, 0x4c(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c148
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c157
leaq 0x10(%rsp), %rdi
leaq 0x4c(%rsp), %rdx
callq 0x797e
decl %r12d
je 0x3c2da
addq $0x4, %r13
testb $0x4, %r15b
je 0x3c1e2
movl (%r13), %eax
movl %eax, 0x48(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c18b
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c19a
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x797e
cmpl $0x1, %r12d
je 0x3c2da
movl 0x4(%r13), %eax
movl %eax, 0x44(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c1c5
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c1d4
leaq 0x10(%rsp), %rdi
leaq 0x44(%rsp), %rdx
callq 0x797e
addl $-0x2, %r12d
je 0x3c2da
addq $0x8, %r13
testb $0x8, %r15b
je 0x3c225
movl (%r13), %eax
movl %eax, 0x40(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c209
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c218
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x797e
decl %r12d
je 0x3c2da
addq $0x4, %r13
testb $0x10, %r15b
je 0x3c264
movl (%r13), %eax
movl %eax, 0x3c(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c24c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c25b
leaq 0x10(%rsp), %rdi
leaq 0x3c(%rsp), %rdx
callq 0x797e
decl %r12d
je 0x3c2da
addq $0x4, %r13
testb $0x20, %r15b
je 0x3c2a4
movl (%r13), %eax
movl %eax, 0x68(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c28b
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c29a
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x797e
cmpl $0x1, %r12d
je 0x3c2da
addq $0x4, %r13
testb $0x40, %r15b
je 0x3c2da
movl (%r13), %eax
movl %eax, 0x64(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c2cb
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c2da
leaq 0x10(%rsp), %rdi
leaq 0x64(%rsp), %rdx
callq 0x797e
movzbl 0x28(%rsp), %r13d
leaq 0xc0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
xorl %eax, %eax
movb %al, (%rcx)
movb %al, 0x7(%rsp)
xorl %eax, %eax
cmpl $0x0, 0x68(%rsp)
setne %al
movl 0x3c(%rsp), %ecx
xorl %r10d, %r10d
orl 0x40(%rsp), %ecx
setne %r10b
movl 0x44(%rsp), %ecx
xorl %r15d, %r15d
orl 0x48(%rsp), %ecx
setne %r15b
xorl %r14d, %r14d
cmpl $0x0, 0xc(%rsp)
setne %r14b
movl 0x4c(%rsp), %r12d
movq (%rbx), %rcx
movq 0xd8(%rcx), %r11
movzbl 0x8(%rsp), %r8d
movzbl 0x30(%rsp), %r9d
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
movl 0x38(%rsp), %edx
movq 0x70(%rsp), %rcx
movl %r8d, 0x8(%rsp)
movl %r9d, 0x30(%rsp)
pushq %r12
pushq %r14
pushq %r15
pushq %r10
pushq %rax
pushq %r13
callq *%r11
addq $0x30, %rsp
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
leaq 0xb0(%rsp), %rdi
callq 0x60b0
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c3b9
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x868b1(%rip), %rsi     # 0xc2c71
leaq 0xb0(%rsp), %rdi
callq 0x64e0
addl %r13d, %ebp
addl 0x78(%rsp), %ebp
movl 0xac(%rsp), %eax
movq %rax, 0x28(%rsp)
movl 0xc(%rsp), %eax
movq %rax, 0xe0(%rsp)
movl 0x48(%rsp), %eax
movq %rax, 0xd8(%rsp)
movl 0x44(%rsp), %r12d
movl 0x4c(%rsp), %eax
movl 0x40(%rsp), %r14d
movq %r13, 0x78(%rsp)
movl 0x3c(%rsp), %r13d
movl 0x6c(%rsp), %r15d
movl 0x64(%rsp), %r10d
movq (%rbx), %rcx
movq 0xe0(%rcx), %rcx
movq %rcx, 0x50(%rsp)
subq $0x8, %rsp
leaq 0xf(%rsp), %r11
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
movl 0x40(%rsp), %edx
movq 0x78(%rsp), %rcx
movl 0x10(%rsp), %r8d
movl 0x38(%rsp), %r9d
pushq %r11
pushq %r10
pushq 0x70(%rsp)
pushq %r15
pushq %r13
pushq %r14
pushq %rax
pushq %r12
pushq 0x120(%rsp)
pushq 0x130(%rsp)
pushq %rbp
pushq 0x88(%rsp)
pushq 0xe0(%rsp)
callq *0xc0(%rsp)
addq $0x70, %rsp
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
leaq 0xb0(%rsp), %rdi
callq 0x60b0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
movl 0xa4(%rsp), %ebp
je 0x3c4d2
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x7e53c(%rip), %rsi     # 0xbaa15
leaq 0xb0(%rsp), %rdi
callq 0x64e0
cmpb $0x0, 0x43c(%rbx)
movl $0x12b, %eax            # imm = 0x12B
movl $0x81, %ecx
cmovnel %eax, %ecx
cmpl %ecx, 0x438(%rbx)
ja 0x3c52b
movq %rbx, %rdi
movq 0x70(%rsp), %rsi
movl 0x38(%rsp), %edx
callq 0x1b12c
testb %al, %al
je 0x3c52b
leaq 0x7c00e(%rip), %rsi     # 0xb852c
leaq 0xb0(%rsp), %rdi
callq 0x64e0
movzbl 0x7(%rsp), %r8d
leaq 0xb0(%rsp), %rcx
movq %rbx, %rdi
movl 0xa8(%rsp), %esi
movl %ebp, %edx
xorl %r9d, %r9d
callq 0x3942c
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r15, %r14
je 0x3c56f
movl (%r14), %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1616c
addq $0x4, %r14
jmp 0x3c557
movq 0xd0(%rsp), %rcx
addl $-0x57, %ecx
cmpl $0x6, %ecx
ja 0x3c593
movl $0x55, %eax
btl %ecx, %eax
jae 0x3c593
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3c676
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x3c5b8
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3c5cf
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6260
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c628
jmp 0x3c628
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
jmp 0x3c60b
jmp 0x3c62f
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3c632
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x3c632
jmp 0x3c62f
jmp 0x3c628
jmp 0x3c628
movq %rax, %rbx
jmp 0x3c657
jmp 0x3c62f
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x3c657
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3c66e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0