// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::emit_flattened_io_block(spirv_cross::SPIRVariable const&, char const*)
void CompilerGLSL::emit_flattened_io_block(const SPIRVariable &var, const char *qual)
{
	auto &type = get<SPIRType>(var.basetype);
	if (!type.array.empty())
		SPIRV_CROSS_THROW("Array of varying structs cannot be flattened to legacy-compatible varyings.");

	auto old_flags = ir.meta[type.self].decoration.decoration_flags;
	// Emit the members as if they are part of a block to get all qualifiers.
	ir.meta[type.self].decoration.decoration_flags.set(DecorationBlock);

	type.member_name_cache.clear();

	uint32_t i = 0;
	for (auto &member : type.member_types)
	{
		add_member_name(type, i);
		auto &membertype = get<SPIRType>(member);

		if (membertype.basetype == SPIRType::Struct)
			SPIRV_CROSS_THROW("Cannot flatten struct inside structs in I/O variables.");

		// Pass in the varying qualifier here so it will appear in the correct declaration order.
		// Replace member name while emitting it so it encodes both struct name and member name.
		// Sanitize underscores because joining the two identifiers might create more than 1 underscore in a row,
		// which is not allowed.
		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, qual);
		// Restore member name.
		set_member_name(type.self, i, member_name);
		i++;
	}

	ir.meta[type.self].decoration.decoration_flags = old_flags;

	// Treat this variable as flattened from now on.
	flattened_structs.insert(var.self);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x240, %rsp            # imm = 0x240
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x8690
testb $0x1, %al
jne 0x61caf
movb $0x1, -0x55(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x1e0(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x7650
movq -0x1d8(%rbp), %rdx
leaq 0xdf965(%rip), %rsi     # 0x14158f
leaq -0x40(%rbp), %rdi
callq 0x7520
jmp 0x61c35
movq -0x1e0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x9c50
jmp 0x61c47
movq -0x1e0(%rbp), %rdi
movb $0x0, -0x55(%rbp)
leaq 0x14c17f(%rip), %rsi    # 0x1addd8
leaq -0x57fd0(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x6222e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x61c8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x7708
leaq -0x41(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x55(%rbp)
jne 0x61c9e
jmp 0x61caa
movq -0x1e0(%rbp), %rdi
callq 0x72c0
jmp 0x62225
movq -0x1d0(%rbp), %rdi
addq $0x38, %rdi
movq %rdi, -0x1e8(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rsi
addq $0x60, %rsi
leaq -0x98(%rbp), %rdi
callq 0xef10
movq -0x1e8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0x60, %rdi
movl $0x2, %esi
callq 0x300d0
jmp 0x61d0a
movq -0x20(%rbp), %rdi
addq $0xa0, %rdi
callq 0x9e1e0
movl $0x0, -0x9c(%rbp)
movq -0x20(%rbp), %rax
addq $0x68, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x86d0
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
callq 0x8700
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x8730
testb $0x1, %al
jne 0x61d75
jmp 0x62192
leaq -0xb0(%rbp), %rdi
callq 0x8770
movq -0x1d0(%rbp), %rdi
movq %rax, -0xc0(%rbp)
movq -0x20(%rbp), %rsi
movl -0x9c(%rbp), %edx
callq 0x5c240
jmp 0x61da0
movq -0x1d0(%rbp), %rdi
movq -0xc0(%rbp), %rax
movl (%rax), %esi
callq 0xea90
movq %rax, -0x1f0(%rbp)
jmp 0x61dbe
movq -0x1f0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
cmpl $0xc, 0xc(%rax)
jne 0x61ebe
movb $0x1, -0xea(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x200(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x7650
movq -0x1f8(%rbp), %rdx
leaq 0xdf7c5(%rip), %rsi     # 0x1415db
leaq -0xe8(%rbp), %rdi
callq 0x7520
jmp 0x61e24
movq -0x200(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x9c50
jmp 0x61e39
movq -0x200(%rbp), %rdi
movb $0x0, -0xea(%rbp)
leaq 0x14bf8a(%rip), %rsi    # 0x1addd8
leaq -0x581c5(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x6222e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x62219
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x61e96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x7708
leaq -0xe9(%rbp), %rdi
callq 0x73d0
testb $0x1, -0xea(%rbp)
jne 0x61ead
jmp 0x61eb9
movq -0x200(%rbp), %rdi
callq 0x72c0
jmp 0x62219
movq -0x1d0(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x9c(%rbp), %edx
callq 0x22fd0
movq %rax, -0x208(%rbp)
jmp 0x61ee0
movq -0x208(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x7170
jmp 0x61ef5
movq -0x1d0(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl -0x9c(%rbp), %ecx
leaq -0x130(%rbp), %rdi
callq 0x62230
jmp 0x61f14
movq -0x1d0(%rbp), %rsi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x210(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x20c(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0x190(%rbp), %rdi
movl $0x1, %ecx
callq *%rax
jmp 0x61f52
leaq 0xe65c5(%rip), %rdx     # 0x14851e
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
leaq -0x130(%rbp), %rcx
callq 0x9ff30
jmp 0x61f75
leaq -0x150(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x577c0
jmp 0x61f8a
movl -0x20c(%rbp), %edx
movl -0x210(%rbp), %esi
movq -0x1d0(%rbp), %rdi
leaq -0x150(%rbp), %rcx
callq 0x22f90
jmp 0x61fab
leaq -0x150(%rbp), %rdi
callq 0x7708
leaq -0x170(%rbp), %rdi
callq 0x7708
leaq -0x190(%rbp), %rdi
callq 0x7708
movq -0x20(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0xc0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x228(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x224(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x1b1(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x7650
movq -0x220(%rbp), %rsi
movq -0x218(%rbp), %rdx
leaq -0x1b0(%rbp), %rdi
callq 0x7520
jmp 0x6202f
movl -0x224(%rbp), %ecx
movl -0x228(%rbp), %edx
movq -0x230(%rbp), %rsi
movq -0x1d0(%rbp), %rdi
movq (%rdi), %rax
movq 0xa8(%rax), %rax
leaq -0x1b0(%rbp), %r8
xorl %r9d, %r9d
callq *%rax
jmp 0x62061
leaq -0x1b0(%rbp), %rdi
callq 0x7708
leaq -0x1b1(%rbp), %rdi
callq 0x73d0
movq -0x1d0(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x9c(%rbp), %edx
leaq -0x130(%rbp), %rcx
callq 0x22f90
jmp 0x6209b
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x7708
leaq -0x110(%rbp), %rdi
callq 0x7708
leaq -0xb0(%rbp), %rdi
callq 0x8790
jmp 0x61d59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x62181
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x62175
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x62135
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x62129
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x7708
leaq -0x170(%rbp), %rdi
callq 0x7708
leaq -0x190(%rbp), %rdi
callq 0x7708
jmp 0x62175
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x62169
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x7708
leaq -0x1b1(%rbp), %rdi
callq 0x73d0
leaq -0x130(%rbp), %rdi
callq 0x7708
leaq -0x110(%rbp), %rdi
callq 0x7708
jmp 0x62219
movq -0x1d0(%rbp), %rdi
addq $0x38, %rdi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0x60, %rdi
leaq -0x98(%rbp), %rsi
callq 0x38560
jmp 0x621c0
movq -0x1d0(%rbp), %rdi
addq $0x6b0, %rdi            # imm = 0x6B0
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
callq 0x2e890
movb %dl, -0x239(%rbp)
movq %rax, -0x238(%rbp)
jmp 0x621ea
movb -0x239(%rbp), %al
movq -0x238(%rbp), %rcx
movq %rcx, -0x1c8(%rbp)
movb %al, -0x1c0(%rbp)
leaq -0x98(%rbp), %rdi
callq 0xf250
addq $0x240, %rsp            # imm = 0x240
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0xf250
movq -0x50(%rbp), %rdi
callq 0x7640
nop