// File: rossy[P]crossc/SPIRV-Cross/spirv_hlsl.cpp
// Function: spirv_cross::CompilerHLSL::emit_interface_block_in_struct(spirv_cross::SPIRVariable const&, std::unordered_set<unsigned int, std::hash<unsigned int>, std::equal_to<unsigned int>, std::allocator<unsigned int>>&)
void CompilerHLSL::emit_interface_block_in_struct(const SPIRVariable &var, unordered_set<uint32_t> &active_locations)
{
	auto &execution = get_entry_point();
	auto type = get<SPIRType>(var.basetype);

	string binding;
	bool use_location_number = true;
	bool legacy = hlsl_options.shader_model <= 30;
	if (execution.model == ExecutionModelFragment && var.storage == StorageClassOutput)
	{
		binding = join(legacy ? "COLOR" : "SV_Target", get_decoration(var.self, DecorationLocation));
		use_location_number = false;
		if (legacy) // COLOR must be a four-component vector on legacy shader model targets (HLSL ERR_COLOR_4COMP)
			type.vecsize = 4;
	}

	const auto get_vacant_location = [&]() -> uint32_t {
		for (uint32_t i = 0; i < 64; i++)
			if (!active_locations.count(i))
				return i;
		SPIRV_CROSS_THROW("All locations from 0 to 63 are exhausted.");
	};

	bool need_matrix_unroll = var.storage == StorageClassInput && execution.model == ExecutionModelVertex;

	auto &m = ir.meta[var.self].decoration;
	auto name = to_name(var.self);
	if (use_location_number)
	{
		uint32_t location_number;

		// If an explicit location exists, use it with TEXCOORD[N] semantic.
		// Otherwise, pick a vacant location.
		if (m.decoration_flags.get(DecorationLocation))
			location_number = m.location;
		else
			location_number = get_vacant_location();

		// Allow semantic remap if specified.
		auto semantic = to_semantic(location_number);

		if (need_matrix_unroll && type.columns > 1)
		{
			if (!type.array.empty())
				SPIRV_CROSS_THROW("Arrays of matrices used as input/output. This is not supported.");

			// Unroll matrices.
			for (uint32_t i = 0; i < type.columns; i++)
			{
				SPIRType newtype = type;
				newtype.columns = 1;
				statement(to_interpolation_qualifiers(get_decoration_bitset(var.self)),
				          variable_decl(newtype, join(name, "_", i)), " : ", semantic, "_", i, ";");
				active_locations.insert(location_number++);
			}
		}
		else
		{
			statement(to_interpolation_qualifiers(get_decoration_bitset(var.self)), variable_decl(type, name), " : ",
			          semantic, ";");

			// Structs and arrays should consume more locations.
			uint32_t consumed_locations = type_to_consumed_locations(type);
			for (uint32_t i = 0; i < consumed_locations; i++)
				active_locations.insert(location_number + i);
		}
	}
	else
		statement(variable_decl(type, name), " : ", binding, ";");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x3c0(%rbp)
callq 0x25150
movq -0x3c0(%rbp), %rdi
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq %rax, %rsi
leaq -0xf8(%rbp), %rdi
callq 0x3d730
leaq -0x118(%rbp), %rdi
callq 0x7530
movq -0x3c0(%rbp), %rax
movb $0x1, -0x119(%rbp)
cmpl $0x1e, 0x788(%rax)
setbe %al
andb $0x1, %al
movb %al, -0x11a(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x4, 0xb8(%rax)
jne 0xbda56
movq -0x10(%rbp), %rax
cmpl $0x3, 0x10(%rax)
jne 0xbda56
movq -0x3c0(%rbp), %rdi
movb -0x11a(%rbp), %dl
leaq 0x88624(%rip), %rcx     # 0x145fd0
leaq 0x88623(%rip), %rax     # 0x145fd6
testb $0x1, %dl
cmovneq %rcx, %rax
movq %rax, -0x148(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
movl $0x1e, %edx
callq 0x23520
movl %eax, -0x3c4(%rbp)
jmp 0xbd9da
movl -0x3c4(%rbp), %eax
movl %eax, -0x14c(%rbp)
leaq -0x140(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0x14c(%rbp), %rdx
callq 0xd7760
jmp 0xbda02
leaq -0x118(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x7430
leaq -0x140(%rbp), %rdi
callq 0x7708
movb $0x0, -0x119(%rbp)
testb $0x1, -0x11a(%rbp)
je 0xbda54
movl $0x4, -0xe4(%rbp)
jmp 0xbda54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xbe142
jmp 0xbda56
movq -0x18(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpl $0x1, 0x10(%rcx)
movb %al, -0x3c5(%rbp)
jne 0xbda87
movq -0x20(%rbp), %rax
cmpl $0x0, 0xb8(%rax)
sete %al
movb %al, -0x3c5(%rbp)
movq -0x3c0(%rbp), %rdi
movb -0x3c5(%rbp), %al
andb $0x1, %al
movb %al, -0x169(%rbp)
addq $0x38, %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq -0x3c0(%rbp), %rsi
movq %rax, -0x178(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0x198(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0xbdada
testb $0x1, -0x119(%rbp)
je 0xbe084
movq -0x178(%rbp), %rdi
addq $0x60, %rdi
movl $0x1e, %esi
callq 0xef50
movb %al, -0x3c6(%rbp)
jmp 0xbdb04
movb -0x3c6(%rbp), %al
testb $0x1, %al
jne 0xbdb10
jmp 0xbdb3c
movq -0x178(%rbp), %rax
movl 0xa4(%rax), %eax
movl %eax, -0x19c(%rbp)
jmp 0xbdb5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xbe136
leaq -0x168(%rbp), %rdi
callq 0xbe170
movl %eax, -0x3cc(%rbp)
jmp 0xbdb50
movl -0x3cc(%rbp), %eax
movl %eax, -0x19c(%rbp)
movq -0x3c0(%rbp), %rsi
movl -0x19c(%rbp), %edx
leaq -0x1c0(%rbp), %rdi
callq 0xbd370
jmp 0xbdb77
testb $0x1, -0x169(%rbp)
je 0xbdeca
cmpl $0x1, -0xe0(%rbp)
jbe 0xbdeca
leaq -0xf8(%rbp), %rdi
addq $0x20, %rdi
callq 0x8690
testb $0x1, %al
jne 0xbdc85
movb $0x1, -0x1e2(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x3e0(%rbp)
leaq -0x1e1(%rbp), %rdi
movq %rdi, -0x3d8(%rbp)
callq 0x7650
movq -0x3d8(%rbp), %rdx
leaq 0x883fe(%rip), %rsi     # 0x145fe0
leaq -0x1e0(%rbp), %rdi
callq 0x7520
jmp 0xbdbf0
movq -0x3e0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x9c50
jmp 0xbdc05
movq -0x3e0(%rbp), %rdi
movb $0x0, -0x1e2(%rbp)
leaq 0xf01be(%rip), %rsi     # 0x1addd8
leaq -0xb3f91(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0xbe166
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xbdc5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x7708
leaq -0x1e1(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x1e2(%rbp)
jne 0xbdc74
jmp 0xbdc80
movq -0x3e0(%rbp), %rdi
callq 0x72c0
jmp 0xbe073
movl $0x0, -0x1e8(%rbp)
movl -0x1e8(%rbp), %eax
cmpl -0xe0(%rbp), %eax
jae 0xbdec5
leaq -0x2c0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x3d730
jmp 0xbdcb6
movq -0x3c0(%rbp), %rdi
movl $0x1, -0x2a8(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x23480
movq %rax, -0x3e8(%rbp)
jmp 0xbdcdc
movq -0x3e8(%rbp), %rdx
movq -0x3c0(%rbp), %rsi
movq (%rsi), %rax
movq 0x140(%rax), %rax
leaq -0x2e0(%rbp), %rdi
callq *%rax
jmp 0xbdcff
leaq 0x8a818(%rip), %rdx     # 0x14851e
leaq -0x320(%rbp), %rdi
leaq -0x198(%rbp), %rsi
leaq -0x1e8(%rbp), %rcx
callq 0xd7990
jmp 0xbdd22
movq -0x3c0(%rbp), %rsi
movq (%rsi), %rax
movq 0xc8(%rax), %rax
leaq -0x300(%rbp), %rdi
leaq -0x2c0(%rbp), %rdx
leaq -0x320(%rbp), %rcx
xorl %r8d, %r8d
callq *%rax
jmp 0xbdd4f
movq -0x3c0(%rbp), %rdi
leaq 0x8b349(%rip), %rcx     # 0x1490a6
movq %rsp, %rax
movq %rcx, 0x8(%rax)
leaq -0x1e8(%rbp), %rcx
movq %rcx, (%rax)
leaq 0x805e4(%rip), %rcx     # 0x13e359
leaq 0x8a7a2(%rip), %r9      # 0x14851e
leaq -0x2e0(%rbp), %rsi
leaq -0x300(%rbp), %rdx
leaq -0x1c0(%rbp), %r8
callq 0xd7810
jmp 0xbdd98
leaq -0x300(%rbp), %rdi
callq 0x7708
leaq -0x320(%rbp), %rdi
callq 0x7708
leaq -0x2e0(%rbp), %rdi
callq 0x7708
movq -0x18(%rbp), %rdi
movl -0x19c(%rbp), %eax
movl %eax, %ecx
incl %ecx
movl %ecx, -0x19c(%rbp)
movl %eax, -0x324(%rbp)
leaq -0x324(%rbp), %rsi
callq 0xd7a50
movb %dl, -0x3f1(%rbp)
movq %rax, -0x3f0(%rbp)
jmp 0xbddf1
movb -0x3f1(%rbp), %al
movq -0x3f0(%rbp), %rcx
movq %rcx, -0x338(%rbp)
movb %al, -0x330(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x314e0
movl -0x1e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e8(%rbp)
jmp 0xbdc8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xbe073
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xbdeb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xbdea8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xbde9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x300(%rbp), %rdi
callq 0x7708
leaq -0x320(%rbp), %rdi
callq 0x7708
leaq -0x2e0(%rbp), %rdi
callq 0x7708
leaq -0x2c0(%rbp), %rdi
callq 0x314e0
jmp 0xbe073
jmp 0xbe062
movq -0x3c0(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
callq 0x23480
movq %rax, -0x400(%rbp)
jmp 0xbdee6
movq -0x400(%rbp), %rdx
movq -0x3c0(%rbp), %rsi
movq (%rsi), %rax
movq 0x140(%rax), %rax
leaq -0x358(%rbp), %rdi
callq *%rax
jmp 0xbdf09
movq -0x3c0(%rbp), %rsi
movq (%rsi), %rax
movq 0xc8(%rax), %rax
leaq -0x378(%rbp), %rdi
leaq -0xf8(%rbp), %rdx
leaq -0x198(%rbp), %rcx
xorl %r8d, %r8d
callq *%rax
jmp 0xbdf36
movq -0x3c0(%rbp), %rdi
leaq 0x80415(%rip), %rcx     # 0x13e359
leaq 0x8b15b(%rip), %r9      # 0x1490a6
leaq -0x358(%rbp), %rsi
leaq -0x378(%rbp), %rdx
leaq -0x1c0(%rbp), %r8
callq 0xd7a90
jmp 0xbdf67
leaq -0x378(%rbp), %rdi
callq 0x7708
leaq -0x358(%rbp), %rdi
callq 0x7708
movq -0x3c0(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xbd090
movl %eax, -0x404(%rbp)
jmp 0xbdf9a
movl -0x404(%rbp), %eax
movl %eax, -0x37c(%rbp)
movl $0x0, -0x380(%rbp)
movl -0x380(%rbp), %eax
cmpl -0x37c(%rbp), %eax
jae 0xbe060
movq -0x18(%rbp), %rdi
movl -0x19c(%rbp), %eax
movl -0x380(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x384(%rbp)
leaq -0x384(%rbp), %rsi
callq 0xd7a50
movb %dl, -0x411(%rbp)
movq %rax, -0x410(%rbp)
jmp 0xbdff5
movb -0x411(%rbp), %al
movq -0x410(%rbp), %rcx
movq %rcx, -0x398(%rbp)
movb %al, -0x390(%rbp)
movl -0x380(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x380(%rbp)
jmp 0xbdfb0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
jmp 0xbe052
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x7708
leaq -0x358(%rbp), %rdi
callq 0x7708
jmp 0xbe073
jmp 0xbe062
leaq -0x1c0(%rbp), %rdi
callq 0x7708
jmp 0xbe109
leaq -0x1c0(%rbp), %rdi
callq 0x7708
jmp 0xbe136
movq -0x3c0(%rbp), %rsi
movq (%rsi), %rax
movq 0xc8(%rax), %rax
leaq -0x3b8(%rbp), %rdi
leaq -0xf8(%rbp), %rdx
leaq -0x198(%rbp), %rcx
xorl %r8d, %r8d
callq *%rax
jmp 0xbe0b1
movq -0x3c0(%rbp), %rdi
leaq 0x8029a(%rip), %rdx     # 0x13e359
leaq 0x8afe0(%rip), %r8      # 0x1490a6
leaq -0x3b8(%rbp), %rsi
leaq -0x118(%rbp), %rcx
callq 0xa4750
jmp 0xbe0db
leaq -0x3b8(%rbp), %rdi
callq 0x7708
jmp 0xbe109
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x3b8(%rbp), %rdi
callq 0x7708
jmp 0xbe136
leaq -0x198(%rbp), %rdi
callq 0x7708
leaq -0x118(%rbp), %rdi
callq 0x7708
leaq -0xf8(%rbp), %rdi
callq 0x314e0
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
leaq -0x198(%rbp), %rdi
callq 0x7708
leaq -0x118(%rbp), %rdi
callq 0x7708
leaq -0xf8(%rbp), %rdi
callq 0x314e0
movq -0x158(%rbp), %rdi
callq 0x7640
nopw %cs:(%rax,%rax)