// File: rossy[P]crossc/SPIRV-Cross/spirv_msl.cpp
// Function: spirv_cross::CompilerMSL::to_function_name[abi:cxx11](unsigned int, spirv_cross::SPIRType const&, bool, bool, bool, bool, bool, bool, bool, unsigned int)
string CompilerMSL::to_function_name(uint32_t img, const SPIRType &imgtype, bool is_fetch, bool is_gather, bool, bool,
                                     bool has_offset, bool, bool has_dref, uint32_t)
{
	// Special-case gather. We have to alter the component being looked up
	// in the swizzle case.
	if (msl_options.swizzle_texture_samples && is_gather)
	{
		string fname = imgtype.image.depth ? "spvGatherCompareSwizzle" : "spvGatherSwizzle";
		fname += "<" + type_to_glsl(get<SPIRType>(imgtype.image.type)) + ", metal::" + type_to_glsl(imgtype);
		// Add the arg types ourselves. Yes, this sucks, but Clang can't
		// deduce template pack parameters in the middle of an argument list.
		switch (imgtype.image.dim)
		{
		case Dim2D:
			fname += ", float2";
			if (imgtype.image.arrayed)
				fname += ", uint";
			if (imgtype.image.depth)
				fname += ", float";
			if (!imgtype.image.depth || has_offset)
				fname += ", int2";
			break;
		case DimCube:
			fname += ", float3";
			if (imgtype.image.arrayed)
				fname += ", uint";
			if (imgtype.image.depth)
				fname += ", float";
			break;
		default:
			SPIRV_CROSS_THROW("Invalid texture dimension for gather op.");
		}
		fname += ">";
		return fname;
	}

	auto *combined = maybe_get<SPIRCombinedImageSampler>(img);

	// Texture reference
	string fname = to_expression(combined ? combined->image : img) + ".";
	if (msl_options.swizzle_texture_samples && !is_gather && is_sampled_image_type(imgtype))
		fname = "spvTextureSwizzle(" + fname;

	// Texture function and sampler
	if (is_fetch)
		fname += "read";
	else if (is_gather)
		fname += "gather";
	else
		fname += "sample";

	if (has_dref)
		fname += "_compare";

	return fname;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x1c0, %rsp            # imm = 0x1C0
movl %r8d, %eax
movq %rcx, %r10
movl %edx, %r11d
movq %rsi, %rbx
movq %rdi, %r14
movq %r14, -0x180(%rbp)
movb %r9b, %r8b
movb %al, %r9b
movq %r14, %rdi
movq %rdi, -0x178(%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, -0x170(%rbp)
testb $0x1, 0x7df(%rax)
je 0x103564
testb $0x1, -0x32(%rbp)
je 0x103564
movb $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rax
movb 0x88(%rax), %dl
leaq 0x49f64(%rip), %rcx     # 0x14d0a4
leaq 0x49f75(%rip), %rax     # 0x14d0bc
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x190(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x7650
movq -0x180(%rbp), %rdi
movq -0x190(%rbp), %rsi
movq -0x188(%rbp), %rdx
callq 0x7520
jmp 0x103181
leaq -0x39(%rbp), %rdi
callq 0x73d0
movq -0x170(%rbp), %rdi
movq -0x30(%rbp), %rax
movl 0x80(%rax), %esi
callq 0xea90
movq %rax, -0x198(%rbp)
jmp 0x1031a9
movq -0x198(%rbp), %rdx
movq -0x170(%rbp), %rsi
movq (%rsi), %rax
movq 0x98(%rax), %rax
leaq -0xd0(%rbp), %rdi
xorl %ecx, %ecx
callq *%rax
jmp 0x1031ce
leaq 0x3f3fc(%rip), %rsi     # 0x1425d1
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
callq 0xa6db0
jmp 0x1031ea
leaq 0x49edc(%rip), %rdx     # 0x14d0cd
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x11910
jmp 0x103206
movq -0x170(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq (%rsi), %rax
movq 0x98(%rax), %rax
leaq -0xf0(%rbp), %rdi
xorl %ecx, %ecx
callq *%rax
jmp 0x103228
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0x2f7f0
jmp 0x103241
movq -0x180(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x7470
jmp 0x103253
leaq -0x70(%rbp), %rdi
callq 0x7708
leaq -0xf0(%rbp), %rdi
callq 0x7708
leaq -0x90(%rbp), %rdi
callq 0x7708
leaq -0xb0(%rbp), %rdi
callq 0x7708
leaq -0xd0(%rbp), %rdi
callq 0x7708
movq -0x30(%rbp), %rax
movl 0x84(%rax), %eax
movl %eax, -0x19c(%rbp)
subl $0x1, %eax
je 0x103368
jmp 0x1032a7
movl -0x19c(%rbp), %eax
subl $0x3, %eax
je 0x1033f4
jmp 0x103456
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x73d0
jmp 0x103748
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x103553
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x103357
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x10334b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x10333f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x103333
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x7708
leaq -0xf0(%rbp), %rdi
callq 0x7708
leaq -0x90(%rbp), %rdi
callq 0x7708
leaq -0xb0(%rbp), %rdi
callq 0x7708
leaq -0xd0(%rbp), %rdi
callq 0x7708
jmp 0x103553
movq -0x180(%rbp), %rdi
leaq 0x49d61(%rip), %rsi     # 0x14d0d7
callq 0x7340
jmp 0x10337d
movq -0x30(%rbp), %rax
testb $0x1, 0x89(%rax)
je 0x1033a1
movq -0x180(%rbp), %rdi
leaq 0x49d48(%rip), %rsi     # 0x14d0e0
callq 0x7340
jmp 0x10339f
jmp 0x1033a1
movq -0x30(%rbp), %rax
testb $0x1, 0x88(%rax)
je 0x1033c5
movq -0x180(%rbp), %rdi
leaq 0x49d2b(%rip), %rsi     # 0x14d0e7
callq 0x7340
jmp 0x1033c3
jmp 0x1033c5
movq -0x30(%rbp), %rax
testb $0x1, 0x88(%rax)
je 0x1033d8
testb $0x1, -0x35(%rbp)
je 0x1033ef
movq -0x180(%rbp), %rdi
leaq 0x49d09(%rip), %rsi     # 0x14d0ef
callq 0x7340
jmp 0x1033ed
jmp 0x1033ef
jmp 0x103523
movq -0x180(%rbp), %rdi
leaq 0x49cf4(%rip), %rsi     # 0x14d0f6
callq 0x7340
jmp 0x103409
movq -0x30(%rbp), %rax
testb $0x1, 0x89(%rax)
je 0x10342d
movq -0x180(%rbp), %rdi
leaq 0x49cbc(%rip), %rsi     # 0x14d0e0
callq 0x7340
jmp 0x10342b
jmp 0x10342d
movq -0x30(%rbp), %rax
testb $0x1, 0x88(%rax)
je 0x103451
movq -0x180(%rbp), %rdi
leaq 0x49c9f(%rip), %rsi     # 0x14d0e7
callq 0x7340
jmp 0x10344f
jmp 0x103451
jmp 0x103523
movb $0x1, -0x112(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x1b0(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x7650
movq -0x1a8(%rbp), %rdx
leaq 0x49c70(%rip), %rsi     # 0x14d0ff
leaq -0x110(%rbp), %rdi
callq 0x7520
jmp 0x10349d
movq -0x1b0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x9c50
jmp 0x1034b2
movq -0x1b0(%rbp), %rdi
movb $0x0, -0x112(%rbp)
leaq 0xaa911(%rip), %rsi     # 0x1addd8
leaq -0xf983e(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x103751
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1034fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x7708
leaq -0x111(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x112(%rbp)
jne 0x103515
jmp 0x103521
movq -0x1b0(%rbp), %rdi
callq 0x72c0
jmp 0x103553
movq -0x180(%rbp), %rdi
leaq 0x3acba(%rip), %rsi     # 0x13e1eb
callq 0x7340
jmp 0x103538
movb $0x1, -0x38(%rbp)
testb $0x1, -0x38(%rbp)
jne 0x10354e
movq -0x180(%rbp), %rdi
callq 0x7708
jmp 0x103735
movq -0x180(%rbp), %rdi
callq 0x7708
jmp 0x103748
movq -0x170(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0xdc700
movq %rax, -0x120(%rbp)
movb $0x0, -0x121(%rbp)
cmpq $0x0, -0x120(%rbp)
je 0x10359d
movq -0x120(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x1b4(%rbp)
jmp 0x1035a6
movl -0x24(%rbp), %eax
movl %eax, -0x1b4(%rbp)
movq -0x170(%rbp), %rsi
movl -0x1b4(%rbp), %edx
leaq -0x148(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x71b50
movq -0x180(%rbp), %rdi
movq -0x1c0(%rbp), %rsi
leaq 0x41752(%rip), %rdx     # 0x144d2d
callq 0x11910
jmp 0x1035e2
leaq -0x148(%rbp), %rdi
callq 0x7708
movq -0x170(%rbp), %rax
testb $0x1, 0x7df(%rax)
je 0x1036a7
testb $0x1, -0x32(%rbp)
jne 0x1036a7
movq -0x170(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x22ec0
movb %al, -0x1c1(%rbp)
jmp 0x103624
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0x103630
jmp 0x1036a7
movq -0x180(%rbp), %rdx
leaq 0x49aea(%rip), %rsi     # 0x14d128
leaq -0x168(%rbp), %rdi
callq 0xdc760
jmp 0x10364c
movq -0x180(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x7430
leaq -0x168(%rbp), %rdi
callq 0x7708
jmp 0x1036a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x7708
jmp 0x103748
movq -0x180(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x7708
jmp 0x103748
testb $0x1, -0x31(%rbp)
je 0x1036c4
movq -0x180(%rbp), %rdi
leaq 0x4a206(%rip), %rsi     # 0x14d8c1
callq 0x7340
jmp 0x1036c2
jmp 0x1036fa
testb $0x1, -0x32(%rbp)
je 0x1036e1
movq -0x180(%rbp), %rdi
leaq 0x49a63(%rip), %rsi     # 0x14d13b
callq 0x7340
jmp 0x1036df
jmp 0x1036f8
movq -0x180(%rbp), %rdi
leaq 0x3e89f(%rip), %rsi     # 0x141f8e
callq 0x7340
jmp 0x1036f6
jmp 0x1036f8
jmp 0x1036fa
testb $0x1, -0x37(%rbp)
je 0x103717
movq -0x180(%rbp), %rdi
leaq 0x49a34(%rip), %rsi     # 0x14d142
callq 0x7340
jmp 0x103715
jmp 0x103717
movb $0x1, -0x121(%rbp)
testb $0x1, -0x121(%rbp)
jne 0x103733
movq -0x180(%rbp), %rdi
callq 0x7708
jmp 0x103735
movq -0x178(%rbp), %rax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbx
popq %r14
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x7640
nopw %cs:(%rax,%rax)