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

	bool is_uav = var.storage == StorageClassStorageBuffer || has_decoration(type.self, DecorationBufferBlock);

	if (is_uav)
	{
		Bitset flags = ir.get_buffer_block_flags(var);
		bool is_readonly = flags.get(DecorationNonWritable);
		bool is_coherent = flags.get(DecorationCoherent);
		add_resource_name(var.self);
		statement(is_coherent ? "globallycoherent " : "", is_readonly ? "ByteAddressBuffer " : "RWByteAddressBuffer ",
		          to_name(var.self), type_to_array_glsl(type), to_resource_binding(var), ";");
	}
	else
	{
		if (type.array.empty())
		{
			if (buffer_is_packing_standard(type, BufferPackingHLSLCbufferPackOffset))
				set_decoration(type.self, DecorationCPacked);
			else
				SPIRV_CROSS_THROW("cbuffer cannot be expressed with either HLSL packing layout or packoffset.");

			// Flatten the top-level struct so we can use packoffset,
			// this restriction is similar to GLSL where layout(offset) is not possible on sub-structs.
			flattened_structs.insert(var.self);

			// Prefer the block name if possible.
			auto buffer_name = to_name(type.self, false);
			if (ir.meta[type.self].decoration.alias.empty() || resource_names.find(buffer_name) != end(resource_names))
				buffer_name = get_block_fallback_name(var.self);
			add_variable(resource_names, 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);

			resource_names.insert(buffer_name);

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

			type.member_name_cache.clear();
			add_resource_name(var.self);
			statement("cbuffer ", buffer_name, to_resource_binding(var));
			begin_scope();

			uint32_t i = 0;
			for (auto &member : type.member_types)
			{
				add_member_name(type, i);
				auto backup_name = get_member_name(type.self, i);
				auto member_name = to_member_name(type, i);
				set_member_name(type.self, i, sanitize_underscores(join(to_name(var.self), "_", member_name)));
				emit_struct_member(type, member, i, "");
				set_member_name(type.self, i, backup_name);
				i++;
			}

			end_scope_decl();
			statement("");
		}
		else
		{
			if (hlsl_options.shader_model < 51)
				SPIRV_CROSS_THROW(
				    "Need ConstantBuffer<T> to use arrays of UBOs, but this is only supported in SM 5.1.");

			// ConstantBuffer<T> does not support packoffset, so it is unuseable unless everything aligns as we expect.
			if (!buffer_is_packing_standard(type, BufferPackingHLSLCbuffer))
				SPIRV_CROSS_THROW("HLSL ConstantBuffer<T> cannot be expressed with normal HLSL packing rules.");

			add_resource_name(type.self);
			add_resource_name(var.self);

			emit_struct(get<SPIRType>(type.self));
			statement("ConstantBuffer<", to_name(type.self), "> ", to_name(var.self), type_to_array_glsl(type),
			          to_resource_binding(var), ";");
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %r12
movq %rdi, %rbx
movl 0xc(%rsi), %esi
callq 0x90a4
movq %rax, %r13
cmpl $0xc, 0x10(%r12)
je 0x544e9
movl 0x8(%r13), %esi
pushq $0x3
popq %rdx
movq %rbx, %rdi
callq 0x103d2
testb %al, %al
je 0x545f5
leaq 0x8(%rbx), %rsi
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
callq 0x1fb0a
movq (%r15), %r15
movl 0x8(%r12), %esi
movq %rbx, %rdi
callq 0x22d1a
btl $0x17, %r15d
leaq 0x3b36e(%rip), %rax     # 0x8f887
leaq 0x443d5(%rip), %rcx     # 0x988f5
cmovaeq %rax, %rcx
btl $0x18, %r15d
leaq 0x443d7(%rip), %rax     # 0x98907
leaq 0x443d2(%rip), %rdx     # 0x98909
cmovaeq %rax, %rdx
movq %rcx, 0xe8(%rsp)
movq %rdx, 0xc8(%rsp)
movl 0x8(%r12), %edx
movq (%rbx), %rax
leaq 0x10(%rsp), %rdi
pushq $0x1
popq %rcx
movq %rbx, %rsi
callq *0x38(%rax)
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2547c
leaq 0xa0(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x54cfa
subq $0x8, %rsp
leaq 0x454ef(%rip), %rax     # 0x99a81
leaq 0xf0(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
leaq 0x18(%rsp), %rcx
leaq 0x88(%rsp), %r8
leaq 0xa8(%rsp), %r9
movq %rbx, %rdi
pushq %rax
callq 0x61630
popq %rax
popq %rcx
leaq 0xa0(%rsp), %rdi
callq 0x6548
leaq 0x80(%rsp), %rdi
callq 0x6548
leaq 0x10(%rsp), %rdi
callq 0x6548
leaq 0x48(%rsp), %rdi
callq 0xb51c
jmp 0x54a7e
movq %rbx, (%rsp)
movq 0x20(%r13), %rax
cmpq 0x28(%r13), %rax
je 0x54716
movq (%rsp), %rbx
cmpl $0x32, 0x788(%rbx)
jbe 0x54a90
pushq $0x4
popq %rdx
pushq $-0x1
popq %r8
movq %rbx, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0x23b1a
testb %al, %al
je 0x54ade
movl 0x8(%r13), %esi
movq %rbx, %rdi
callq 0x22d1a
movl 0x8(%r12), %esi
movq %rbx, %rdi
callq 0x22d1a
movl 0x8(%r13), %esi
movq %rbx, %rdi
callq 0x90a4
movq %rbx, %rdi
movq %rax, %rsi
callq 0x22b86
movl 0x8(%r13), %edx
movq (%rbx), %rax
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rbp
movq %rbx, %rsi
movl %ebp, %ecx
callq *0x38(%rax)
movl 0x8(%r12), %edx
movq (%rbx), %rax
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %ecx
callq *0x38(%rax)
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2547c
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x54cfa
leaq 0x453c1(%rip), %rax     # 0x99a81
leaq 0x442fd(%rip), %rsi     # 0x989c4
leaq 0x3aaef(%rip), %rcx     # 0x8f1bd
leaq 0x40(%rsp), %rdx
leaq 0x10(%rsp), %r8
leaq 0x80(%rsp), %r9
movq %rbx, %rdi
pushq %rax
pushq %r14
callq 0x61814
popq %rax
popq %rcx
leaq 0xa0(%rsp), %rdi
callq 0x6548
leaq 0x80(%rsp), %rdi
callq 0x6548
leaq 0x10(%rsp), %rdi
callq 0x6548
jmp 0x54a74
pushq $0x5
popq %rdx
pushq $-0x1
popq %r8
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
callq 0x23b1a
testb %al, %al
je 0x54b29
movl 0x8(%r13), %esi
pushq $0xa
popq %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x1206e
leaq 0x6b0(%rbx), %rdi
leaq 0x8(%r12), %rsi
movq %rsi, 0x8(%rsp)
callq 0x1af30
movl 0x8(%r13), %edx
movq (%rbx), %rax
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq *0x38(%rax)
movl 0x8(%r13), %eax
movq 0x38(%rbx), %rcx
imulq $0x148, %rax, %rax      # imm = 0x148
cmpq $0x0, 0x8(%rcx,%rax)
je 0x547a2
leaq 0x488(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x1be34
testq %rax, %rax
movq (%rsp), %rbx
je 0x547d4
movq 0x8(%rsp), %rax
movl (%rax), %edx
movq (%rbx), %rax
leaq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq *0x20(%rax)
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x6170
leaq 0x10(%rsp), %rdi
callq 0x6548
movq (%rsp), %rbx
leaq 0x488(%rbx), %r15
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x25356
cmpq $0x0, 0x48(%rsp)
jne 0x5483b
movl 0xc(%r12), %esi
movq (%rsp), %rdi
callq 0x90a4
addq $0x8, %rax
leaq 0x4473b(%rip), %rcx     # 0x98f47
leaq 0x10(%rsp), %rdi
movq %rcx, %rsi
movq %rax, %rdx
movq 0x8(%rsp), %r8
callq 0x41e67
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rbx
movq %rbx, %rsi
callq 0x6320
movq %rbx, %rdi
callq 0x6548
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
callq 0x1bf20
movq (%rsp), %rax
leaq 0x3d8(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x48908
leaq 0x40(%rsp), %rsi
movq %rax, %rdi
callq 0x6170
movq %r13, %rdi
addq $0xa0, %rdi
callq 0xb854
movq 0x8(%rsp), %rax
movl (%rax), %esi
movq (%rsp), %rdi
callq 0x22d1a
leaq 0x10(%rsp), %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
movq %r12, %rdx
callq 0x54cfa
leaq 0x44078(%rip), %rsi     # 0x9891c
leaq 0x40(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
callq 0x6173a
leaq 0x10(%rsp), %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x22d28
movq 0x68(%r13), %r12
movq 0x70(%r13), %rax
movq %rax, 0xc0(%rsp)
xorl %ebp, %ebp
leaq 0x10(%rsp), %r15
movq %r13, 0x30(%rsp)
cmpq 0xc0(%rsp), %r12
je 0x54a59
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x22d40
movl 0x8(%r13), %esi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x11ee2
movq %rbx, %r13
movq %r15, %rdi
movq %rax, %rsi
callq 0x63c0
leaq 0x80(%rsp), %rdi
movq %r13, %rsi
movq 0x30(%rsp), %r15
movq %r15, %rdx
movl %ebp, %ecx
callq 0x25cca
movl 0x8(%r15), %r15d
movq 0x8(%rsp), %rax
movl (%rax), %edx
movq (%r13), %rax
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
pushq $0x1
popq %rcx
callq *0x38(%rax)
leaq 0xe8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x445d6(%rip), %rdx     # 0x98f47
leaq 0x80(%rsp), %rcx
callq 0x42137
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x20bb0
movq %r13, %rdi
movl %r15d, %esi
movl %ebp, 0x3c(%rsp)
movl %ebp, %edx
movq %rbx, %rcx
callq 0x11ed8
movq %rbx, %rbp
movq %rbx, %rdi
callq 0x6548
leaq 0xe8(%rsp), %r14
movq %r14, %rdi
callq 0x6548
leaq 0xc8(%rsp), %rdi
callq 0x6548
movq %r12, %rbx
movl (%r12), %r15d
movq %rbp, %rdi
leaq 0x3aea9(%rip), %rsi     # 0x8f887
movq %r14, %rdx
callq 0x6100
movq (%r13), %rax
movq %r13, %rdi
movq %r13, %r12
movq 0x30(%rsp), %r13
movq %r13, %rsi
movl %r15d, %edx
movl 0x3c(%rsp), %r14d
movl %r14d, %ecx
movq %rbp, %r8
xorl %r9d, %r9d
callq *0xa8(%rax)
movq %rbp, %rdi
callq 0x6548
movl 0x8(%r13), %esi
movq %r12, %rdi
movl %r14d, %edx
leaq 0x10(%rsp), %r15
movq %r15, %rcx
callq 0x11ed8
movl %r14d, %ebp
incl %ebp
leaq 0x80(%rsp), %rdi
callq 0x6548
movq %r15, %rdi
callq 0x6548
movq %rbx, %r12
addq $0x4, %r12
movq 0x30(%rsp), %r13
jmp 0x548e4
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x22dba
leaq 0x3ae1b(%rip), %rsi     # 0x8f887
movq %rbx, %rdi
callq 0x928e
leaq 0x40(%rsp), %rdi
callq 0x6548
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %r14
leaq 0x43e83(%rip), %rsi     # 0x98925
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0x922f6(%rip), %rsi     # 0xe6dc0
movq 0x9350f(%rip), %rdx     # 0xe7fe0
movq %r14, %rdi
callq 0x6490
jmp 0x54b72
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %r14
leaq 0x43e89(%rip), %rsi     # 0x98979
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0x922a8(%rip), %rsi     # 0xe6dc0
movq 0x934c1(%rip), %rdx     # 0xe7fe0
movq %r14, %rdi
callq 0x6490
jmp 0x54b72
pushq $0x10
popq %rdi
callq 0x6140
movq %rax, %r14
leaq 0x43ea7(%rip), %rsi     # 0x989e2
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x6100
movb $0x1, %bpl
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x6f6e
xorl %ebp, %ebp
leaq 0x9225d(%rip), %rsi     # 0xe6dc0
movq 0x93476(%rip), %rdx     # 0xe7fe0
movq %r14, %rdi
callq 0x6490
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
jne 0x54b8c
jmp 0x54cf1
movq %rax, %rbx
jmp 0x54bd4
jmp 0x54ce4
jmp 0x54ce4
jmp 0x54be1
jmp 0x54ce4
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
je 0x54cf1
jmp 0x54bd4
jmp 0x54bd1
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x6548
testb %bpl, %bpl
je 0x54cf1
jmp 0x54bd4
movq %rax, %rbx
movq %r14, %rdi
callq 0x6200
jmp 0x54cf1
movq %rax, %rbx
jmp 0x54cd8
jmp 0x54ce4
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x6548
jmp 0x54c03
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x6548
jmp 0x54c15
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6548
jmp 0x54ce7
movq %rax, %rbx
jmp 0x54ce7
jmp 0x54ce4
jmp 0x54ce4
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x6548
jmp 0x54c4b
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x6548
jmp 0x54c5d
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6548
jmp 0x54c6e
jmp 0x54c6b
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0xb51c
jmp 0x54cf1
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x6548
jmp 0x54cb1
jmp 0x54ca4
jmp 0x54ce4
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
jmp 0x54cc6
jmp 0x54ca4
movq %rax, %rbx
jmp 0x54cd8
movq %rax, %rbx
jmp 0x54ccb
movq %rax, %rbx
jmp 0x54cbe
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x6548
leaq 0xc8(%rsp), %rdi
callq 0x6548
leaq 0x80(%rsp), %rdi
callq 0x6548
leaq 0x10(%rsp), %rdi
callq 0x6548
jmp 0x54ce7
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x6548
movq %rbx, %rdi
callq 0x64b0
nop