// File: /workspace/github_cpp_makefile_star2_O1/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 0x162fc
movl %eax, 0x2c(%rsp)
movq 0x20(%rbx), %r14
movq 0x28(%rbx), %rax
movq %rax, 0x98(%rsp)
xorl %r12d, %r12d
cmpq %rax, %r14
je 0x8d4ad
leaq 0x50(%rsp), %r13
movl 0x8(%r14), %eax
cmpl $0xa, %eax
je 0x8d34f
cmpl $0x3, %eax
jne 0x8d42b
movq %r14, %rdi
callq 0x1be66
cmpb $0x1, 0x108(%rax)
jne 0x8d42b
movq %rax, %rbp
movl 0x2c(%rsp), %eax
cmpl %eax, 0x8(%rbp)
je 0x8d42b
movl 0xc(%rbp), %esi
movq %rbx, %rdi
callq 0xa426
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 0xe480
leaq 0x78(%rsp), %r15
movq %r13, %rdi
leaq 0x35ff3(%rip), %rsi     # 0xc326e
callq 0x64e0
cmpl $0x27d8, 0x7d0(%rbx)    # imm = 0x27D8
jb 0x8d43f
movl 0x8(%rbp), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x1299a
testb %al, %al
je 0x8d43f
movl 0x8(%rbp), %esi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x14ff6
movl %eax, 0x74(%rsp)
movq %rbx, %rdi
leaq 0x35f97(%rip), %rsi     # 0xc325d
leaq 0x30(%rsp), %rdx
leaq 0x285dc(%rip), %rcx     # 0xb58ae
movq %r13, %r8
leaq 0x35f97(%rip), %r9      # 0xc3273
leaq 0x35fa6(%rip), %rax     # 0xc3289
pushq %rax
leaq 0x7c(%rsp), %rax
pushq %rax
callq 0xa60e4
addq $0x10, %rsp
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2e53a
movq %rbx, %rdi
leaq 0x35f52(%rip), %rsi     # 0xc325d
leaq 0x30(%rsp), %rdx
leaq 0x28597(%rip), %rcx     # 0xb58ae
leaq 0x8(%rsp), %r8
leaq 0x35f6b(%rip), %r9      # 0xc328e
leaq 0x327bf(%rip), %rax     # 0xbfae9
pushq %rax
pushq %r15
leaq 0x28036(%rip), %rax     # 0xb536a
pushq %rax
pushq %r13
leaq 0x35f71(%rip), %rax     # 0xc32af
pushq %rax
pushq %r13
callq 0xa6220
addq $0x30, %rsp
jmp 0x8d482
movq %r13, %r15
movq %r14, %rdi
callq 0x25f0e
movq %rax, %rbp
movl 0x28(%rax), %esi
movq %rbx, %rdi
callq 0xa426
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 0x2d3f6
movq %rbx, %rdi
leaq 0x35ea4(%rip), %rsi     # 0xc325d
leaq 0x8(%rsp), %rdx
leaq 0x3268d(%rip), %rcx     # 0xbfa52
movq %r13, %r8
leaq 0x3271a(%rip), %r9      # 0xbfae9
callq 0xa5f2c
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x8d3f0
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x8d40c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8d428
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6260
movb $0x1, %r12b
addq $0x10, %r14
cmpq 0x98(%rsp), %r14
jne 0x8d1da
jmp 0x8d4ad
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2e53a
movq %rbx, %rdi
leaq 0x35e06(%rip), %rsi     # 0xc325d
leaq 0x30(%rsp), %rdx
leaq 0x2844b(%rip), %rcx     # 0xb58ae
leaq 0x8(%rsp), %r8
leaq 0x325e3(%rip), %r9      # 0xbfa52
leaq 0x32673(%rip), %rax     # 0xbfae9
pushq %rax
pushq %r15
callq 0xa6416
addq $0x10, %rsp
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x8d3d4
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x8d3d4
movl 0x2c(%rsp), %ebp
testl %ebp, %ebp
je 0x8d54e
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 0x1c66e
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2e53a
leaq 0x35dbf(%rip), %rsi     # 0xc32b4
leaq 0x32556(%rip), %rcx     # 0xbfa52
leaq 0x325e6(%rip), %r9      # 0xbfae9
leaq 0x30(%rsp), %rdx
leaq 0x8(%rsp), %r8
movq %rbx, %rdi
callq 0xa6552
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8d530
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8d54b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6260
movb $0x1, %r12b
testb $0x1, %r12b
je 0x8d563
leaq 0x28354(%rip), %rsi     # 0xb58af
movq %rbx, %rdi
callq 0xa700
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8d5ab
jmp 0x8d5df
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8d5a0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x8d5a0
jmp 0x8d5df
jmp 0x8d5df
movq %rax, %rbx
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x8d629
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x8d5e2
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x8d5e2
jmp 0x8d5df
jmp 0x8d5df
jmp 0x8d600
jmp 0x8d5da
movq %rax, %rbx
jmp 0x8d61f
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x8d603
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x8d603
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x8d61f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x8d63b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0
nop