// File: /workspace/github_cpp_makefile_star2_O2/rossy[P]crossc/SPIRV-Cross/spirv_hlsl.cpp
// Function: spirv_cross::CompilerHLSL::emit_function_prototype(spirv_cross::SPIRFunction&, spirv_cross::Bitset const&)
void CompilerHLSL::emit_function_prototype(SPIRFunction &func, const Bitset &return_flags)
{
	if (func.self != ir.default_entry_point)
		add_function_overload(func);

	auto &execution = get_entry_point();
	// Avoid shadow declarations.
	local_variable_names = resource_names;

	string decl;

	auto &type = get<SPIRType>(func.return_type);
	if (type.array.empty())
	{
		decl += flags_to_precision_qualifiers_glsl(type, return_flags);
		decl += type_to_glsl(type);
		decl += " ";
	}
	else
	{
		// We cannot return arrays in HLSL, so "return" through an out variable.
		decl = "void ";
	}

	if (func.self == ir.default_entry_point)
	{
		if (execution.model == ExecutionModelVertex)
			decl += "vert_main";
		else if (execution.model == ExecutionModelFragment)
			decl += "frag_main";
		else if (execution.model == ExecutionModelGLCompute)
			decl += "comp_main";
		else
			SPIRV_CROSS_THROW("Unsupported execution model.");
		processing_entry_point = true;
	}
	else
		decl += to_name(func.self);

	decl += "(";

	if (!type.array.empty())
	{
		// Fake array returns by writing to an out array instead.
		decl += "out ";
		decl += type_to_glsl(type);
		decl += " ";
		decl += "SPIRV_Cross_return_value";
		decl += type_to_array_glsl(type);
		if (!func.arguments.empty())
			decl += ", ";
	}

	for (auto &arg : func.arguments)
	{
		// Might change the variable name if it already exists in this function.
		// SPIRV OpName doesn't have any semantic effect, so it's valid for an implementation
		// to use same name for variables.
		// Since we want to make the GLSL debuggable and somewhat sane, use fallback names for variables which are duplicates.
		add_local_variable_name(arg.id);

		decl += argument_decl(arg);

		// Flatten a combined sampler to two separate arguments in modern HLSL.
		auto &arg_type = get<SPIRType>(arg.type);
		if (hlsl_options.shader_model > 30 && arg_type.basetype == SPIRType::SampledImage &&
		    arg_type.image.dim != DimBuffer)
		{
			// Manufacture automatic sampler arg for SampledImage texture
			decl += ", ";
			decl += join(image_is_comparison(arg_type, arg.id) ? "SamplerComparisonState " : "SamplerState ",
			             to_sampler_expression(arg.id), type_to_array_glsl(arg_type));
		}

		if (&arg != &func.arguments.back())
			decl += ", ";

		// Hold a pointer to the parameter so we can invalidate the readonly field if needed.
		auto *var = maybe_get<SPIRVariable>(arg.id);
		if (var)
			var->parameter = &arg;
	}

	decl += ")";
	statement(decl);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
movl 0x8(%rsi), %eax
cmpl 0x108(%rdi), %eax
je 0x554c0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3e668
movq %rbx, %rdi
callq 0x12fa4
movq %rax, %r14
leaq 0x488(%rbx), %rsi
leaq 0x450(%rbx), %rdi
callq 0xb54c
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl 0xc(%r13), %esi
movq %rbx, %rdi
callq 0x90a4
movq %rax, %r15
movq 0x20(%rax), %rax
cmpq 0x28(%r15), %rax
je 0x5551b
leaq 0x43549(%rip), %rsi     # 0x98a58
leaq 0x20(%rsp), %rdi
callq 0x64e0
jmp 0x55570
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x25714
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x64d0
movq (%rbx), %rax
movq %rsp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq *0x98(%rax)
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x64f0
movq %rsp, %rdi
callq 0x6548
leaq 0x3a320(%rip), %rsi     # 0x8f886
leaq 0x20(%rsp), %rdi
callq 0x64d0
movl 0x8(%r13), %edx
cmpl 0x108(%rbx), %edx
jne 0x5559e
movl 0xb8(%r14), %eax
testl %eax, %eax
je 0x555cd
cmpl $0x5, %eax
je 0x555c4
cmpl $0x4, %eax
jne 0x55837
leaq 0x434cc(%rip), %rsi     # 0x98a68
jmp 0x555d4
movq (%rbx), %rax
movq %rsp, %rdi
pushq $0x1
popq %rcx
movq %rbx, %rsi
callq *0x38(%rax)
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x64f0
movq %rsp, %rdi
callq 0x6548
jmp 0x555e5
leaq 0x434a7(%rip), %rsi     # 0x98a72
jmp 0x555d4
leaq 0x4348a(%rip), %rsi     # 0x98a5e
leaq 0x20(%rsp), %rdi
callq 0x64d0
movb $0x1, 0x5d8(%rbx)
leaq 0x4863d(%rip), %rsi     # 0x9dc29
leaq 0x20(%rsp), %rdi
callq 0x64d0
movq 0x20(%r15), %rax
cmpq 0x28(%r15), %rax
je 0x5569e
leaq 0x3ff98(%rip), %rsi     # 0x955a3
leaq 0x20(%rsp), %rdi
callq 0x64d0
movq (%rbx), %rax
movq %rsp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq *0x98(%rax)
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x64f0
movq %rsp, %rdi
callq 0x6548
leaq 0x3a241(%rip), %rsi     # 0x8f886
leaq 0x20(%rsp), %rdi
callq 0x64d0
leaq 0x404ef(%rip), %rsi     # 0x95b45
leaq 0x20(%rsp), %rdi
callq 0x64d0
movq %rsp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2547c
leaq 0x20(%rsp), %rdi
movq %rsp, %rsi
callq 0x64f0
movq %rsp, %rdi
callq 0x6548
movq 0x18(%r13), %rax
cmpq 0x20(%r13), %rax
je 0x5569e
leaq 0x3f9f7(%rip), %rsi     # 0x9508b
leaq 0x20(%rsp), %rdi
callq 0x64d0
movq 0x18(%r13), %r15
movq %r13, 0x40(%rsp)
movq 0x20(%r13), %rax
movq %rax, 0x48(%rsp)
movq %rsp, %r12
leaq 0x78(%rsp), %r13
cmpq 0x48(%rsp), %r15
je 0x557fd
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0x2f168
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x3dae4
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x64f0
movq %r12, %rdi
callq 0x6548
movl (%r15), %esi
movq %rbx, %rdi
callq 0x90a4
cmpl $0x1f, 0x788(%rbx)
jb 0x557bc
movq %rax, %r14
cmpl $0xe, 0xc(%rax)
jne 0x557bc
cmpl $0x5, 0x84(%r14)
je 0x557bc
leaq 0x20(%rsp), %rdi
leaq 0x3f95a(%rip), %rsi     # 0x9508b
callq 0x64d0
movl 0x4(%r15), %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x16cd4
testb %al, %al
leaq 0x43346(%rip), %rax     # 0x98a94
leaq 0x43327(%rip), %rcx     # 0x98a7c
cmovneq %rcx, %rax
movq %rax, 0x50(%rsp)
movl 0x4(%r15), %edx
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x552f6
movq %r13, %rbp
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2547c
movq %r12, %rdi
leaq 0x50(%rsp), %rsi
leaq 0x58(%rsp), %rdx
movq %rbp, %rcx
callq 0x61a46
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x64f0
movq %r12, %rdi
callq 0x6548
movq %r13, %rdi
callq 0x6548
leaq 0x58(%rsp), %rdi
callq 0x6548
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
addq $-0x14, %rax
cmpq %rax, %r15
je 0x557df
leaq 0x20(%rsp), %rdi
leaq 0x3f8b1(%rip), %rsi     # 0x9508b
callq 0x64d0
movl 0x4(%r15), %esi
movq %rbx, %rdi
callq 0xa9e4
testq %rax, %rax
je 0x557f4
movq %r15, 0x68(%rax)
addq $0x14, %r15
jmp 0x556b8
leaq 0x401f1(%rip), %rsi     # 0x959f5
leaq 0x20(%rsp), %rdi
callq 0x64d0
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x9da6
leaq 0x20(%rsp), %rdi
callq 0x6548
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %r14
leaq 0x39e60(%rip), %rsi     # 0x8f6a9
movq %rsp, %rdi
leaq 0x58(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
movq %rsp, %rsi
movq %r14, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0x91553(%rip), %rsi     # 0xe6dc0
movq 0x9276c(%rip), %rdx     # 0xe7fe0
movq %r14, %rdi
callq 0x6490
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6548
testb %bpl, %bpl
jne 0x55891
jmp 0x558ed
movq %rax, %rbx
movq %r14, %rdi
callq 0x6200
jmp 0x558ed
jmp 0x558dd
jmp 0x558ea
jmp 0x558dd
jmp 0x558ea
jmp 0x558dd
jmp 0x558ea
jmp 0x558dd
jmp 0x558ea
jmp 0x558ea
jmp 0x558ea
movq %rax, %rbx
jmp 0x558c6
jmp 0x558ea
movq %rax, %rbx
jmp 0x558d0
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6548
leaq 0x78(%rsp), %rdi
callq 0x6548
leaq 0x58(%rsp), %rdi
jmp 0x558e3
jmp 0x558ea
jmp 0x558ea
jmp 0x558ea
movq %rax, %rbx
movq %rsp, %rdi
callq 0x6548
jmp 0x558ed
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x64b0
nop