// File: rossy[P]crossc/SPIRV-Cross/spirv_msl.cpp
// Function: spirv_cross::CompilerMSL::argument_decl[abi:cxx11](spirv_cross::SPIRFunction::Parameter const&)
string CompilerMSL::argument_decl(const SPIRFunction::Parameter &arg)
{

	auto &var = get<SPIRVariable>(arg.id);
	auto &type = expression_type(arg.id);

	// If we need to modify the name of the variable, make sure we use the original variable.
	// Our alias is just a shadow variable.
	uint32_t name_id = var.self;
	if (arg.alias_global_variable && var.basevariable)
		name_id = var.basevariable;

	bool constref = !arg.alias_global_variable && type.pointer && arg.write_count == 0;

	bool type_is_image = type.basetype == SPIRType::Image || type.basetype == SPIRType::SampledImage ||
	                     type.basetype == SPIRType::Sampler;

	// Arrays of images/samplers in MSL are always const.
	if (!type.array.empty() && type_is_image)
		constref = true;

	string decl;
	if (constref)
		decl += "const ";

	bool builtin = is_builtin_variable(var);
	if (builtin)
		decl += builtin_type_decl(static_cast<BuiltIn>(get_decoration(arg.id, DecorationBuiltIn)));
	else
		decl += type_to_glsl(type, arg.id);

	bool opaque_handle = type.storage == StorageClassUniformConstant;

	if (!builtin && !opaque_handle && !type.pointer &&
	    (type.storage == StorageClassFunction || type.storage == StorageClassGeneric))
	{
		// If the argument is a pure value and not an opaque type, we will pass by value.
		decl += " ";
		decl += to_expression(name_id);
	}
	else if (is_array(type) && !type_is_image)
	{
		// Arrays of images and samplers are special cased.
		if (get<SPIRVariable>(name_id).storage == StorageClassUniform ||
		    get<SPIRVariable>(name_id).storage == StorageClassStorageBuffer)
			// If an array of buffers, declare an array of pointers, since we
			// can't have an array of references.
			decl += "*";
		decl += " (&";
		decl += to_expression(name_id);
		decl += ")";
		decl += type_to_array_glsl(type);
	}
	else if (!opaque_handle)
	{
		decl += "&";
		decl += " ";
		decl += to_expression(name_id);
	}
	else
	{
		decl += " ";
		decl += to_expression(name_id);
	}

	return decl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x140(%rbp)
movq %rdi, %rax
movq %rax, -0x138(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x130(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %esi
callq 0xfec0
movq -0x130(%rbp), %rdi
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x1f760
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
testb $0x1, 0x10(%rax)
je 0x102702
movq -0x20(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x102702
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x10(%rcx)
movb %al, -0x141(%rbp)
jne 0x102737
movq -0x28(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x60(%rcx)
movb %al, -0x141(%rbp)
je 0x102737
movq -0x18(%rbp), %rax
cmpl $0x0, 0xc(%rax)
sete %al
movb %al, -0x141(%rbp)
movb -0x141(%rbp), %al
andb $0x1, %al
movb %al, -0x2d(%rbp)
movq -0x28(%rbp), %rcx
movb $0x1, %al
cmpl $0xd, 0xc(%rcx)
movb %al, -0x142(%rbp)
je 0x102777
movq -0x28(%rbp), %rcx
movb $0x1, %al
cmpl $0xe, 0xc(%rcx)
movb %al, -0x142(%rbp)
je 0x102777
movq -0x28(%rbp), %rax
cmpl $0xf, 0xc(%rax)
sete %al
movb %al, -0x142(%rbp)
movb -0x142(%rbp), %al
andb $0x1, %al
movb %al, -0x2e(%rbp)
movq -0x28(%rbp), %rdi
addq $0x20, %rdi
callq 0x8690
testb $0x1, %al
jne 0x10279d
testb $0x1, -0x2e(%rbp)
je 0x10279d
movb $0x1, -0x2d(%rbp)
movq -0x140(%rbp), %rdi
movb $0x0, -0x2f(%rbp)
callq 0x7530
testb $0x1, -0x2d(%rbp)
je 0x1027db
movq -0x140(%rbp), %rdi
leaq 0x3eeba(%rip), %rsi     # 0x14167b
callq 0x7340
jmp 0x1027c8
jmp 0x1027db
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x102c1e
movq -0x130(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x205a0
movb %al, -0x143(%rbp)
jmp 0x1027f3
movb -0x143(%rbp), %al
andb $0x1, %al
movb %al, -0x3d(%rbp)
testb $0x1, -0x3d(%rbp)
je 0x102873
movq -0x130(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %esi
movl $0xb, %edx
callq 0x23520
movl %eax, -0x148(%rbp)
jmp 0x102824
movl -0x148(%rbp), %edx
movq -0x130(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x10a360
jmp 0x10283c
movq -0x140(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x7470
jmp 0x10284e
leaq -0x60(%rbp), %rdi
callq 0x7708
jmp 0x1028ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x7708
jmp 0x102c1e
movq -0x130(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movq (%rsi), %rax
movq 0x98(%rax), %rax
leaq -0x80(%rbp), %rdi
callq *%rax
jmp 0x102897
movq -0x140(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x7470
jmp 0x1028a9
leaq -0x80(%rbp), %rdi
callq 0x7708
jmp 0x1028ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x7708
jmp 0x102c1e
movq -0x28(%rbp), %rax
cmpl $0x0, 0x64(%rax)
sete %al
andb $0x1, %al
movb %al, -0x81(%rbp)
testb $0x1, -0x3d(%rbp)
jne 0x10298a
testb $0x1, -0x81(%rbp)
jne 0x10298a
movq -0x28(%rbp), %rax
testb $0x1, 0x60(%rax)
jne 0x10298a
movq -0x28(%rbp), %rax
cmpl $0x7, 0x64(%rax)
je 0x10291a
movq -0x28(%rbp), %rax
cmpl $0x8, 0x64(%rax)
jne 0x10298a
movq -0x140(%rbp), %rdi
leaq 0x3bf75(%rip), %rsi     # 0x13e89d
callq 0x7340
jmp 0x10292f
movq -0x130(%rbp), %rsi
movl -0x2c(%rbp), %edx
leaq -0xa8(%rbp), %rdi
callq 0x71b50
jmp 0x102947
movq -0x140(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x7470
jmp 0x10295c
leaq -0xa8(%rbp), %rdi
callq 0x7708
jmp 0x102bf8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x7708
jmp 0x102c1e
movq -0x130(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x208a0
movb %al, -0x149(%rbp)
jmp 0x1029a2
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x1029b1
jmp 0x102af8
testb $0x1, -0x2e(%rbp)
jne 0x102af8
movq -0x130(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xfec0
movq %rax, -0x158(%rbp)
jmp 0x1029d3
movq -0x158(%rbp), %rax
cmpl $0x2, 0x10(%rax)
je 0x102a05
movq -0x130(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0xfec0
movq %rax, -0x160(%rbp)
jmp 0x1029f8
movq -0x160(%rbp), %rax
cmpl $0xc, 0x10(%rax)
jne 0x102a1c
movq -0x140(%rbp), %rdi
leaq 0x3bb67(%rip), %rsi     # 0x13e57a
callq 0x7340
jmp 0x102a1a
jmp 0x102a1c
movq -0x140(%rbp), %rdi
leaq 0x4ab6e(%rip), %rsi     # 0x14d598
callq 0x7340
jmp 0x102a31
movq -0x130(%rbp), %rsi
movl -0x2c(%rbp), %edx
leaq -0xc8(%rbp), %rdi
callq 0x71b50
jmp 0x102a49
movq -0x140(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x7470
jmp 0x102a5e
leaq -0xc8(%rbp), %rdi
callq 0x7708
movq -0x140(%rbp), %rdi
leaq 0x42481(%rip), %rsi     # 0x144ef9
callq 0x7340
jmp 0x102a7f
movq -0x130(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x61340
jmp 0x102a98
movq -0x140(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x7470
jmp 0x102aad
leaq -0xe8(%rbp), %rdi
callq 0x7708
jmp 0x102bf6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x7708
jmp 0x102c1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x7708
jmp 0x102c1e
testb $0x1, -0x81(%rbp)
jne 0x102b8a
movq -0x140(%rbp), %rdi
leaq 0x4a2b6(%rip), %rsi     # 0x14cdc9
callq 0x7340
jmp 0x102b1a
movq -0x140(%rbp), %rdi
leaq 0x3bd75(%rip), %rsi     # 0x13e89d
callq 0x7340
jmp 0x102b2f
movq -0x130(%rbp), %rsi
movl -0x2c(%rbp), %edx
leaq -0x108(%rbp), %rdi
callq 0x71b50
jmp 0x102b47
movq -0x140(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x7470
jmp 0x102b5c
leaq -0x108(%rbp), %rdi
callq 0x7708
jmp 0x102bf4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x7708
jmp 0x102c1e
movq -0x140(%rbp), %rdi
leaq 0x3bd05(%rip), %rsi     # 0x13e89d
callq 0x7340
jmp 0x102b9f
movq -0x130(%rbp), %rsi
movl -0x2c(%rbp), %edx
leaq -0x128(%rbp), %rdi
callq 0x71b50
jmp 0x102bb7
movq -0x140(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x7470
jmp 0x102bcc
leaq -0x128(%rbp), %rdi
callq 0x7708
jmp 0x102bf4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x7708
jmp 0x102c1e
jmp 0x102bf6
jmp 0x102bf8
movb $0x1, -0x2f(%rbp)
testb $0x1, -0x2f(%rbp)
jne 0x102c0e
movq -0x140(%rbp), %rdi
callq 0x7708
movq -0x138(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x140(%rbp), %rdi
callq 0x7708
movq -0x38(%rbp), %rdi
callq 0x7640
nopw %cs:(%rax,%rax)