// File: /workspace/github_cpp_makefile_star2_O3/rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::emit_declared_builtin_block(spv::StorageClass, spv::ExecutionModel)
void CompilerGLSL::emit_declared_builtin_block(StorageClass storage, ExecutionModel model)
{
	Bitset emitted_builtins;
	Bitset global_builtins;
	const SPIRVariable *block_var = nullptr;
	bool emitted_block = false;
	bool builtin_array = false;

	// Need to use declared size in the type.
	// These variables might have been declared, but not statically used, so we haven't deduced their size yet.
	uint32_t cull_distance_size = 0;
	uint32_t clip_distance_size = 0;

	for (auto &id : ir.ids)
	{
		if (id.get_type() != TypeVariable)
			continue;

		auto &var = id.get<SPIRVariable>();
		auto &type = get<SPIRType>(var.basetype);
		bool block = has_decoration(type.self, DecorationBlock);
		Bitset builtins;

		if (var.storage == storage && block && is_builtin_variable(var))
		{
			uint32_t index = 0;
			for (auto &m : ir.meta[type.self].members)
			{
				if (m.builtin)
				{
					builtins.set(m.builtin_type);
					if (m.builtin_type == BuiltInCullDistance)
						cull_distance_size = get<SPIRType>(type.member_types[index]).array.front();
					else if (m.builtin_type == BuiltInClipDistance)
						clip_distance_size = get<SPIRType>(type.member_types[index]).array.front();
				}
				index++;
			}
		}
		else if (var.storage == storage && !block && is_builtin_variable(var))
		{
			// While we're at it, collect all declared global builtins (HLSL mostly ...).
			auto &m = ir.meta[var.self].decoration;
			if (m.builtin)
			{
				global_builtins.set(m.builtin_type);
				if (m.builtin_type == BuiltInCullDistance)
					cull_distance_size = type.array.front();
				else if (m.builtin_type == BuiltInClipDistance)
					clip_distance_size = type.array.front();
			}
		}

		if (builtins.empty())
			continue;

		if (emitted_block)
			SPIRV_CROSS_THROW("Cannot use more than one builtin I/O block.");

		emitted_builtins = builtins;
		emitted_block = true;
		builtin_array = !type.array.empty();
		block_var = &var;
	}

	global_builtins =
	    Bitset(global_builtins.get_lower() & ((1ull << BuiltInPosition) | (1ull << BuiltInPointSize) |
	                                          (1ull << BuiltInClipDistance) | (1ull << BuiltInCullDistance)));

	// Try to collect all other declared builtins.
	if (!emitted_block)
		emitted_builtins = global_builtins;

	// Can't declare an empty interface block.
	if (emitted_builtins.empty())
		return;

	if (storage == StorageClassOutput)
		statement("out gl_PerVertex");
	else
		statement("in gl_PerVertex");

	begin_scope();
	if (emitted_builtins.get(BuiltInPosition))
		statement("vec4 gl_Position;");
	if (emitted_builtins.get(BuiltInPointSize))
		statement("float gl_PointSize;");
	if (emitted_builtins.get(BuiltInClipDistance))
		statement("float gl_ClipDistance[", clip_distance_size, "];");
	if (emitted_builtins.get(BuiltInCullDistance))
		statement("float gl_CullDistance[", cull_distance_size, "];");

	bool tessellation = model == ExecutionModelTessellationEvaluation || model == ExecutionModelTessellationControl;
	if (builtin_array)
	{
		// Make sure the array has a supported name in the code.
		if (storage == StorageClassOutput)
			set_name(block_var->self, "gl_out");
		else if (storage == StorageClassInput)
			set_name(block_var->self, "gl_in");

		if (model == ExecutionModelTessellationControl && storage == StorageClassOutput)
			end_scope_decl(join(to_name(block_var->self), "[", get_entry_point().output_vertices, "]"));
		else
			end_scope_decl(join(to_name(block_var->self), tessellation ? "[gl_MaxPatchVertices]" : "[]"));
	}
	else
		end_scope_decl();
	statement("");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl %edx, 0x18(%rsp)
movl %esi, %r13d
movq %rdi, %r15
xorl %r12d, %r12d
leaq 0xb0(%rsp), %rax
movq %r12, -0x8(%rax)
leaq 0xe0(%rsp), %rax
movq %rax, -0x30(%rax)
movl $0x1, %ecx
movq %rcx, -0x28(%rax)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rax)
movl $0x3f800000, %edx       # imm = 0x3F800000
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
leaq 0xf0(%rsp), %rax
movq %r12, -0x8(%rax)
leaq 0x120(%rsp), %rax
movq %rax, -0x30(%rax)
movq %rcx, -0x28(%rax)
movups %xmm0, -0x20(%rax)
movl %edx, -0x10(%rax)
movups %xmm0, -0x8(%rax)
movl %r12d, 0xc(%rsp)
movl %r12d, 0x8(%rsp)
movq 0x20(%rdi), %r14
movq 0x28(%rdi), %rax
cmpq %rax, %r14
je 0x3391c
xorl %r12d, %r12d
movq $0x0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
movq %r15, 0x10(%rsp)
movl %r13d, 0x1c(%rsp)
movq %rax, 0x98(%rsp)
cmpl $0x2, 0x8(%r14)
jne 0x33902
movq %r14, %rdi
callq 0xb2a4
movq %rax, %rbp
movl 0xc(%rax), %esi
movq %r15, %rdi
callq 0xa3ea
movq %rax, %rbx
movq %r12, 0xa0(%rsp)
movl 0x8(%rax), %esi
movq %r15, %rdi
movl $0x2, %edx
callq 0x12974
movl %eax, %r12d
movq $0x0, 0x40(%rsp)
leaq 0x78(%rsp), %rax
movq %rax, 0x48(%rsp)
movq $0x1, 0x50(%rsp)
leaq 0x48(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl $0x3f800000, 0x68(%rsp) # imm = 0x3F800000
movups %xmm0, 0x28(%rax)
movl 0x10(%rbp), %eax
cmpl %r13d, %eax
setne %cl
movl %r12d, %edx
xorb $0x1, %dl
orb %cl, %dl
jne 0x337cf
movq %r15, %rdi
movq %rbp, %rsi
callq 0x13330
testb %al, %al
je 0x337c7
movl 0x8(%rbx), %eax
movq 0x38(%r15), %rcx
imulq $0x148, %rax, %rax      # imm = 0x148
movq 0xd0(%rcx,%rax), %r12
movq 0xd8(%rcx,%rax), %r13
cmpq %r13, %r12
je 0x33880
xorl %r15d, %r15d
cmpb $0x1, 0xcc(%r12)
jne 0x337af
movl 0xa0(%r12), %ecx
movl %ecx, 0x88(%rsp)
cmpq $0x3f, %rcx
ja 0x33743
movl $0x1, %eax
shlq %cl, %rax
orq %rax, 0x40(%rsp)
jmp 0x33767
leaq 0x48(%rsp), %rdi
movq %rdi, 0x20(%rsp)
leaq 0x88(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x1f510
movl 0xa0(%r12), %ecx
cmpl $0x3, %ecx
je 0x33791
cmpl $0x4, %ecx
jne 0x337af
movl %r15d, %eax
movq 0x68(%rbx), %rcx
movl (%rcx,%rax,4), %esi
movq 0x10(%rsp), %rdi
callq 0xa3ea
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
jmp 0x337af
movl %r15d, %eax
movq 0x68(%rbx), %rcx
movl (%rcx,%rax,4), %esi
movq 0x10(%rsp), %rdi
callq 0xa3ea
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, 0x8(%rsp)
incl %r15d
addq $0xd0, %r12
cmpq %r13, %r12
jne 0x33710
jmp 0x33880
movl 0x10(%rbp), %eax
movl 0x1c(%rsp), %r13d
cmpl %r13d, %eax
setne %al
orb %al, %r12b
jne 0x33880
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x13330
testb %al, %al
je 0x33880
movl 0x8(%rbp), %eax
movq 0x10(%rsp), %rcx
movq 0x38(%rcx), %r15
imulq $0x148, %rax, %rax      # imm = 0x148
cmpb $0x1, 0xcc(%r15,%rax)
jne 0x33880
addq %rax, %r15
movl 0xa0(%r15), %ecx
movl %ecx, 0x88(%rsp)
cmpq $0x3f, %rcx
ja 0x3383a
movl $0x1, %eax
shlq %cl, %rax
orq %rax, 0xe8(%rsp)
jmp 0x33859
leaq 0xf0(%rsp), %rdi
movq %rdi, 0x20(%rsp)
leaq 0x88(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x1f510
movl 0xa0(%r15), %eax
cmpl $0x3, %eax
je 0x33876
cmpl $0x4, %eax
jne 0x33880
movq 0x20(%rbx), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
jmp 0x33880
movq 0x20(%rbx), %rax
movl (%rax), %eax
movl %eax, 0x8(%rsp)
movq 0x40(%rsp), %rax
movq 0x60(%rsp), %rcx
orq %rax, %rcx
jne 0x3389e
movq 0x10(%rsp), %r15
movq 0xa0(%rsp), %r12
jmp 0x338eb
testb $0x1, 0x80(%rsp)
movq 0x10(%rsp), %r15
jne 0x33caa
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x1d5b4
movq 0x20(%rbx), %rax
cmpq 0x28(%rbx), %rax
setne %al
movq %rax, 0x90(%rsp)
movb $0x1, %al
movq %rax, 0x80(%rsp)
movq %rbp, %r12
leaq 0x48(%rsp), %rdi
callq 0xd570
movl 0x1c(%rsp), %r13d
movq 0x98(%rsp), %rax
addq $0x10, %r14
cmpq %rax, %r14
jne 0x33649
movq 0xe8(%rsp), %rax
andl $0x1b, %eax
jmp 0x33936
xorl %eax, %eax
movq $0x0, 0x90(%rsp)
movq $0x0, 0x80(%rsp)
leaq 0x48(%rsp), %rbx
movq %rax, -0x8(%rbx)
leaq 0x78(%rsp), %rcx
movq %rcx, -0x30(%rcx)
movq $0x1, -0x28(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rcx)
movl $0x3f800000, -0x10(%rcx) # imm = 0x3F800000
movups %xmm0, -0x8(%rcx)
movq %rax, 0xe8(%rsp)
leaq 0xf0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6728
movq %rbx, %rdi
callq 0xd570
testb $0x1, 0x80(%rsp)
jne 0x339af
movq 0xe8(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
movq %r14, %rsi
callq 0x1d5b4
movq 0xc8(%rsp), %rax
orq 0xa8(%rsp), %rax
je 0x33c83
cmpl $0x3, %r13d
jne 0x339dc
leaq 0x84520(%rip), %rsi     # 0xb7ef2
movq %r15, %rdi
callq 0xccac
jmp 0x339eb
leaq 0x84520(%rip), %rsi     # 0xb7f03
movq %r15, %rdi
callq 0xc6ae
leaq 0x871e5(%rip), %rsi     # 0xbabd7
movq %r15, %rdi
callq 0x59e02
incl 0x638(%r15)
movq 0xa8(%rsp), %rax
testb $0x1, %al
je 0x33a24
leaq 0x844ff(%rip), %rsi     # 0xb7f13
movq %r15, %rdi
callq 0xb730
movq 0xa8(%rsp), %rax
testb $0x2, %al
je 0x33a3f
leaq 0x844f6(%rip), %rsi     # 0xb7f25
movq %r15, %rdi
callq 0xc446
movq 0xa8(%rsp), %rax
testb $0x8, %al
je 0x33a66
leaq 0x84516(%rip), %rsi     # 0xb7f60
leaq 0x89091(%rip), %rcx     # 0xbcae2
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x528fc
movq 0xa8(%rsp), %rax
testb $0x10, %al
je 0x33a85
leaq 0x84507(%rip), %rsi     # 0xb7f78
leaq 0x8906a(%rip), %rcx     # 0xbcae2
leaq 0xc(%rsp), %rdx
movq %r15, %rdi
callq 0x528fc
testb $0x1, 0x90(%rsp)
je 0x33b7d
cmpl $0x3, %r13d
jne 0x33b8a
movl 0x8(%r12), %ebx
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x84487(%rip), %rsi     # 0xb7f39
leaq 0x84486(%rip), %rdx     # 0xb7f3f
leaq 0x40(%rsp), %rdi
callq 0x7be0
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movl %ebx, %esi
callq 0x14a44
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x33ae9
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x6260
cmpl $0x1, 0x18(%rsp)
jne 0x33bdc
movl 0x8(%r12), %edx
movq (%r15), %rax
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
movq %r15, %rdi
callq 0x15f76
addq $0xb4, %rax
leaq 0x8f1cb(%rip), %rdx     # 0xc2cec
leaq 0x8a016(%rip), %r8      # 0xbdb3e
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %rax, %rcx
callq 0x52a5a
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x2b486
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x33b5e
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
leaq 0xf0(%rsp), %r14
jne 0x33c67
jmp 0x33c74
movq %r15, %rdi
callq 0x28270
jmp 0x33c74
cmpl $0x1, %r13d
jne 0x33bdc
movl 0x8(%r12), %ebx
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x8439b(%rip), %rsi     # 0xb7f40
leaq 0x84399(%rip), %rdx     # 0xb7f45
leaq 0x40(%rsp), %rdi
callq 0x7be0
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movl %ebx, %esi
callq 0x14a44
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x33bdc
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x6260
movl 0x8(%r12), %edx
movq (%r15), %rax
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
movl 0x18(%rsp), %eax
decl %eax
cmpl $0x2, %eax
leaq 0x84342(%rip), %rax     # 0xb7f46
leaq 0x84351(%rip), %rcx     # 0xb7f5c
cmovbq %rax, %rcx
leaq 0x88(%rsp), %rdx
movq %rcx, (%rdx)
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x52b05
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
leaq 0xf0(%rsp), %r14
callq 0x2b486
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x33c59
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x33c74
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x80c34(%rip), %rsi     # 0xb48af
movq %r15, %rdi
callq 0xa6c4
movq %r14, %rdi
callq 0xd570
leaq 0xb0(%rsp), %rdi
callq 0xd570
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x841ff(%rip), %rsi     # 0xb7ec6
leaq 0x84223(%rip), %rdx     # 0xb7ef1
leaq 0x20(%rsp), %rdi
callq 0x7be0
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0xc80d9(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0xc80b1(%rip), %rsi     # 0xfbdb0
movq 0xc92d2(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
jne 0x33d59
jmp 0x33d6b
jmp 0x33dca
jmp 0x33d2b
jmp 0x33dca
jmp 0x33d68
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x33dde
movq 0x50(%rsp), %rsi
jmp 0x33d7e
jmp 0x33dca
movq %rax, %rbx
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x33d6b
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x33d6b
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x33dde
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x33dde
jmp 0x33dca
jmp 0x33dd1
jmp 0x33dca
movq %rax, %rdi
callq 0xd549
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x33db0
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
jne 0x33dba
jmp 0x33dd4
movq %rax, %rbx
movq %r14, %rdi
callq 0x6200
jmp 0x33dd4
jmp 0x33dca
jmp 0x33dca
jmp 0x33dca
movq %rax, %rbx
jmp 0x33dde
jmp 0x33dd1
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xd570
leaq 0xf0(%rsp), %rdi
callq 0xd570
leaq 0xb0(%rsp), %rdi
callq 0xd570
movq %rbx, %rdi
callq 0x64a0