// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x1b906
movq %rax, %r13
movzwl (%r14), %eax
movq %rax, 0xc8(%rsp)
movl 0x8(%r14), %r14d
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl (%r13), %eax
movl %eax, 0xa4(%rsp)
movl 0x4(%r13), %ebp
movl 0x8(%r13), %eax
movl %eax, 0x38(%rsp)
movl 0xc(%r13), %eax
movl %eax, 0x64(%rsp)
movl $0x0, 0xc(%rsp)
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0x3c6de
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c6ed
leaq 0x10(%rsp), %rdi
leaq 0x64(%rsp), %rdx
callq 0x7a00
movl $0xfffffffc, %r15d      # imm = 0xFFFFFFFC
movl $0x10, %r12d
movq 0xc8(%rsp), %rax
addl $-0x59, %eax
cmpl $0x9, %eax
ja 0x3c7ab
leaq 0x7a0ec(%rip), %rcx     # 0xb6800
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x10(%r13), %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movl $0xfffffffb, %r15d      # imm = 0xFFFFFFFB
movl $0x14, %r12d
jmp 0x3c7b3
movl 0x10(%r13), %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movb $0x1, %al
movl %eax, 0x28(%rsp)
movl $0xfffffffb, %r15d      # imm = 0xFFFFFFFB
movl $0x14, %r12d
jmp 0x3c7bb
movl $0x0, 0x28(%rsp)
movb $0x1, %al
movl %eax, 0x8(%rsp)
jmp 0x3c7bb
movl $0x0, 0x8(%rsp)
movb $0x1, %al
movl %eax, 0x28(%rsp)
jmp 0x3c7bb
movl 0x10(%r13), %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
movb $0x1, %al
movl %eax, 0x30(%rsp)
movl $0xfffffffb, %r15d      # imm = 0xFFFFFFFB
movl $0x14, %r12d
movl $0x0, 0x28(%rsp)
jmp 0x3c7c3
movl $0x0, 0x8(%rsp)
movl $0x0, 0x28(%rsp)
movl $0x0, 0x30(%rsp)
movq $0x0, 0x50(%rsp)
movq %rbx, %rdi
movl 0x38(%rsp), %esi
callq 0x12aba
movl 0x8(%rax), %esi
movq %rbx, %rdi
callq 0xa426
movq %rax, 0x70(%rsp)
movl 0x84(%rax), %eax
movl $0x2, %ecx
movq %rcx, 0x68(%rsp)
cmpq $0x6, %rax
jae 0x3c80d
leaq 0x7ac6f(%rip), %rcx     # 0xb7474
movl (%rcx,%rax,4), %eax
movq %rax, 0x68(%rsp)
movl 0xc(%rsp), %eax
testl %eax, %eax
je 0x3c83d
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c82e
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c83d
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x7a00
addq %r12, %r13
xorl %r12d, %r12d
movq 0x70(%rsp), %rax
movzbl 0x89(%rax), %eax
movl %eax, 0x78(%rsp)
movl %r12d, 0x60(%rsp)
movl %r12d, 0x4c(%rsp)
movl %r12d, 0x48(%rsp)
movl %r12d, 0x44(%rsp)
movl %r12d, 0x40(%rsp)
movl %r12d, 0x3c(%rsp)
movl %r12d, 0x5c(%rsp)
movl %r12d, 0x58(%rsp)
addl %r15d, %r14d
je 0x3c88b
movl (%r13), %r12d
addq $0x4, %r13
decl %r14d
testl %r14d, %r14d
je 0x3c8cf
movl %r12d, %eax
andl $0x1, %eax
je 0x3c8cf
movl (%r13), %eax
movl %eax, 0x60(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c8b9
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c8c8
leaq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0x7a00
addq $0x4, %r13
decl %r14d
testl %r14d, %r14d
je 0x3c913
movl %r12d, %eax
andl $0x2, %eax
je 0x3c913
movl (%r13), %eax
movl %eax, 0x4c(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c8fd
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c90c
leaq 0x10(%rsp), %rdi
leaq 0x4c(%rsp), %rdx
callq 0x7a00
addq $0x4, %r13
decl %r14d
movl %r12d, %r15d
andl $0x4, %r15d
testl %r14d, %r14d
je 0x3c95b
testl %r15d, %r15d
je 0x3c95b
movl (%r13), %eax
movl %eax, 0x48(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c945
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c954
leaq 0x10(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x7a00
addq $0x4, %r13
decl %r14d
testl %r14d, %r14d
je 0x3c99c
testl %r15d, %r15d
je 0x3c99c
movl (%r13), %eax
movl %eax, 0x44(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c986
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c995
leaq 0x10(%rsp), %rdi
leaq 0x44(%rsp), %rdx
callq 0x7a00
addq $0x4, %r13
decl %r14d
testl %r14d, %r14d
je 0x3c9e0
movl %r12d, %eax
andl $0x8, %eax
je 0x3c9e0
movl (%r13), %eax
movl %eax, 0x40(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3c9ca
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3c9d9
leaq 0x10(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x7a00
addq $0x4, %r13
decl %r14d
testl %r14d, %r14d
je 0x3ca24
movl %r12d, %eax
andl $0x10, %eax
je 0x3ca24
movl (%r13), %eax
movl %eax, 0x3c(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3ca0e
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3ca1d
leaq 0x10(%rsp), %rdi
leaq 0x3c(%rsp), %rdx
callq 0x7a00
addq $0x4, %r13
decl %r14d
testl %r14d, %r14d
je 0x3ca68
movl %r12d, %eax
andl $0x20, %eax
je 0x3ca68
movl (%r13), %eax
movl %eax, 0x5c(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3ca52
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3ca61
leaq 0x10(%rsp), %rdi
leaq 0x5c(%rsp), %rdx
callq 0x7a00
addq $0x4, %r13
decl %r14d
testl %r14d, %r14d
je 0x3caa3
andl $0x40, %r12d
je 0x3caa3
movl (%r13), %eax
movl %eax, 0x58(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x3ca94
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x3caa3
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x7a00
movl %ebp, 0xa0(%rsp)
movzbl 0x28(%rsp), %r14d
leaq 0xb8(%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, 0x5c(%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 %r12d, %r12d
cmpl $0x0, 0xc(%rsp)
setne %r12b
movl 0x4c(%rsp), %ebp
movq (%rbx), %rcx
movq 0xd8(%rcx), %r11
movzbl 0x8(%rsp), %r13d
movzbl 0x30(%rsp), %r9d
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
movl 0x38(%rsp), %edx
movq 0x70(%rsp), %rcx
movl %r13d, %r8d
movl %r9d, 0x8(%rsp)
pushq %rbp
pushq %r12
pushq %r15
pushq %r10
pushq %rax
pushq %r14
callq *%r11
addq $0x30, %rsp
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
leaq 0xa8(%rsp), %rdi
callq 0x60b0
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3cb85
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x6260
movl %r13d, %r15d
leaq 0x87112(%rip), %rsi     # 0xc3ca1
leaq 0xa8(%rsp), %rdi
callq 0x64e0
movq 0x68(%rsp), %r12
addl %r14d, %r12d
addl 0x78(%rsp), %r12d
movl 0x64(%rsp), %eax
movq %rax, 0x68(%rsp)
movl 0xc(%rsp), %eax
movq %rax, 0x78(%rsp)
movl 0x48(%rsp), %eax
movq %rax, 0xd0(%rsp)
movl 0x44(%rsp), %r11d
movl 0x4c(%rsp), %ebp
movl 0x40(%rsp), %eax
movq %r14, 0x30(%rsp)
movl 0x3c(%rsp), %r14d
movl 0x60(%rsp), %r13d
movl 0x58(%rsp), %r10d
movq (%rbx), %rcx
movq 0xe0(%rcx), %rcx
movq %rcx, 0x28(%rsp)
subq $0x8, %rsp
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
movl 0x40(%rsp), %edx
movq 0x78(%rsp), %rcx
movl %r15d, %r8d
movl 0x10(%rsp), %r9d
leaq 0xf(%rsp), %r15
pushq %r15
pushq %r10
pushq 0x68(%rsp)
pushq %r13
pushq %r14
pushq %rax
pushq %rbp
pushq %r11
pushq 0x118(%rsp)
pushq 0xc8(%rsp)
pushq %r12
pushq 0xc8(%rsp)
pushq 0x98(%rsp)
callq *0x98(%rsp)
addq $0x70, %rsp
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
leaq 0xa8(%rsp), %rdi
callq 0x60b0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
movl 0xa0(%rsp), %ebp
je 0x3cc9e
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x7ed80(%rip), %rsi     # 0xbba25
leaq 0xa8(%rsp), %rdi
callq 0x64e0
cmpb $0x0, 0x43c(%rbx)
movl $0x12b, %eax            # imm = 0x12B
movl $0x81, %ecx
cmovnel %eax, %ecx
cmpl %ecx, 0x438(%rbx)
ja 0x3ccf7
movq %rbx, %rdi
movq 0x70(%rsp), %rsi
movl 0x38(%rsp), %edx
callq 0x1b812
testb %al, %al
je 0x3ccf7
leaq 0x7c852(%rip), %rsi     # 0xb953c
leaq 0xa8(%rsp), %rdi
callq 0x64e0
movzbl 0x7(%rsp), %r8d
leaq 0xa8(%rsp), %rcx
movq %rbx, %rdi
movl 0xa4(%rsp), %esi
movl %ebp, %edx
xorl %r9d, %r9d
callq 0x39bea
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r15
cmpq %r15, %r14
je 0x3cd3b
movl (%r14), %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x164e0
addq $0x4, %r14
jmp 0x3cd23
movq 0xc8(%rsp), %rax
addl $-0x57, %eax
cmpl $0x6, %eax
ja 0x3cd62
movq %rax, %rcx
movl $0x55, %eax
btl %ecx, %eax
jae 0x3cd62
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3ce76
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x3cd87
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3cd9e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6260
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x10(%r13), %eax
movq %rax, 0x50(%rsp)
movb $0x1, %al
movl %eax, 0x30(%rsp)
movl $0xfffffffb, %r15d      # imm = 0xFFFFFFFB
movl $0x14, %r12d
movl $0x0, 0x8(%rsp)
movl $0x0, 0x28(%rsp)
jmp 0x3c7cc
jmp 0x3ce27
jmp 0x3ce27
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
jmp 0x3ce0a
jmp 0x3ce2e
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3ce31
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x3ce31
jmp 0x3ce2e
jmp 0x3ce27
jmp 0x3ce27
movq %rax, %rbx
jmp 0x3ce56
jmp 0x3ce2e
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x3ce56
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3ce6d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0
nop