// File: rossy[P]crossc/SPIRV-Cross/spirv_cpp.cpp
// Function: spirv_cross::CompilerCPP::emit_resources()
void CompilerCPP::emit_resources()
{
	// Output all basic struct types which are not Block or BufferBlock as these are declared inplace
	// when such variables are instantiated.
	for (auto &id : ir.ids)
	{
		if (id.get_type() == TypeType)
		{
			auto &type = id.get<SPIRType>();
			if (type.basetype == SPIRType::Struct && type.array.empty() && !type.pointer &&
			    (!ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock) &&
			     !ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock)))
			{
				emit_struct(type);
			}
		}
	}

	statement("struct Resources : ", resource_type);
	begin_scope();

	// Output UBOs and SSBOs
	for (auto &id : ir.ids)
	{
		if (id.get_type() == TypeVariable)
		{
			auto &var = id.get<SPIRVariable>();
			auto &type = get<SPIRType>(var.basetype);

			if (var.storage != StorageClassFunction && type.pointer && type.storage == StorageClassUniform &&
			    !is_hidden_variable(var) &&
			    (ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock) ||
			     ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock)))
			{
				emit_buffer_block(var);
			}
		}
	}

	// Output push constant blocks
	for (auto &id : ir.ids)
	{
		if (id.get_type() == TypeVariable)
		{
			auto &var = id.get<SPIRVariable>();
			auto &type = get<SPIRType>(var.basetype);
			if (!is_hidden_variable(var) && var.storage != StorageClassFunction && type.pointer &&
			    type.storage == StorageClassPushConstant)
			{
				emit_push_constant_block(var);
			}
		}
	}

	// Output in/out interfaces.
	for (auto &id : ir.ids)
	{
		if (id.get_type() == TypeVariable)
		{
			auto &var = id.get<SPIRVariable>();
			auto &type = get<SPIRType>(var.basetype);

			if (var.storage != StorageClassFunction && !is_hidden_variable(var) && type.pointer &&
			    (var.storage == StorageClassInput || var.storage == StorageClassOutput) &&
			    interface_variable_exists_in_entry_point(var.self))
			{
				emit_interface_block(var);
			}
		}
	}

	// Output Uniform Constants (values, samplers, images, etc).
	for (auto &id : ir.ids)
	{
		if (id.get_type() == TypeVariable)
		{
			auto &var = id.get<SPIRVariable>();
			auto &type = get<SPIRType>(var.basetype);

			if (var.storage != StorageClassFunction && !is_hidden_variable(var) && type.pointer &&
			    (type.storage == StorageClassUniformConstant || type.storage == StorageClassAtomicCounter))
			{
				emit_uniform(var);
			}
		}
	}

	// Global variables.
	bool emitted = false;
	for (auto global : global_variables)
	{
		auto &var = get<SPIRVariable>(global);
		if (var.storage == StorageClassWorkgroup)
		{
			emit_shared(var);
			emitted = true;
		}
	}

	if (emitted)
		statement("");

	declare_undefined_values();

	statement("inline void init(spirv_cross_shader& s)");
	begin_scope();
	statement(resource_type, "::init(s);");
	for (auto &reg : resource_registrations)
		statement(reg);
	end_scope();
	resource_registrations.clear();

	end_scope_decl();

	statement("");
	statement("Resources* __res;");
	if (get_entry_point().model == ExecutionModelGLCompute)
		statement("ComputePrivateResources __priv_res;");
	statement("");

	// Emit regular globals which are allocated per invocation.
	emitted = false;
	for (auto global : global_variables)
	{
		auto &var = get<SPIRVariable>(global);
		if (var.storage == StorageClassPrivate)
		{
			if (var.storage == StorageClassWorkgroup)
				emit_shared(var);
			else
				statement(CompilerGLSL::variable_decl(var), ";");
			emitted = true;
		}
	}

	if (emitted)
		statement("");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
