// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::layout_for_member[abi:cxx11](spirv_cross::SPIRType const&, unsigned int)
string CompilerGLSL::layout_for_member(const SPIRType &type, uint32_t index)
{
	if (is_legacy())
		return "";

	bool is_block = ir.meta[type.self].decoration.decoration_flags.get(DecorationBlock) ||
	                ir.meta[type.self].decoration.decoration_flags.get(DecorationBufferBlock);
	if (!is_block)
		return "";

	auto &memb = ir.meta[type.self].members;
	if (index >= memb.size())
		return "";
	auto &dec = memb[index];

	vector<string> attr;

	// We can only apply layouts on members in block interfaces.
	// This is a bit problematic because in SPIR-V decorations are applied on the struct types directly.
	// This is not supported on GLSL, so we have to make the assumption that if a struct within our buffer block struct
	// has a decoration, it was originally caused by a top-level layout() qualifier in GLSL.
	//
	// We would like to go from (SPIR-V style):
	//
	// struct Foo { layout(row_major) mat4 matrix; };
	// buffer UBO { Foo foo; };
	//
	// to
	//
	// struct Foo { mat4 matrix; }; // GLSL doesn't support any layout shenanigans in raw struct declarations.
	// buffer UBO { layout(row_major) Foo foo; }; // Apply the layout on top-level.
	auto flags = combined_decoration_for_member(type, index);

	if (flags.get(DecorationRowMajor))
		attr.push_back("row_major");
	// We don't emit any global layouts, so column_major is default.
	//if (flags & (1ull << DecorationColMajor))
	//    attr.push_back("column_major");

	if (dec.decoration_flags.get(DecorationLocation) && can_use_io_location(type.storage, true))
		attr.push_back(join("location = ", dec.location));

	// Can only declare component if we can declare location.
	if (dec.decoration_flags.get(DecorationComponent) && can_use_io_location(type.storage, true))
	{
		if (!options.es)
		{
			if (options.version < 440 && options.version >= 140)
				require_extension_internal("GL_ARB_enhanced_layouts");
			else if (options.version < 140)
				SPIRV_CROSS_THROW("Component decoration is not supported in targets below GLSL 1.40.");
			attr.push_back(join("component = ", dec.component));
		}
		else
			SPIRV_CROSS_THROW("Component decoration is not supported in ES targets.");
	}

	// DecorationCPacked is set by layout_for_variable earlier to mark that we need to emit offset qualifiers.
	// This is only done selectively in GLSL as needed.
	if (has_decoration(type.self, DecorationCPacked) && dec.decoration_flags.get(DecorationOffset))
		attr.push_back(join("offset = ", dec.offset));

	if (attr.empty())
		return "";

	string res = "layout(";
	res += merge(attr);
	res += ") ";
	return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x1e8(%rbp)
movq %rdi, %rax
movq %rax, -0x1e0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x9f610
testb $0x1, %al
jne 0x5c641
jmp 0x5c695
leaq -0x1d(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x7650
movq -0x1e8(%rbp), %rdi
movq -0x1f0(%rbp), %rdx
leaq 0xe2238(%rip), %rsi     # 0x13e89e
callq 0x7520
jmp 0x5c66d
leaq -0x1d(%rbp), %rdi
callq 0x73d0
jmp 0x5cf74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1d(%rbp), %rdi
callq 0x73d0
jmp 0x5cf84
movq -0x1d8(%rbp), %rdi
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0x60, %rdi
movl $0x2, %esi
callq 0xef50
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x1f1(%rbp)
jne 0x5c706
movq -0x1d8(%rbp), %rdi
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, %rdi
addq $0x60, %rdi
movl $0x3, %esi
callq 0xef50
movb %al, -0x1f1(%rbp)
movb -0x1f1(%rbp), %al
andb $0x1, %al
movb %al, -0x2d(%rbp)
testb $0x1, -0x2d(%rbp)
jne 0x5c76b
leaq -0x2e(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0x7650
movq -0x1e8(%rbp), %rdi
movq -0x200(%rbp), %rdx
leaq 0xe2162(%rip), %rsi     # 0x13e89e
callq 0x7520
jmp 0x5c743
leaq -0x2e(%rbp), %rdi
callq 0x73d0
jmp 0x5cf74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x2e(%rbp), %rdi
callq 0x73d0
jmp 0x5cf84
movq -0x1d8(%rbp), %rdi
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
addq $0xd0, %rax
movq %rax, -0x38(%rbp)
movl -0x1c(%rbp), %eax
movq %rax, -0x208(%rbp)
movq -0x38(%rbp), %rdi
callq 0x2eca0
movq %rax, %rcx
movq -0x208(%rbp), %rax
cmpq %rcx, %rax
jb 0x5c808
leaq -0x39(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x7650
movq -0x1e8(%rbp), %rdi
movq -0x210(%rbp), %rdx
leaq 0xe20c5(%rip), %rsi     # 0x13e89e
callq 0x7520
jmp 0x5c7e0
leaq -0x39(%rbp), %rdi
callq 0x73d0
jmp 0x5cf74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x73d0
jmp 0x5cf84
movq -0x38(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x2fa30
movq %rax, -0x48(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x30390
movq -0x1d8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
leaq -0xa0(%rbp), %rdi
callq 0x2c660
jmp 0x5c83f
leaq -0xa0(%rbp), %rdi
movl $0x4, %esi
callq 0xef50
movb %al, -0x211(%rbp)
jmp 0x5c858
movb -0x211(%rbp), %al
testb $0x1, %al
jne 0x5c867
jmp 0x5c91b
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x7650
movq -0x220(%rbp), %rdx
leaq 0xe4722(%rip), %rsi     # 0x140faa
leaq -0xc0(%rbp), %rdi
callq 0x7520
jmp 0x5c896
leaq -0x60(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xecd0
jmp 0x5c8a8
leaq -0xc0(%rbp), %rdi
callq 0x7708
leaq -0xc1(%rbp), %rdi
callq 0x73d0
jmp 0x5c91b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5cf69
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5cf5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5c90a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x7708
leaq -0xc1(%rbp), %rdi
callq 0x73d0
jmp 0x5cf5d
movq -0x48(%rbp), %rdi
addq $0x60, %rdi
movl $0x1e, %esi
callq 0xef50
movb %al, -0x221(%rbp)
jmp 0x5c935
movb -0x221(%rbp), %al
testb $0x1, %al
jne 0x5c944
jmp 0x5c9cd
movq -0x1d8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x64(%rax), %esi
movl $0x1, %edx
callq 0x5cf90
movb %al, -0x222(%rbp)
jmp 0x5c964
movb -0x222(%rbp), %al
testb $0x1, %al
jne 0x5c970
jmp 0x5c9cd
movq -0x48(%rbp), %rdx
addq $0xa4, %rdx
leaq 0xe4632(%rip), %rsi     # 0x140fb4
leaq -0xe8(%rbp), %rdi
callq 0x9ee20
jmp 0x5c990
leaq -0x60(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0xecd0
jmp 0x5c9a2
leaq -0xe8(%rbp), %rdi
callq 0x7708
jmp 0x5c9cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x7708
jmp 0x5cf5d
movq -0x48(%rbp), %rdi
addq $0x60, %rdi
movl $0x1f, %esi
callq 0xef50
movb %al, -0x223(%rbp)
jmp 0x5c9e7
movb -0x223(%rbp), %al
testb $0x1, %al
jne 0x5c9f6
jmp 0x5cd1a
movq -0x1d8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x64(%rax), %esi
movl $0x1, %edx
callq 0x5cf90
movb %al, -0x224(%rbp)
jmp 0x5ca16
movb -0x224(%rbp), %al
testb $0x1, %al
jne 0x5ca25
jmp 0x5cd1a
movq -0x1d8(%rbp), %rax
testb $0x1, 0x43c(%rax)
jne 0x5cc48
movq -0x1d8(%rbp), %rax
cmpl $0x1b8, 0x438(%rax)     # imm = 0x1B8
jae 0x5caff
movq -0x1d8(%rbp), %rax
cmpl $0x8c, 0x438(%rax)
jb 0x5caff
leaq -0x109(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x7650
movq -0x230(%rbp), %rdx
leaq 0xe4538(%rip), %rsi     # 0x140fc0
leaq -0x108(%rbp), %rdi
callq 0x7520
jmp 0x5ca96
movq -0x1d8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x589d0
jmp 0x5caab
leaq -0x108(%rbp), %rdi
callq 0x7708
leaq -0x109(%rbp), %rdi
callq 0x73d0
jmp 0x5cbe8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5caee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x7708
leaq -0x109(%rbp), %rdi
callq 0x73d0
jmp 0x5cf5d
movq -0x1d8(%rbp), %rax
cmpl $0x8c, 0x438(%rax)
jae 0x5cbe6
movb $0x1, -0x132(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x240(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x7650
movq -0x238(%rbp), %rdx
leaq 0xe4489(%rip), %rsi     # 0x140fd8
leaq -0x130(%rbp), %rdi
callq 0x7520
jmp 0x5cb5d
movq -0x240(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x9c50
jmp 0x5cb72
movq -0x240(%rbp), %rdi
movb $0x0, -0x132(%rbp)
leaq 0x151251(%rip), %rsi    # 0x1addd8
leaq -0x52efe(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x5cf8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5cbbe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x7708
leaq -0x131(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x132(%rbp)
jne 0x5cbd5
jmp 0x5cbe1
movq -0x240(%rbp), %rdi
callq 0x72c0
jmp 0x5cf5d
jmp 0x5cbe8
movq -0x48(%rbp), %rdx
addq $0xa8, %rdx
leaq 0xe4420(%rip), %rsi     # 0x14101a
leaq -0x158(%rbp), %rdi
callq 0x9f680
jmp 0x5cc08
leaq -0x60(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0xecd0
jmp 0x5cc1a
leaq -0x158(%rbp), %rdi
callq 0x7708
jmp 0x5cd18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x7708
jmp 0x5cf5d
movb $0x1, -0x17a(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x250(%rbp)
leaq -0x179(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x7650
movq -0x248(%rbp), %rdx
leaq 0xe43a6(%rip), %rsi     # 0x141027
leaq -0x178(%rbp), %rdi
callq 0x7520
jmp 0x5cc8f
movq -0x250(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x9c50
jmp 0x5cca4
movq -0x250(%rbp), %rdi
movb $0x0, -0x17a(%rbp)
leaq 0x15111f(%rip), %rsi    # 0x1addd8
leaq -0x53030(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x5cf8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5ccf0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x7708
leaq -0x179(%rbp), %rdi
callq 0x73d0
testb $0x1, -0x17a(%rbp)
jne 0x5cd07
jmp 0x5cd13
movq -0x250(%rbp), %rdi
callq 0x72c0
jmp 0x5cf5d
jmp 0x5cd1a
movq -0x1d8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x8(%rax), %esi
movl $0xa, %edx
callq 0x1f560
movb %al, -0x251(%rbp)
jmp 0x5cd3a
movb -0x251(%rbp), %al
testb $0x1, %al
jne 0x5cd49
jmp 0x5cdcc
movq -0x48(%rbp), %rdi
addq $0x60, %rdi
movl $0x23, %esi
callq 0xef50
movb %al, -0x252(%rbp)
jmp 0x5cd63
movb -0x252(%rbp), %al
testb $0x1, %al
jne 0x5cd6f
jmp 0x5cdcc
movq -0x48(%rbp), %rdx
addq $0xb4, %rdx
leaq 0xe42db(%rip), %rsi     # 0x14105c
leaq -0x1a0(%rbp), %rdi
callq 0x9f730
jmp 0x5cd8f
leaq -0x60(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0xecd0
jmp 0x5cda1
leaq -0x1a0(%rbp), %rdi
callq 0x7708
jmp 0x5cdcc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x7708
jmp 0x5cf5d
leaq -0x60(%rbp), %rdi
callq 0x9f150
testb $0x1, %al
jne 0x5cddb
jmp 0x5ce42
leaq -0x1a1(%rbp), %rdi
movq %rdi, -0x260(%rbp)
callq 0x7650
movq -0x1e8(%rbp), %rdi
movq -0x260(%rbp), %rdx
leaq 0xe1a9b(%rip), %rsi     # 0x13e89e
callq 0x7520
jmp 0x5ce0a
leaq -0x1a1(%rbp), %rdi
callq 0x73d0
movl $0x1, -0x1a8(%rbp)
jmp 0x5cf46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1a1(%rbp), %rdi
callq 0x73d0
jmp 0x5cf5d
movb $0x0, -0x1a9(%rbp)
leaq -0x1aa(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x7650
movq -0x1e8(%rbp), %rdi
movq -0x268(%rbp), %rdx
leaq 0xe40b5(%rip), %rsi     # 0x140f26
callq 0x7520
jmp 0x5ce78
leaq -0x1aa(%rbp), %rdi
callq 0x73d0
leaq -0x1d0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x9f2c0
jmp 0x5ce96
movq -0x1e8(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x7470
jmp 0x5ceab
leaq -0x1d0(%rbp), %rdi
callq 0x7708
movq -0x1e8(%rbp), %rdi
leaq 0xe8424(%rip), %rsi     # 0x1452e9
callq 0x7340
jmp 0x5cecc
movb $0x1, -0x1a9(%rbp)
movl $0x1, -0x1a8(%rbp)
testb $0x1, -0x1a9(%rbp)
jne 0x5cf36
jmp 0x5cf2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1aa(%rbp), %rdi
callq 0x73d0
jmp 0x5cf5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5cf38
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x7708
jmp 0x5cf38
movq -0x1e8(%rbp), %rdi
callq 0x7708
jmp 0x5cf46
movq -0x1e8(%rbp), %rdi
callq 0x7708
jmp 0x5cf5d
leaq -0xa0(%rbp), %rdi
callq 0xf250
leaq -0x60(%rbp), %rdi
callq 0x14cd0
jmp 0x5cf74
leaq -0xa0(%rbp), %rdi
callq 0xf250
leaq -0x60(%rbp), %rdi
callq 0x14cd0
jmp 0x5cf84
movq -0x1e0(%rbp), %rax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x7640
nopl (%rax)