// File: /workspace/github_cpp_makefile_star2_O3/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 $0xf8, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movl 0xc(%rsi), %esi
callq 0xa3ea
movq %rax, %r14
cmpl $0xc, 0x10(%r12)
je 0x67a77
movl 0x8(%r14), %esi
movq %rbx, %rdi
movl $0x3, %edx
callq 0x12974
testb %al, %al
je 0x67bb3
leaq 0x8(%rbx), %rsi
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
callq 0x2460e
movq (%r15), %r15
movl 0x8(%r12), %esi
movq %rbx, %rdi
callq 0x281be
btl $0x17, %r15d
leaq 0x4ce08(%rip), %rax     # 0xb48af
leaq 0x55eb7(%rip), %rcx     # 0xbd965
cmovaeq %rax, %rcx
btl $0x18, %r15d
leaq 0x55eb9(%rip), %rax     # 0xbd977
leaq 0x55eb4(%rip), %rdx     # 0xbd979
cmovaeq %rax, %rdx
movq %rcx, 0xd0(%rsp)
movq %rdx, 0xb0(%rsp)
movl 0x8(%r12), %edx
movq (%rbx), %rax
movq %rsp, %rdi
movq %rbx, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2b55a
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x684ce
subq $0x8, %rsp
leaq 0x56fd7(%rip), %rax     # 0xbeaf1
leaq 0xd8(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
leaq 0x8(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x28(%rsp), %r9
movq %rbx, %rdi
pushq %rax
callq 0x78bde
addq $0x10, %rsp
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67b61
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67b7c
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67b97
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x78(%rsp), %rdi
callq 0xd570
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%r14), %rax
cmpq 0x28(%r14), %rax
je 0x67cf9
cmpl $0x32, 0x788(%rbx)
jbe 0x6810b
movq %rbx, %rdi
movq %r14, %rsi
movl $0x4, %edx
xorl %ecx, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x29318
testb %al, %al
je 0x68177
movl 0x8(%r14), %esi
movq %rbx, %rdi
callq 0x281be
movl 0x8(%r12), %esi
movq %rbx, %rdi
callq 0x281be
movl 0x8(%r14), %esi
movq %rbx, %rdi
callq 0xa3ea
movq %rbx, %rdi
movq %rax, %rsi
callq 0x27fa4
movl 0x8(%r14), %edx
movq (%rbx), %rax
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
movl 0x8(%r12), %edx
movq (%rbx), %rax
movq %rsp, %rdi
movq %rbx, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2b55a
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x684ce
leaq 0x56e7c(%rip), %rax     # 0xbeaf1
leaq 0x55db8(%rip), %rsi     # 0xbda34
leaq 0x4c562(%rip), %rcx     # 0xb41e5
leaq 0x70(%rsp), %rdx
movq %rsp, %r8
leaq 0x50(%rsp), %r9
movq %rbx, %rdi
pushq %rax
pushq %r14
callq 0x78ea8
addq $0x10, %rsp
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67cba
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67cd5
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x680e1
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x680e1
movq %rbx, %rdi
movq %r14, %rsi
movl $0x5, %edx
xorl %ecx, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x29318
testb %al, %al
je 0x681e0
movl 0x8(%r14), %esi
movq %rbx, %rdi
movl $0xa, %edx
xorl %ecx, %ecx
callq 0x14d16
leaq 0x6b0(%rbx), %rdi
leaq 0x8(%r12), %rsi
leaq 0x70(%rsp), %rdx
movq %rdi, (%rdx)
movq %rsi, 0x40(%rsp)
callq 0x1f510
movl 0x8(%r14), %edx
movq (%rbx), %rax
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
xorl %ecx, %ecx
callq *0x38(%rax)
movl 0x8(%r14), %eax
movq 0x38(%rbx), %rcx
imulq $0x148, %rax, %rax      # imm = 0x148
cmpq $0x0, 0x8(%rcx,%rax)
je 0x67d8b
leaq 0x488(%rbx), %rdi
leaq 0x70(%rsp), %rsi
callq 0x20790
testq %rax, %rax
je 0x67dc6
movq 0x40(%rsp), %rax
movl (%rax), %edx
movq (%rbx), %rax
movq %rsp, %rdi
movq %rbx, %rsi
callq *0x20(%rax)
leaq 0x70(%rsp), %rdi
movq %rsp, %rsi
callq 0x6170
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67dc6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
leaq 0x488(%rbx), %r15
leaq 0x70(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2b3ee
cmpq $0x0, 0x78(%rsp)
movq %r14, 0x48(%rsp)
jne 0x67e45
movl 0xc(%r12), %esi
movq %rbx, %rdi
callq 0xa3ea
addq $0x8, %rax
leaq 0x561b5(%rip), %rcx     # 0xbdfb7
movq %rsp, %rdi
movq %rcx, %rsi
movq %rax, %rdx
movq 0x40(%rsp), %r8
callq 0x51b54
leaq 0x70(%rsp), %rdi
movq %rsp, %r13
movq %r13, %rsi
callq 0x6310
movq (%r13), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x67e40
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x48(%rsp), %r14
movq %rsp, %rdx
movq %r15, (%rdx)
leaq 0x70(%rsp), %rsi
movq %r15, %rdi
callq 0x208a8
leaq 0x3d8(%rbx), %rdi
movq 0x40(%rsp), %rsi
callq 0x5ada8
leaq 0x70(%rsp), %rsi
movq %rax, %rdi
callq 0x6170
movq %r14, %rdi
addq $0xa0, %rdi
callq 0xd940
movq 0x40(%rsp), %rax
movl (%rax), %esi
movq %rbx, %rdi
callq 0x281be
movq %rsp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x684ce
leaq 0x55ae3(%rip), %rsi     # 0xbd98c
leaq 0x70(%rsp), %rdx
movq %rsp, %rcx
movq %rbx, %rdi
callq 0x78d56
leaq 0x10(%rsp), %r12
movq -0x10(%r12), %rdi
cmpq %r12, %rdi
je 0x67ed5
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x281d8
movq 0x68(%r14), %r15
movq 0x70(%r14), %rax
movq %rax, 0xf0(%rsp)
cmpq %rax, %r15
je 0x680ca
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x281f0
movl 0x8(%r14), %esi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x14b5c
movq %r12, (%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0xe456
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movq 0x48(%rsp), %r14
movq %r14, %rdx
movl %ebp, %ecx
callq 0x2c088
movl 0x8(%r14), %r12d
movq 0x40(%rsp), %rax
movl (%rax), %edx
movq (%rbx), %rax
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %ecx
callq *0x38(%rax)
leaq 0xd0(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
leaq 0x5603e(%rip), %rdx     # 0xbdfb7
leaq 0x50(%rsp), %rcx
callq 0x51f10
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x25974
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
movq %r14, %rcx
callq 0x14b52
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x67fbf
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x67fe4
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x68009
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x6260
movl (%r15), %r12d
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x20(%rsp), %r14
movq %r14, %rdi
leaq 0x4c88a(%rip), %rdx     # 0xb48af
movq %rdx, %rsi
callq 0x7be0
movq (%rbx), %rax
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
movl %r12d, %edx
movl %ebp, %ecx
movq %r14, %r8
xorl %r9d, %r9d
callq *0xa8(%rax)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
leaq 0x10(%rsp), %r12
je 0x6806a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0x48(%rsp), %rax
movl 0x8(%rax), %esi
movq %rbx, %rdi
movl %ebp, %edx
movq %rsp, %rcx
callq 0x14b52
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x6809b
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
movq (%rsp), %rdi
cmpq %r12, %rdi
movq 0x48(%rsp), %r14
je 0x680b6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
addq $0x4, %r15
incl %ebp
cmpq 0xf0(%rsp), %r15
jne 0x67ef8
movq %rbx, %rdi
callq 0x28270
leaq 0x4c7d6(%rip), %rsi     # 0xb48af
movq %rbx, %rdi
callq 0xa6c4
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67ba1
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x67ba1
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x80(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x5586a(%rip), %rsi     # 0xbd995
leaq 0x558b6(%rip), %rdx     # 0xbd9e8
leaq 0x70(%rsp), %rdi
callq 0x7be0
movb $0x1, %bpl
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0x93c75(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x93c4d(%rip), %rsi     # 0xfbdb0
movq 0x94e6e(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
jmp 0x68247
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x80(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x55852(%rip), %rsi     # 0xbd9e9
leaq 0x55895(%rip), %rdx     # 0xbda33
leaq 0x70(%rsp), %rdi
callq 0x7be0
movb $0x1, %bpl
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0x93c09(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x93be1(%rip), %rsi     # 0xfbdb0
movq 0x94e02(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
jmp 0x68247
movl $0x10, %edi
callq 0x6140
movq %rax, %r14
leaq 0x80(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x55852(%rip), %rsi     # 0xbda52
leaq 0x55895(%rip), %rdx     # 0xbda9c
leaq 0x70(%rsp), %rdi
callq 0x7be0
movb $0x1, %bpl
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x6320
leaq 0x93ba0(%rip), %rax     # 0xfbdc8
addq $0x10, %rax
movq %rax, (%r14)
xorl %ebp, %ebp
leaq 0x93b78(%rip), %rsi     # 0xfbdb0
movq 0x94d99(%rip), %rdx     # 0xfcfd8
movq %r14, %rdi
callq 0x6470
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r15, %rdi
je 0x68264
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
jne 0x68271
jmp 0x684c6
movq %rax, %rbx
jmp 0x682dc
jmp 0x684a2
jmp 0x684a2
jmp 0x68330
jmp 0x684a2
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r15, %rdi
je 0x682a4
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
je 0x684c6
jmp 0x682dc
jmp 0x682d9
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r15, %rdi
je 0x682ce
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6260
testb %bpl, %bpl
je 0x684c6
jmp 0x682dc
movq %rax, %rbx
movq %r14, %rdi
callq 0x6200
jmp 0x684c6
jmp 0x68330
jmp 0x684a2
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x68313
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x68313
movq %rax, %rbx
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x68333
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x68333
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
jmp 0x6848e
jmp 0x684a2
jmp 0x684a2
jmp 0x684a2
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x68373
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x68373
movq %rax, %rbx
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x68393
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x68393
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x683b5
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x683b5
jmp 0x683b2
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0xd570
jmp 0x684c6
jmp 0x684a2
movq %rax, %rbx
jmp 0x68485
jmp 0x68466
movq %rax, %rbx
jmp 0x68424
movq %rax, %rbx
jmp 0x683ff
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x683ff
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x68424
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x6260
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x68469
movq 0xc0(%rsp), %rsi
jmp 0x6845c
jmp 0x68466
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x68469
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x68469
movq %rax, %rbx
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x68485
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x6260
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x684a5
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6260
jmp 0x684a5
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x684c6
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x6260
movq %rbx, %rdi
callq 0x64a0