// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::emit_buffer_block_native(spirv_cross::SPIRVariable const&)
void CompilerGLSL::emit_buffer_block_native(const SPIRVariable &var)
{
	auto &type = get<SPIRType>(var.basetype);

	Bitset flags = ir.get_buffer_block_flags(var);
	bool ssbo = var.storage == StorageClassStorageBuffer ||
	            ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock);
	bool is_restrict = ssbo && flags.get(DecorationRestrict);
	bool is_writeonly = ssbo && flags.get(DecorationNonReadable);
	bool is_readonly = ssbo && flags.get(DecorationNonWritable);
	bool is_coherent = ssbo && flags.get(DecorationCoherent);

	// Block names should never alias, but from HLSL input they kind of can because block types are reused for UAVs ...
	auto buffer_name = to_name(type.self, false);

	auto &block_namespace = ssbo ? block_ssbo_names : block_ubo_names;

	// Shaders never use the block by interface name, so we don't
	// have to track this other than updating name caches.
	if (ir.meta[type.self].decoration.alias.empty() || block_namespace.find(buffer_name) != end(block_namespace))
		buffer_name = get_block_fallback_name(var.self);

	// Make sure we get something unique.
	add_variable(block_namespace, buffer_name);

	// If for some reason buffer_name is an illegal name, make a final fallback to a workaround name.
	// This cannot conflict with anything else, so we're safe now.
	if (buffer_name.empty())
		buffer_name = join("_", get<SPIRType>(var.basetype).self, "_", var.self);

	// Instance names cannot alias block names.
	resource_names.insert(buffer_name);

	// Save for post-reflection later.
	declared_block_names[var.self] = buffer_name;

	statement(layout_for_variable(var), is_coherent ? "coherent " : "", is_restrict ? "restrict " : "",
	          is_writeonly ? "writeonly " : "", is_readonly ? "readonly " : "", ssbo ? "buffer " : "uniform ",
	          buffer_name);

	begin_scope();

	type.member_name_cache.clear();

	uint32_t i = 0;
	for (auto &member : type.member_types)
	{
		add_member_name(type, i);
		emit_struct_member(type, member, i);
		i++;
	}

	add_resource_name(var.self);
	end_scope_decl(to_name(var.self) + type_to_array_glsl(type));
	statement("");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x200(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq -0x200(%rbp), %rsi
movq %rax, -0x18(%rbp)
addq $0x8, %rsi
movq -0x10(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x54c20
movq -0x10(%rbp), %rcx
movb $0x1, %al
cmpl $0xc, 0x10(%rcx)
movb %al, -0x1f1(%rbp)
je 0x609e8
movq -0x200(%rbp), %rdi
addq $0x38, %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0x60, %rdi
movl $0x3, %esi
callq 0xef50
movb %al, -0x201(%rbp)
jmp 0x609da
movb -0x201(%rbp), %al
movb %al, -0x1f1(%rbp)
jmp 0x609e8
movb -0x1f1(%rbp), %al
andb $0x1, %al
movb %al, -0x59(%rbp)
xorl %eax, %eax
testb $0x1, -0x59(%rbp)
movb %al, -0x202(%rbp)
je 0x60a25
leaq -0x58(%rbp), %rdi
movl $0x13, %esi
callq 0xef50
movb %al, -0x203(%rbp)
jmp 0x60a17
movb -0x203(%rbp), %al
movb %al, -0x202(%rbp)
jmp 0x60a25
movb -0x202(%rbp), %al
andb $0x1, %al
movb %al, -0x6d(%rbp)
xorl %eax, %eax
testb $0x1, -0x59(%rbp)
movb %al, -0x204(%rbp)
je 0x60a62
leaq -0x58(%rbp), %rdi
movl $0x19, %esi
callq 0xef50
movb %al, -0x205(%rbp)
jmp 0x60a54
movb -0x205(%rbp), %al
movb %al, -0x204(%rbp)
jmp 0x60a62
movb -0x204(%rbp), %al
andb $0x1, %al
movb %al, -0x6e(%rbp)
xorl %eax, %eax
testb $0x1, -0x59(%rbp)
movb %al, -0x206(%rbp)
je 0x60a9f
leaq -0x58(%rbp), %rdi
movl $0x18, %esi
callq 0xef50
movb %al, -0x207(%rbp)
jmp 0x60a91
movb -0x207(%rbp), %al
movb %al, -0x206(%rbp)
jmp 0x60a9f
movb -0x206(%rbp), %al
andb $0x1, %al
movb %al, -0x6f(%rbp)
xorl %eax, %eax
testb $0x1, -0x59(%rbp)
movb %al, -0x208(%rbp)
je 0x60adc
leaq -0x58(%rbp), %rdi
movl $0x17, %esi
callq 0xef50
movb %al, -0x209(%rbp)
jmp 0x60ace
movb -0x209(%rbp), %al
movb %al, -0x208(%rbp)
jmp 0x60adc
movq -0x200(%rbp), %rsi
movb -0x208(%rbp), %al
andb $0x1, %al
movb %al, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0x90(%rbp), %rdi
xorl %ecx, %ecx
callq *%rax
jmp 0x60b09
testb $0x1, -0x59(%rbp)
je 0x60b25
movq -0x200(%rbp), %rax
addq $0x568, %rax            # imm = 0x568
movq %rax, -0x218(%rbp)
jmp 0x60b39
movq -0x200(%rbp), %rax
addq $0x530, %rax            # imm = 0x530
movq %rax, -0x218(%rbp)
movq -0x200(%rbp), %rdi
movq -0x218(%rbp), %rax
movq %rax, -0x98(%rbp)
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
callq 0x75f0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x219(%rbp)
jne 0x60be1
movq -0x98(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x2f720
movq %rax, -0x228(%rbp)
jmp 0x60b97
movq -0x228(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
callq 0x2f750
movq %rax, -0x230(%rbp)
jmp 0x60bba
movq -0x230(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x2f970
movb %al, -0x219(%rbp)
movb -0x219(%rbp), %al
testb $0x1, %al
jne 0x60bf0
jmp 0x60c72
movq -0x200(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movq (%rsi), %rax
movq 0x20(%rax), %rax
leaq -0xc8(%rbp), %rdi
callq *%rax
jmp 0x60c10
leaq -0x90(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x7050
jmp 0x60c25
leaq -0xc8(%rbp), %rdi
callq 0x7708
jmp 0x60c72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x61169
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x6115d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x7708
jmp 0x6115d
movq -0x200(%rbp), %rdi
movq -0x98(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x61180
jmp 0x60c8e
leaq -0x90(%rbp), %rdi
callq 0x75f0
testb $0x1, %al
jne 0x60ca0
jmp 0x60d06
movq -0x200(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq %rax, -0x238(%rbp)
jmp 0x60cbc
movq -0x238(%rbp), %rdx
addq $0x8, %rdx
movq -0x10(%rbp), %r8
addq $0x8, %r8
leaq 0xe7848(%rip), %rcx     # 0x14851e
leaq -0xe8(%rbp), %rdi
movq %rcx, %rsi
callq 0x9fb20
jmp 0x60ce7
leaq -0x90(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x7430
leaq -0xe8(%rbp), %rdi
callq 0x7708
movq -0x200(%rbp), %rdi
addq $0x488, %rdi            # imm = 0x488
leaq -0x90(%rbp), %rsi
callq 0x2f780
movb %dl, -0x241(%rbp)
movq %rax, -0x240(%rbp)
jmp 0x60d2f
movq -0x200(%rbp), %rdi
movb -0x241(%rbp), %al
movq -0x240(%rbp), %rcx
movq %rcx, -0xf8(%rbp)
movb %al, -0xf0(%rbp)
addq $0x3d8, %rdi            # imm = 0x3D8
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0x9fbe0
movq %rax, -0x250(%rbp)
jmp 0x60d6d
movq -0x250(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x7050
jmp 0x60d82
movq -0x200(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x118(%rbp), %rdi
callq 0x5e4c0
jmp 0x60d9b
movq -0x200(%rbp), %rdi
movb -0x70(%rbp), %cl
leaq 0xe7128(%rip), %rdx     # 0x147ed4
leaq 0xddaeb(%rip), %rax     # 0x13e89e
testb $0x1, %cl
movq %rax, %rcx
cmovneq %rdx, %rcx
movq %rcx, -0x120(%rbp)
movb -0x6d(%rbp), %cl
leaq 0xe070f(%rip), %rdx     # 0x1414dd
testb $0x1, %cl
movq %rax, %rcx
cmovneq %rdx, %rcx
movq %rcx, -0x128(%rbp)
movb -0x6e(%rbp), %cl
leaq 0xe06fe(%rip), %rdx     # 0x1414e7
testb $0x1, %cl
movq %rax, %rcx
cmovneq %rdx, %rcx
movq %rcx, -0x130(%rbp)
movb -0x6f(%rbp), %dl
leaq 0xe06ee(%rip), %rcx     # 0x1414f2
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x138(%rbp)
movb -0x59(%rbp), %dl
leaq 0xe70d8(%rip), %rcx     # 0x147ef4
leaq 0xe06d9(%rip), %rax     # 0x1414fc
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x140(%rbp)
movq %rsp, %rax
leaq -0x90(%rbp), %rcx
movq %rcx, 0x8(%rax)
leaq -0x140(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x118(%rbp), %rsi
leaq -0x120(%rbp), %rdx
leaq -0x128(%rbp), %rcx
leaq -0x130(%rbp), %r8
leaq -0x138(%rbp), %r9
callq 0x9fc10
jmp 0x60e73
leaq -0x118(%rbp), %rdi
callq 0x7708
movq -0x200(%rbp), %rdi
callq 0x5c200
jmp 0x60e8d
movq -0x18(%rbp), %rdi
addq $0xa0, %rdi
callq 0x9e1e0
movl $0x0, -0x144(%rbp)
movq -0x18(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rdi
callq 0x86d0
movq %rax, -0x158(%rbp)
movq -0x150(%rbp), %rdi
callq 0x8700
movq %rax, -0x160(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x8730
testb $0x1, %al
jne 0x60ef8
jmp 0x61036
leaq -0x158(%rbp), %rdi
callq 0x8770
movq -0x200(%rbp), %rdi
movq %rax, -0x168(%rbp)
movq -0x18(%rbp), %rsi
movl -0x144(%rbp), %edx
callq 0x5c240
jmp 0x60f23
movq -0x18(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x168(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x260(%rbp)
movl -0x144(%rbp), %eax
movl %eax, -0x25c(%rbp)
leaq -0x189(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x7650
movq -0x258(%rbp), %rdx
leaq 0xdd934(%rip), %rsi     # 0x13e89e
leaq -0x188(%rbp), %rdi
callq 0x7520
jmp 0x60f78
movl -0x25c(%rbp), %ecx
movl -0x260(%rbp), %edx
movq -0x268(%rbp), %rsi
movq -0x200(%rbp), %rdi
movq (%rdi), %rax
movq 0xa8(%rax), %rax
leaq -0x188(%rbp), %r8
xorl %r9d, %r9d
callq *%rax
jmp 0x60faa
leaq -0x188(%rbp), %rdi
callq 0x7708
leaq -0x189(%rbp), %rdi
callq 0x73d0
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x8790
jmp 0x60edc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x7708
jmp 0x6115d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x61025
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x7708
leaq -0x189(%rbp), %rdi
callq 0x73d0
jmp 0x6115d
movq -0x200(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x5c1d0
jmp 0x6104b
movq -0x200(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0x1d0(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0x61070
movq -0x200(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x1f0(%rbp), %rdi
callq 0x61340
jmp 0x61089
leaq -0x1b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
leaq -0x1f0(%rbp), %rdx
callq 0x2f7f0
jmp 0x610a5
movq -0x200(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x61240
jmp 0x610ba
leaq -0x1b0(%rbp), %rdi
callq 0x7708
leaq -0x1f0(%rbp), %rdi
callq 0x7708
leaq -0x1d0(%rbp), %rdi
callq 0x7708
movq -0x200(%rbp), %rdi
leaq 0xdd7b2(%rip), %rsi     # 0x13e89e
callq 0xedf0
jmp 0x610f3
leaq -0x90(%rbp), %rdi
callq 0x7708
leaq -0x58(%rbp), %rdi
callq 0xf250
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x61151
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x61145
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x7708
leaq -0x1f0(%rbp), %rdi
callq 0x7708
leaq -0x1d0(%rbp), %rdi
callq 0x7708
leaq -0x90(%rbp), %rdi
callq 0x7708
leaq -0x58(%rbp), %rdi
callq 0xf250
movq -0x68(%rbp), %rdi
callq 0x7640
nopl (%rax,%rax)