// File: rossy[P]crossc/SPIRV-Cross/spirv_hlsl.cpp
// Function: spirv_cross::CompilerHLSL::remap_num_workgroups_builtin()
uint32_t CompilerHLSL::remap_num_workgroups_builtin()
{
	update_active_builtins();

	if (!active_input_builtins.get(BuiltInNumWorkgroups))
		return 0;

	// Create a new, fake UBO.
	uint32_t offset = ir.increase_bound_by(4);

	uint32_t uint_type_id = offset;
	uint32_t block_type_id = offset + 1;
	uint32_t block_pointer_type_id = offset + 2;
	uint32_t variable_id = offset + 3;

	SPIRType uint_type;
	uint_type.basetype = SPIRType::UInt;
	uint_type.width = 32;
	uint_type.vecsize = 3;
	uint_type.columns = 1;
	set<SPIRType>(uint_type_id, uint_type);

	SPIRType block_type;
	block_type.basetype = SPIRType::Struct;
	block_type.member_types.push_back(uint_type_id);
	set<SPIRType>(block_type_id, block_type);
	set_decoration(block_type_id, DecorationBlock);
	set_member_name(block_type_id, 0, "count");
	set_member_decoration(block_type_id, 0, DecorationOffset, 0);

	SPIRType block_pointer_type = block_type;
	block_pointer_type.pointer = true;
	block_pointer_type.storage = StorageClassUniform;
	block_pointer_type.parent_type = block_type_id;
	auto &ptr_type = set<SPIRType>(block_pointer_type_id, block_pointer_type);

	// Preserve self.
	ptr_type.self = block_type_id;

	set<SPIRVariable>(variable_id, block_pointer_type_id, StorageClassUniform);
	ir.meta[variable_id].decoration.alias = "SPIRV_Cross_NumWorkgroups";

	num_workgroups_builtin = variable_id;
	return variable_id;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x300(%rbp)
callq 0x2b100
movq -0x300(%rbp), %rdi
addq $0x2d0, %rdi            # imm = 0x2D0
movl $0x18, %esi
callq 0xef50
testb $0x1, %al
jne 0xd3777
movl $0x0, -0x4(%rbp)
jmp 0xd3a77
movq -0x300(%rbp), %rdi
addq $0x8, %rdi
movl $0x4, %esi
callq 0x55780
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
incl %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x20(%rbp)
movl -0x14(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x24(%rbp)
leaq -0x100(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0x31440
movq -0x300(%rbp), %rdi
movq -0x308(%rbp), %rdx
movl $0x5, -0xf4(%rbp)
movl $0x20, -0xf0(%rbp)
movl $0x3, -0xec(%rbp)
movl $0x1, -0xe8(%rbp)
movl -0x18(%rbp), %esi
callq 0xdeb40
jmp 0xd3802
leaq -0x1e8(%rbp), %rdi
callq 0x31440
movl $0xc, -0x1dc(%rbp)
leaq -0x180(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x88f0
jmp 0xd382a
movq -0x300(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x1e8(%rbp), %rdx
callq 0xdeb40
jmp 0xd3842
movq -0x300(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x232d0
jmp 0xd385a
movl -0x1c(%rbp), %eax
movl %eax, -0x314(%rbp)
leaq -0x209(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x7650
movq -0x310(%rbp), %rdx
leaq 0x6c5c9(%rip), %rsi     # 0x13fe4d
leaq -0x208(%rbp), %rdi
callq 0x7520
jmp 0xd3892
movl -0x314(%rbp), %esi
movq -0x300(%rbp), %rdi
xorl %edx, %edx
leaq -0x208(%rbp), %rcx
callq 0x22f90
jmp 0xd38af
leaq -0x208(%rbp), %rdi
callq 0x7708
leaq -0x209(%rbp), %rdi
callq 0x73d0
movq -0x300(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl $0x23, %ecx
xorl %r8d, %r8d
movl %r8d, %edx
callq 0x22f50
jmp 0xd38e3
leaq -0x2e8(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x3d730
jmp 0xd38f8
movq -0x300(%rbp), %rdi
movb $0x1, -0x288(%rbp)
movl $0x2, -0x284(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x24c(%rbp)
movl -0x20(%rbp), %esi
leaq -0x2e8(%rbp), %rdx
callq 0xdeb40
movq %rax, -0x320(%rbp)
jmp 0xd3931
movq -0x300(%rbp), %rdi
movq -0x320(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x2f0(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x24(%rbp), %esi
movl $0x2, -0x2f4(%rbp)
leaq -0x20(%rbp), %rdx
leaq -0x2f4(%rbp), %rcx
callq 0xdeb90
jmp 0xd3972
movq -0x300(%rbp), %rdi
addq $0x38, %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
leaq 0x757e1(%rip), %rsi     # 0x149172
callq 0x7510
jmp 0xd3998
movq -0x300(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, 0x7c8(%rax)
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x314e0
leaq -0x1e8(%rbp), %rdi
callq 0x314e0
leaq -0x100(%rbp), %rdi
callq 0x314e0
jmp 0xd3a77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0xd3a69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0xd3a5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
jmp 0xd3a31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x7708
leaq -0x209(%rbp), %rdi
callq 0x73d0
jmp 0xd3a5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x108(%rbp)
movl %eax, -0x10c(%rbp)
leaq -0x2e8(%rbp), %rdi
callq 0x314e0
leaq -0x1e8(%rbp), %rdi
callq 0x314e0
leaq -0x100(%rbp), %rdi
callq 0x314e0
jmp 0xd3a83
movl -0x4(%rbp), %eax
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
movq -0x108(%rbp), %rdi
callq 0x7640
nop