addq $0x8, %rax
addq $0x18, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0xf940
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0xf970
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0xf9a0
testb $0x1, %al
jne 0xce36
jmp 0xcf13
leaq -0x18(%rbp), %rdi
callq 0xf9e0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0xfa00
cmpl $0x1, %eax
jne 0xcf03
movq -0x28(%rbp), %rdi
callq 0xfa20
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0xc, 0xc(%rax)
jne 0xcf01
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
callq 0x8690
testb $0x1, %al
jne 0xce83
jmp 0xcf01
movq -0x30(%rbp), %rax
testb $0x1, 0x60(%rax)
jne 0xcf01
movq -0x1a0(%rbp), %rdi
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0x60, %rdi
movl $0x2, %esi
callq 0xef50
testb $0x1, %al
jne 0xcf01
movq -0x1a0(%rbp), %rdi
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0x60, %rdi
movl $0x3, %esi
callq 0xef50
testb $0x1, %al
jne 0xcf01
movq -0x1a0(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x5bf00
jmp 0xcf03
jmp 0xcf05
leaq -0x18(%rbp), %rdi
callq 0xfbd0
jmp 0xce20
movq -0x1a0(%rbp), %rdi
movq %rdi, %rdx
addq $0x7c0, %rdx            # imm = 0x7C0
leaq 0x13141e(%rip), %rsi    # 0x13e349
callq 0xfbf0
movq -0x1a0(%rbp), %rdi
callq 0x5c200
movq -0x1a0(%rbp), %rax
addq $0x8, %rax
addq $0x18, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0xf940
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rdi
callq 0xf970
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xf9a0
testb $0x1, %al
jne 0xcf7f
jmp 0xd08e
leaq -0x40(%rbp), %rdi
callq 0xf9e0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0xfa00
cmpl $0x2, %eax
jne 0xd07e
movq -0x50(%rbp), %rdi
callq 0xfd10
movq -0x1a0(%rbp), %rdi
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x7, 0x10(%rax)
je 0xd07c
movq -0x60(%rbp), %rax
testb $0x1, 0x60(%rax)
je 0xd07c
movq -0x60(%rbp), %rax
cmpl $0x2, 0x64(%rax)
jne 0xd07c
movq -0x1a0(%rbp), %rdi
movq -0x58(%rbp), %rsi
xorl %edx, %edx
callq 0x20460
testb $0x1, %al
jne 0xd07c
movq -0x1a0(%rbp), %rdi
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0x60, %rdi
movl $0x2, %esi
callq 0xef50
testb $0x1, %al
jne 0xd068
movq -0x1a0(%rbp), %rdi
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x60(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0x60, %rdi
movl $0x3, %esi
callq 0xef50
testb $0x1, %al
jne 0xd068
jmp 0xd07c
movq -0x1a0(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq (%rdi), %rax
callq *0xe8(%rax)
jmp 0xd07e
jmp 0xd080
leaq -0x40(%rbp), %rdi
callq 0xfbd0
jmp 0xcf69
movq -0x1a0(%rbp), %rax
addq $0x8, %rax
addq $0x18, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0xf940
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
callq 0xf970
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xf9a0
testb $0x1, %al
jne 0xd0d1
jmp 0xd186
leaq -0x70(%rbp), %rdi
callq 0xf9e0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rdi
callq 0xfa00
cmpl $0x2, %eax
jne 0xd176
movq -0x80(%rbp), %rdi
callq 0xfd10
movq -0x1a0(%rbp), %rdi
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq -0x1a0(%rbp), %rdi
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rsi
xorl %edx, %edx
callq 0x20460
testb $0x1, %al
jne 0xd174
movq -0x88(%rbp), %rax
cmpl $0x7, 0x10(%rax)
je 0xd174
movq -0x90(%rbp), %rax
testb $0x1, 0x60(%rax)
je 0xd174
movq -0x90(%rbp), %rax
cmpl $0x9, 0x64(%rax)
jne 0xd174
movq -0x1a0(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq (%rdi), %rax
callq *0xf0(%rax)
jmp 0xd176
jmp 0xd178
leaq -0x70(%rbp), %rdi
callq 0xfbd0
jmp 0xd0bb
movq -0x1a0(%rbp), %rax
addq $0x8, %rax
addq $0x18, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rdi
callq 0xf940
movq %rax, -0xa0(%rbp)
movq -0x98(%rbp), %rdi
callq 0xf970
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xf9a0
testb $0x1, %al
jne 0xd1de
jmp 0xd2c7
leaq -0xa0(%rbp), %rdi
callq 0xf9e0
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0xfa00
cmpl $0x2, %eax
jne 0xd2b4
movq -0xb0(%rbp), %rdi
callq 0xfd10
movq -0x1a0(%rbp), %rdi
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rax
cmpl $0x7, 0x10(%rax)
je 0xd2b2
movq -0x1a0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
xorl %edx, %edx
callq 0x20460
testb $0x1, %al
jne 0xd2b2
movq -0xc0(%rbp), %rax
testb $0x1, 0x60(%rax)
je 0xd2b2
movq -0xb8(%rbp), %rax
cmpl $0x1, 0x10(%rax)
je 0xd283
movq -0xb8(%rbp), %rax
cmpl $0x3, 0x10(%rax)
jne 0xd2b2
movq -0x1a0(%rbp), %rdi
movq -0xb8(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x21c10
testb $0x1, %al
jne 0xd29f
jmp 0xd2b2
movq -0x1a0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0xc220
jmp 0xd2b4
jmp 0xd2b6
leaq -0xa0(%rbp), %rdi
callq 0xfbd0
jmp 0xd1c2
movq -0x1a0(%rbp), %rax
addq $0x8, %rax
addq $0x18, %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
callq 0xf940
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
callq 0xf970
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0xf9a0
testb $0x1, %al
jne 0xd31f
jmp 0xd3f0
leaq -0xd0(%rbp), %rdi
callq 0xf9e0
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rdi
callq 0xfa00
cmpl $0x2, %eax
jne 0xd3dd
movq -0xe0(%rbp), %rdi
callq 0xfd10
movq -0x1a0(%rbp), %rdi
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq %rax, -0xf0(%rbp)
movq -0xe8(%rbp), %rax
cmpl $0x7, 0x10(%rax)
je 0xd3db
movq -0x1a0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
xorl %edx, %edx
callq 0x20460
testb $0x1, %al
jne 0xd3db
movq -0xf0(%rbp), %rax
testb $0x1, 0x60(%rax)
je 0xd3db
movq -0xf0(%rbp), %rax
cmpl $0x0, 0x64(%rax)
je 0xd3c4
movq -0xf0(%rbp), %rax
cmpl $0xa, 0x64(%rax)
jne 0xd3db
movq -0x1a0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq (%rdi), %rax
callq *0xf8(%rax)
jmp 0xd3dd
jmp 0xd3df
leaq -0xd0(%rbp), %rdi
callq 0xfbd0
jmp 0xd303
movq -0x1a0(%rbp), %rax
movb $0x0, -0xf1(%rbp)
addq $0x118, %rax            # imm = 0x118
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
callq 0x86d0
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rdi
callq 0x8700
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x8730
testb $0x1, %al
jne 0xd44a
jmp 0xd4ae
leaq -0x108(%rbp), %rdi
callq 0x8770
movq -0x1a0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x114(%rbp)
movl -0x114(%rbp), %esi
callq 0xfec0
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
cmpl $0x4, 0x10(%rax)
jne 0xd49e
movq -0x1a0(%rbp), %rdi
movq -0x120(%rbp), %rsi
callq 0xc5d0
movb $0x1, -0xf1(%rbp)
jmp 0xd4a0
leaq -0x108(%rbp), %rdi
callq 0x8790
jmp 0xd431
testb $0x1, -0xf1(%rbp)
je 0xd4ca
movq -0x1a0(%rbp), %rdi
leaq 0x1313d9(%rip), %rsi    # 0x13e89e
callq 0xedf0
movq -0x1a0(%rbp), %rdi
movq (%rdi), %rax
callq *0x180(%rax)
movq -0x1a0(%rbp), %rdi
leaq 0x130e75(%rip), %rsi    # 0x13e35d
callq 0xff00
movq -0x1a0(%rbp), %rdi
callq 0x5c200
movq -0x1a0(%rbp), %rdi
movq %rdi, %rsi
addq $0x7c0, %rsi            # imm = 0x7C0
leaq 0x130e74(%rip), %rdx    # 0x13e385
callq 0x10020
movq -0x1a0(%rbp), %rax
addq $0x788, %rax            # imm = 0x788
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rdi
callq 0x10140
movq %rax, -0x130(%rbp)
movq -0x128(%rbp), %rdi
callq 0x10170
movq %rax, -0x138(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x101a0
testb $0x1, %al
jne 0xd569
jmp 0xd59d
leaq -0x130(%rbp), %rdi
callq 0x101e0
movq -0x1a0(%rbp), %rdi
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rsi
callq 0x10200
leaq -0x130(%rbp), %rdi
callq 0x10320
jmp 0xd550
movq -0x1a0(%rbp), %rdi
callq 0x876c0
movq -0x1a0(%rbp), %rdi
addq $0x788, %rdi            # imm = 0x788
callq 0x10340
movq -0x1a0(%rbp), %rdi
callq 0x5c350
movq -0x1a0(%rbp), %rdi
leaq 0x1312c8(%rip), %rsi    # 0x13e89e
callq 0xedf0
movq -0x1a0(%rbp), %rdi
leaq 0x130da7(%rip), %rsi    # 0x13e390
callq 0x10360
movq -0x1a0(%rbp), %rdi
callq 0x25150
cmpl $0x5, 0xb8(%rax)
jne 0xd616
movq -0x1a0(%rbp), %rdi
leaq 0x130d91(%rip), %rsi    # 0x13e3a2
callq 0x10480
movq -0x1a0(%rbp), %rdi
leaq 0x13127a(%rip), %rsi    # 0x13e89e
callq 0xedf0
movq -0x1a0(%rbp), %rax
movb $0x0, -0xf1(%rbp)
addq $0x118, %rax            # imm = 0x118
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rdi
callq 0x86d0
movq %rax, -0x150(%rbp)
movq -0x148(%rbp), %rdi
callq 0x8700
movq %rax, -0x158(%rbp)
leaq -0x150(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x8730
testb $0x1, %al
jne 0xd686
jmp 0xd76b
leaq -0x150(%rbp), %rdi
callq 0x8770
movq -0x1a0(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x15c(%rbp)
movl -0x15c(%rbp), %esi
callq 0xfec0
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rax
cmpl $0x6, 0x10(%rax)
jne 0xd758
movq -0x168(%rbp), %rax
cmpl $0x4, 0x10(%rax)
jne 0xd6e6
movq -0x1a0(%rbp), %rdi
movq -0x168(%rbp), %rsi
callq 0xc5d0
jmp 0xd751
movq -0x1a0(%rbp), %rsi
movq -0x168(%rbp), %rdx
leaq -0x188(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x62d60
movq -0x1a0(%rbp), %rdi
movq -0x1a8(%rbp), %rsi
leaq 0x13b98a(%rip), %rdx    # 0x1490a6
callq 0xf270
jmp 0xd723
leaq -0x188(%rbp), %rdi
callq 0x7708
jmp 0xd751
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x190(%rbp)
movl %eax, -0x194(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x7708
jmp 0xd790
movb $0x1, -0xf1(%rbp)
jmp 0xd75a
leaq -0x150(%rbp), %rdi
callq 0x8790
jmp 0xd66a
testb $0x1, -0xf1(%rbp)
je 0xd787
movq -0x1a0(%rbp), %rdi
leaq 0x13111c(%rip), %rsi    # 0x13e89e
callq 0xedf0
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x190(%rbp), %rdi
callq 0x7640
nopl (%rax)