// File: rossy[P]crossc/SPIRV-Cross/spirv_hlsl.cpp
// Function: spirv_cross::CompilerHLSL::emit_push_constant_block(spirv_cross::SPIRVariable const&)
void CompilerHLSL::emit_push_constant_block(const SPIRVariable &var)
{
	if (root_constants_layout.empty())
	{
		emit_buffer_block(var);
	}
	else
	{
		for (const auto &layout : root_constants_layout)
		{
			auto &type = get<SPIRType>(var.basetype);

			if (buffer_is_packing_standard(type, BufferPackingHLSLCbufferPackOffset, layout.start, layout.end))
				set_decoration(type.self, DecorationCPacked);
			else
				SPIRV_CROSS_THROW(
				    "root constant cbuffer cannot be expressed with either HLSL packing layout or packoffset.");

			flattened_structs.insert(var.self);
			type.member_name_cache.clear();
			add_resource_name(var.self);
			auto &memb = ir.meta[type.self].members;

			statement("cbuffer SPIRV_CROSS_RootConstant_", to_name(var.self),
			          to_resource_register('b', layout.binding, layout.space));
			begin_scope();

			// Index of the next field in the generated root constant constant buffer
			auto constant_index = 0u;

			// Iterate over all member of the push constant and check which of the fields
			// fit into the given root constant layout.
			for (auto i = 0u; i < memb.size(); i++)
			{
				const auto offset = memb[i].offset;
				if (layout.start <= offset && offset < layout.end)
				{
					const auto &member = type.member_types[i];

					add_member_name(type, constant_index);
					auto backup_name = get_member_name(type.self, i);
					auto member_name = to_member_name(type, i);
					set_member_name(type.self, constant_index,
					                sanitize_underscores(join(to_name(var.self), "_", member_name)));
					emit_struct_member(type, member, i, "", layout.start);
					set_member_name(type.self, constant_index, backup_name);

					constant_index++;
				}
			}

			end_scope_decl();
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
addq $0x7d0, %rdi            # imm = 0x7D0
callq 0xdb3a0
testb $0x1, %al
jne 0xc36c0
jmp 0xc36d9
movq -0x1b0(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0xe8(%rax)
jmp 0xc3d07
movq -0x1b0(%rbp), %rax
addq $0x7d0, %rax            # imm = 0x7D0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0xdb3e0
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0xdb410
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xdb440
testb $0x1, %al
jne 0xc371a
jmp 0xc3d05
leaq -0x20(%rbp), %rdi
callq 0xdb480
movq -0x1b0(%rbp), %rdi
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq -0x1b0(%rbp), %rdi
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movl 0x4(%rax), %r8d
movl $0x5, %edx
callq 0x5e040
testb $0x1, %al
jne 0xc3767
jmp 0xc3786
movq -0x1b0(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %esi
movl $0xa, %edx
xorl %ecx, %ecx
callq 0x232d0
jmp 0xc383e
movb $0x1, -0x6d(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x1c0(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x7650
movq -0x1b8(%rbp), %rdx
leaq 0x847f2(%rip), %rsi     # 0x147fab
leaq -0x58(%rbp), %rdi
callq 0x7520
jmp 0xc37c4
movq -0x1c0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x9c50
jmp 0xc37d6
movq -0x1c0(%rbp), %rdi
movb $0x0, -0x6d(%rbp)
leaq 0xea5f0(%rip), %rsi     # 0x1addd8
leaq -0xb9b5f(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0xc3d19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc381c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x7708
leaq -0x59(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x6d(%rbp)
jne 0xc382d
jmp 0xc3839
movq -0x1c0(%rbp), %rdi
callq 0x72c0
jmp 0xc3d10
movq -0x1b0(%rbp), %rdi
addq $0x6b0, %rdi            # imm = 0x6B0
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0x2e890
movq %rax, -0x80(%rbp)
movb %dl, -0x78(%rbp)
movq -0x38(%rbp), %rdi
addq $0xa0, %rdi
callq 0x9e1e0
movq -0x1b0(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x5c1d0
movq -0x1b0(%rbp), %rdi
addq $0x38, %rdi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq -0x1b0(%rbp), %rsi
addq $0xd0, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0xa8(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
movq -0x1b0(%rbp), %rsi
movq -0x30(%rbp), %rax
movl 0x8(%rax), %ecx
movl 0xc(%rax), %r8d
leaq -0xc8(%rbp), %rdi
movl $0x62, %edx
callq 0xc3d20
jmp 0xc38f1
movq -0x1b0(%rbp), %rdi
leaq 0x84705(%rip), %rsi     # 0x148004
leaq -0xa8(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0xdb4a0
jmp 0xc3914
leaq -0xc8(%rbp), %rdi
callq 0x7708
leaq -0xa8(%rbp), %rdi
callq 0x7708
movq -0x1b0(%rbp), %rdi
callq 0x5c200
movl $0x0, -0xcc(%rbp)
movl $0x0, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
movq %rax, -0x1c8(%rbp)
movq -0x88(%rbp), %rdi
callq 0x2eca0
movq %rax, %rcx
movq -0x1c8(%rbp), %rax
cmpq %rcx, %rax
jae 0xc3ceb
movq -0x88(%rbp), %rdi
movl -0xd0(%rbp), %eax
movl %eax, %esi
callq 0x2fa30
movl 0xb4(%rax), %eax
movl %eax, -0xd4(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
cmpl -0xd4(%rbp), %eax
ja 0xc3cd5
movl -0xd4(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0xc3cd5
movq -0x38(%rbp), %rdi
addq $0x68, %rdi
movl -0xd0(%rbp), %eax
movl %eax, %esi
callq 0x8630
movq -0x1b0(%rbp), %rdi
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rsi
movl -0xcc(%rbp), %edx
callq 0x5c240
movq -0x1b0(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %esi
movl -0xd0(%rbp), %edx
callq 0x22fd0
movq %rax, %rsi
leaq -0x100(%rbp), %rdi
callq 0x7170
movq -0x1b0(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl -0xd0(%rbp), %ecx
leaq -0x120(%rbp), %rdi
callq 0x62230
jmp 0xc3a36
movq -0x1b0(%rbp), %rsi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x1d0(%rbp)
movl -0xcc(%rbp), %eax
movl %eax, -0x1cc(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0x180(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0xc3a74
leaq 0x84aa3(%rip), %rdx     # 0x14851e
leaq -0x160(%rbp), %rdi
leaq -0x180(%rbp), %rsi
leaq -0x120(%rbp), %rcx
callq 0x9ff30
jmp 0xc3a97
leaq -0x140(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x577c0
jmp 0xc3aac
movl -0x1cc(%rbp), %edx
movl -0x1d0(%rbp), %esi
movq -0x1b0(%rbp), %rdi
leaq -0x140(%rbp), %rcx
callq 0x22f90
jmp 0xc3acd
leaq -0x140(%rbp), %rdi
callq 0x7708
leaq -0x160(%rbp), %rdi
callq 0x7708
leaq -0x180(%rbp), %rdi
callq 0x7708
movq -0x38(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0xe0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1e0(%rbp)
movl -0xd0(%rbp), %eax
movl %eax, -0x1dc(%rbp)
leaq -0x1a1(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x7650
movq -0x1d8(%rbp), %rdx
leaq 0x7ad66(%rip), %rsi     # 0x13e89e
leaq -0x1a0(%rbp), %rdi
callq 0x7520
jmp 0xc3b46
movl -0x1dc(%rbp), %ecx
movl -0x1e0(%rbp), %edx
movq -0x1e8(%rbp), %rsi
movq -0x1b0(%rbp), %rdi
movq -0x30(%rbp), %rax
movl (%rax), %r9d
movq (%rdi), %rax
movq 0xa8(%rax), %rax
leaq -0x1a0(%rbp), %r8
callq *%rax
jmp 0xc3b7c
leaq -0x1a0(%rbp), %rdi
callq 0x7708
leaq -0x1a1(%rbp), %rdi
callq 0x73d0
movq -0x1b0(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x8(%rax), %esi
movl -0xcc(%rbp), %edx
leaq -0x100(%rbp), %rcx
callq 0x22f90
jmp 0xc3bb6
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x7708
leaq -0x100(%rbp), %rdi
callq 0x7708
jmp 0xc3cd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc3c08
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x7708
leaq -0xa8(%rbp), %rdi
callq 0x7708
jmp 0xc3d10
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc3cc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc3cbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc3c7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc3c6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x7708
leaq -0x160(%rbp), %rdi
callq 0x7708
leaq -0x180(%rbp), %rdi
callq 0x7708
jmp 0xc3cbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xc3caf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x7708
leaq -0x1a1(%rbp), %rdi
callq 0x73d0
leaq -0x120(%rbp), %rdi
callq 0x7708
leaq -0x100(%rbp), %rdi
callq 0x7708
jmp 0xc3d10
jmp 0xc3cd7
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0xc394c
movq -0x1b0(%rbp), %rdi
callq 0x5c350
leaq -0x20(%rbp), %rdi
callq 0xdb5d0
jmp 0xc3704
jmp 0xc3d07
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x7640
nopl (%rax)