// File: /workspace/github_cpp_makefile_star2_O3/rossy[P]crossc/SPIRV-Cross/spirv_msl.cpp
// Function: spirv_cross::CompilerMSL::emit_specialization_constants()
void CompilerMSL::emit_specialization_constants()
{
	SpecializationConstant wg_x, wg_y, wg_z;
	uint32_t workgroup_size_id = get_work_group_size_specialization_constants(wg_x, wg_y, wg_z);
	bool emitted = false;

	for (auto &id : ir.ids)
	{
		if (id.get_type() == TypeConstant)
		{
			auto &c = id.get<SPIRConstant>();
			if (!c.specialization)
				continue;

			// If WorkGroupSize is a specialization constant, it will be declared explicitly below.
			if (c.self == workgroup_size_id)
				continue;

			auto &type = get<SPIRType>(c.constant_type);
			string sc_type_name = type_to_glsl(type);
			string sc_name = to_name(c.self);
			string sc_tmp_name = sc_name + "_tmp";

			// Function constants are only supported in MSL 1.2 and later.
			// If we don't support it just declare the "default" directly.
			// This "default" value can be overridden to the true specialization constant by the API user.
			if (msl_options.supports_msl_version(1, 2) && has_decoration(c.self, DecorationSpecId))
			{
				uint32_t constant_id = get_decoration(c.self, DecorationSpecId);
				// Only scalar, non-composite values can be function constants.
				statement("constant ", sc_type_name, " ", sc_tmp_name, " [[function_constant(", constant_id, ")]];");
				statement("constant ", sc_type_name, " ", sc_name, " = is_function_constant_defined(", sc_tmp_name,
				          ") ? ", sc_tmp_name, " : ", constant_expression(c), ";");
			}
			else
			{
				// Composite specialization constants must be built from other specialization constants.
				statement("constant ", sc_type_name, " ", sc_name, " = ", constant_expression(c), ";");
			}
			emitted = true;
		}
		else if (id.get_type() == TypeConstantOp)
		{
			auto &c = id.get<SPIRConstantOp>();
			auto &type = get<SPIRType>(c.basetype);
			auto name = to_name(c.self);
			statement("constant ", variable_decl(type, name), " = ", constant_op_expression(c), ";");
			emitted = true;
		}
	}

	// TODO: This can be expressed as a [[threads_per_threadgroup]] input semantic, but we need to know
	// the work group size at compile time in SPIR-V, and [[threads_per_threadgroup]] would need to be passed around as a global.
	// The work group size may be a specialization constant.
	if (workgroup_size_id)
	{
		statement("constant uint3 ", builtin_to_glsl(BuiltInWorkgroupSize, StorageClassWorkgroup), " = ",
		          constant_expression(get<SPIRConstant>(workgroup_size_id)), ";");
		emitted = true;
	}

	if (emitted)
		statement("");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
leaq 0xb0(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
callq 0x15fe4
movl %eax, %ebp
movq 0x20(%rbx), %r14
movq 0x28(%rbx), %rax
movq %rax, 0x98(%rsp)
cmpq %rax, %r14
je 0x8c86c
movl %ebp, 0x2c(%rsp)
xorl %r12d, %r12d
leaq 0x50(%rsp), %r13
movl 0x8(%r14), %eax
cmpl $0xa, %eax
je 0x8c6f7
cmpl $0x3, %eax
jne 0x8c7d3
movq %r14, %rdi
callq 0x1b808
cmpb $0x1, 0x108(%rax)
jne 0x8c7d3
movq %rax, %rbp
movl 0x2c(%rsp), %eax
cmpl %eax, 0x8(%rbp)
je 0x8c7d3
movl 0xc(%rbp), %esi
movq %rbx, %rdi
callq 0xa3ea
movq (%rbx), %r8
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq *0x98(%r8)
movl 0x8(%rbp), %edx
movq (%rbx), %rax
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
leaq 0x60(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0xe456
leaq 0x78(%rsp), %r15
movq %r13, %rdi
leaq 0x35c1b(%rip), %rsi     # 0xc223e
callq 0x64e0
cmpl $0x27d8, 0x7d0(%rbx)    # imm = 0x27D8
jb 0x8c7e7
movl 0x8(%rbp), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x12974
testb %al, %al
je 0x8c7e7
movl 0x8(%rbp), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x14e6e
movl %eax, 0x74(%rsp)
movq %rbx, %rdi
leaq 0x35bbf(%rip), %rsi     # 0xc222d
leaq 0x30(%rsp), %rdx
leaq 0x28234(%rip), %rcx     # 0xb48ae
movq %r13, %r8
leaq 0x35bbf(%rip), %r9      # 0xc2243
leaq 0x35bce(%rip), %rax     # 0xc2259
pushq %rax
leaq 0x7c(%rsp), %rax
pushq %rax
callq 0xa51d8
addq $0x10, %rsp
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2deba
movq %rbx, %rdi
leaq 0x35b7a(%rip), %rsi     # 0xc222d
leaq 0x30(%rsp), %rdx
leaq 0x281ef(%rip), %rcx     # 0xb48ae
leaq 0x8(%rsp), %r8
leaq 0x35b93(%rip), %r9      # 0xc225e
leaq 0x3241f(%rip), %rax     # 0xbeaf1
pushq %rax
pushq %r15
leaq 0x27c8e(%rip), %rax     # 0xb436a
pushq %rax
pushq %r13
leaq 0x35b99(%rip), %rax     # 0xc227f
pushq %rax
pushq %r13
callq 0xa5314
addq $0x30, %rsp
jmp 0x8c82a
movq %r13, %r15
movq %r14, %rdi
callq 0x2584c
movq %rax, %rbp
movl 0x28(%rax), %esi
movq %rbx, %rdi
callq 0xa3ea
movq %rax, %r12
movl 0x8(%rbp), %edx
movq (%rbx), %rax
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
movq (%rbx), %rax
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq *0xc8(%rax)
movq %r15, %r13
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2cd88
movq %rbx, %rdi
leaq 0x35acc(%rip), %rsi     # 0xc222d
leaq 0x8(%rsp), %rdx
leaq 0x322ed(%rip), %rcx     # 0xbea5a
movq %r13, %r8
leaq 0x3237a(%rip), %r9      # 0xbeaf1
callq 0xa5020
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x8c798
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x8c7b4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8c7d0
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6260
movb $0x1, %r12b
addq $0x10, %r14
cmpq 0x98(%rsp), %r14
jne 0x8c582
jmp 0x8c855
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2deba
movq %rbx, %rdi
leaq 0x35a2e(%rip), %rsi     # 0xc222d
leaq 0x30(%rsp), %rdx
leaq 0x280a3(%rip), %rcx     # 0xb48ae
leaq 0x8(%rsp), %r8
leaq 0x32243(%rip), %r9      # 0xbea5a
leaq 0x322d3(%rip), %rax     # 0xbeaf1
pushq %rax
pushq %r15
callq 0xa550a
addq $0x10, %rsp
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x8c77c
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x8c77c
movl 0x2c(%rsp), %ebp
testl %ebp, %ebp
jne 0x8c874
testb $0x1, %r12b
jne 0x8c906
jmp 0x8c915
testl %ebp, %ebp
je 0x8c915
movq (%rbx), %rax
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
movl $0x19, %edx
movl $0x4, %ecx
callq *0xa0(%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x1c036
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2deba
leaq 0x359d4(%rip), %rsi     # 0xc2284
leaq 0x321a3(%rip), %rcx     # 0xbea5a
leaq 0x32233(%rip), %r9      # 0xbeaf1
leaq 0x30(%rsp), %rdx
leaq 0x8(%rsp), %r8
movq %rbx, %rdi
callq 0xa5646
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8c8eb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8c906
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x27fa2(%rip), %rsi     # 0xb48af
movq %rbx, %rdi
callq 0xa6c4
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8c95d
jmp 0x8c991
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8c952
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x8c952
jmp 0x8c991
jmp 0x8c991
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x8c9db
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x8c994
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x8c994
jmp 0x8c991
jmp 0x8c991
jmp 0x8c9b2
jmp 0x8c98c
movq %rax, %rbx
jmp 0x8c9d1
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x8c9b5
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x8c9b5
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x8c9d1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8c9ed
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0
nop