// File: /workspace/github_cpp_makefile_star2_O1/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, 0x20(%rsp)
movl %esi, %r13d
movq %rdi, %r15
xorl %esi, %esi
leaq 0xb0(%rsp), %rax
movq %rsi, -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 %rsi, -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 %esi, 0xc(%rsp)
movl %esi, 0x8(%rsp)
movq 0x20(%rdi), %r14
movq 0x28(%rdi), %rax
cmpq %rax, %r14
je 0x33fc3
movq $0x0, 0x10(%rsp)
movq $0x0, 0x88(%rsp)
movq $0x0, 0x98(%rsp)
movq %r15, 0x18(%rsp)
movl %r13d, 0x24(%rsp)
movq %rax, 0xa0(%rsp)
cmpl $0x2, 0x8(%r14)
jne 0x33fb4
movq %r14, %rdi
callq 0xb2e2
movq %rax, %rbp
movl 0xc(%rax), %esi
movq %r15, %rdi
callq 0xa426
movq %rax, %rbx
movl 0x8(%rax), %esi
movq %r15, %rdi
movl $0x2, %edx
callq 0x1299a
movl %eax, %r12d
movq $0x0, 0x48(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x50(%rsp)
movq $0x1, 0x58(%rsp)
leaq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl $0x3f800000, 0x70(%rsp) # imm = 0x3F800000
movups %xmm0, 0x28(%rax)
cmpl %r13d, 0x10(%rbp)
setne %al
movl %r12d, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0x33e81
movq %r15, %rdi
movq %rbp, %rsi
callq 0x133a2
testb %al, %al
je 0x33e81
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 0x33f33
xorl %r15d, %r15d
cmpb $0x1, 0xcc(%r12)
jne 0x33e69
movl 0xa0(%r12), %ecx
movl %ecx, 0x90(%rsp)
cmpq $0x3f, %rcx
ja 0x33dfd
movl $0x1, %eax
shlq %cl, %rax
orq %rax, 0x48(%rsp)
jmp 0x33e19
leaq 0x50(%rsp), %rdi
movq %rdi, 0x28(%rsp)
leaq 0x90(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x1fc02
movl 0xa0(%r12), %eax
cmpl $0x3, %eax
je 0x33e4b
cmpl $0x4, %eax
jne 0x33e69
movl %r15d, %eax
movq 0x68(%rbx), %rcx
movl (%rcx,%rax,4), %esi
movq 0x18(%rsp), %rdi
callq 0xa426
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
jmp 0x33e69
movl %r15d, %eax
movq 0x68(%rbx), %rcx
movl (%rcx,%rax,4), %esi
movq 0x18(%rsp), %rdi
callq 0xa426
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, 0x8(%rsp)
incl %r15d
addq $0xd0, %r12
cmpq %r13, %r12
jne 0x33dca
jmp 0x33f33
cmpl %r13d, 0x10(%rbp)
setne %al
orb %al, %r12b
jne 0x33f33
movq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x133a2
testb %al, %al
je 0x33f33
movl 0x8(%rbp), %eax
movq 0x18(%rsp), %rcx
movq 0x38(%rcx), %r15
imulq $0x148, %rax, %rax      # imm = 0x148
cmpb $0x1, 0xcc(%r15,%rax)
jne 0x33f33
addq %rax, %r15
movl 0xa0(%r15), %ecx
movl %ecx, 0x90(%rsp)
cmpq $0x3f, %rcx
ja 0x33eed
movl $0x1, %eax
shlq %cl, %rax
orq %rax, 0xe8(%rsp)
jmp 0x33f0c
leaq 0xf0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
leaq 0x90(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x1fc02
movl 0xa0(%r15), %eax
cmpl $0x3, %eax
je 0x33f29
cmpl $0x4, %eax
jne 0x33f33
movq 0x20(%rbx), %rax
movl (%rax), %eax
movl %eax, 0xc(%rsp)
jmp 0x33f33
movq 0x20(%rbx), %rax
movl (%rax), %eax
movl %eax, 0x8(%rsp)
movq 0x48(%rsp), %rax
movq 0x68(%rsp), %rcx
orq %rax, %rcx
jne 0x33f4e
movq 0x18(%rsp), %r15
movl 0x24(%rsp), %r13d
jmp 0x33fa2
testb $0x1, 0x88(%rsp)
movq 0x18(%rsp), %r15
jne 0x3431e
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x1dcd0
movl 0x24(%rsp), %r13d
movq 0x20(%rbx), %rax
cmpq 0x28(%rbx), %rax
setne %al
movq %rax, 0x98(%rsp)
movb $0x1, %al
movq %rax, 0x88(%rsp)
movq %rbp, 0x10(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xd5b0
movq 0xa0(%rsp), %rax
addq $0x10, %r14
cmpq %rax, %r14
jne 0x33d0a
jmp 0x33fe4
movq $0x0, 0x10(%rsp)
movq $0x0, 0x98(%rsp)
movq $0x0, 0x88(%rsp)
movq 0xe8(%rsp), %rax
andl $0x1b, %eax
leaq 0x50(%rsp), %rbx
movq %rax, -0x8(%rbx)
leaq 0x80(%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 0x6734
movq %rbx, %rdi
callq 0xd5b0
testb $0x1, 0x88(%rsp)
jne 0x3406b
movq 0xe8(%rsp), %rax
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
movq %r14, %rsi
callq 0x1dcd0
movq 0xc8(%rsp), %rax
orq 0xa8(%rsp), %rax
je 0x342f7
cmpl $0x3, %r13d
jne 0x34098
leaq 0x84e74(%rip), %rsi     # 0xb8f02
movq %r15, %rdi
callq 0xccec
jmp 0x340a7
leaq 0x84e74(%rip), %rsi     # 0xb8f13
movq %r15, %rdi
callq 0xc6ee
leaq 0x87b39(%rip), %rsi     # 0xbbbe7
movq %r15, %rdi
callq 0x5a5fc
incl 0x638(%r15)
testb $0x1, 0xa8(%rsp)
je 0x340d6
leaq 0x84e55(%rip), %rsi     # 0xb8f23
movq %r15, %rdi
callq 0xb770
testb $0x2, 0xa8(%rsp)
je 0x340ef
leaq 0x84e4e(%rip), %rsi     # 0xb8f35
movq %r15, %rdi
callq 0xc486
testb $0x8, 0xa8(%rsp)
je 0x34114
leaq 0x84e70(%rip), %rsi     # 0xb8f70
leaq 0x899d3(%rip), %rcx     # 0xbdada
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x530f4
testb $0x10, 0xa8(%rsp)
je 0x34139
leaq 0x84e63(%rip), %rsi     # 0xb8f88
leaq 0x899ae(%rip), %rcx     # 0xbdada
leaq 0xc(%rsp), %rdx
movq %r15, %rdi
callq 0x530f4
testb $0x1, 0x98(%rsp)
je 0x34183
cmpl $0x3, %r13d
jne 0x34190
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ebx
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x84de8(%rip), %rsi     # 0xb8f49
leaq 0x84de7(%rip), %rdx     # 0xb8f4f
leaq 0x48(%rsp), %rdi
callq 0x7c64
leaq 0x48(%rsp), %rdx
movq %r15, %rdi
movl %ebx, %esi
callq 0x14bd2
jmp 0x341ce
movq %r15, %rdi
callq 0x2889c
jmp 0x342e8
cmpl $0x1, %r13d
jne 0x341ed
movq 0x10(%rsp), %rax
movl 0x8(%rax), %ebx
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x84da2(%rip), %rsi     # 0xb8f50
leaq 0x84da0(%rip), %rdx     # 0xb8f55
leaq 0x48(%rsp), %rdi
callq 0x7c64
leaq 0x48(%rsp), %rdx
movq %r15, %rdi
movl %ebx, %esi
callq 0x14bd2
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x341e5
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0xf0(%rsp), %r14
movl 0x20(%rsp), %eax
xorl $0x1, %eax
xorl $0x3, %r13d
orl %eax, %r13d
jne 0x34255
movq 0x10(%rsp), %rax
movl 0x8(%rax), %edx
movq (%r15), %rax
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
movq %r15, %rdi
callq 0x16254
addq $0xb4, %rax
leaq 0x8faef(%rip), %rdx     # 0xc3d1c
leaq 0x8a902(%rip), %r8      # 0xbeb36
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq %rax, %rcx
callq 0x53252
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x2ba8e
jmp 0x342b2
movq 0x10(%rsp), %rax
movl 0x8(%rax), %edx
movq (%r15), %rax
leaq 0x28(%rsp), %rdi
movq %r15, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
movl 0x20(%rsp), %eax
decl %eax
cmpl $0x2, %eax
leaq 0x84cd6(%rip), %rax     # 0xb8f56
leaq 0x84ce5(%rip), %rcx     # 0xb8f6c
cmovbq %rax, %rcx
leaq 0x90(%rsp), %rdx
movq %rcx, (%rdx)
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x532fd
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x2ba8e
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x342cd
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x342e8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x815c0(%rip), %rsi     # 0xb58af
movq %r15, %rdi
callq 0xa700
movq %r14, %rdi
callq 0xd5b0
leaq 0xb0(%rsp), %rdi
callq 0xd5b0
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 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x84b9b(%rip), %rsi     # 0xb8ed6
leaq 0x84bbf(%rip), %rdx     # 0xb8f01
leaq 0x28(%rsp), %rdi
callq 0x7c64
movb $0x1, %bpl
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0xc8a35(%rip), %rax     # 0xfcd98
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0xc8a0d(%rip), %rsi     # 0xfcd80
movq 0xc9c5e(%rip), %rdx     # 0xfdfd8
movq %r14, %rdi
callq 0x6470
jmp 0x343b1
jmp 0x3442e
jmp 0x3438b
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x343ce
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x343ce
jmp 0x343cb
jmp 0x3442e
jmp 0x3442e
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x34442
movq 0x58(%rsp), %rsi
jmp 0x343e1
jmp 0x3442e
movq %rax, %rbx
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x34442
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x34442
jmp 0x34435
jmp 0x3442e
movq %rax, %rdi
callq 0xd589
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x34419
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x34419
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x34438
movq %r14, %rdi
callq 0x6200
jmp 0x34438
jmp 0x3442e
jmp 0x3442e
jmp 0x3442e
movq %rax, %rbx
jmp 0x34442
jmp 0x34435
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xd5b0
leaq 0xf0(%rsp), %rdi
callq 0xd5b0
leaq 0xb0(%rsp), %rdi
callq 0xd5b0
movq %rbx, %rdi
callq 0x64a0