// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::replace_fragment_output(spirv_cross::SPIRVariable&)
void CompilerGLSL::replace_fragment_output(SPIRVariable &var)
{
	auto &m = ir.meta[var.self].decoration;
	uint32_t location = 0;
	if (m.decoration_flags.get(DecorationLocation))
		location = m.location;

	// If our variable is arrayed, we must not emit the array part of this as the SPIR-V will
	// do the access chain part of this for us.
	auto &type = get<SPIRType>(var.basetype);

	if (type.array.empty())
	{
		// Redirect the write to a specific render target in legacy GLSL.
		m.alias = join("gl_FragData[", location, "]");

		if (is_legacy_es() && location != 0)
			require_extension_internal("GL_EXT_draw_buffers");
	}
	else if (type.array.size() == 1)
	{
		// If location is non-zero, we probably have to add an offset.
		// This gets really tricky since we'd have to inject an offset in the access chain.
		// FIXME: This seems like an extremely odd-ball case, so it's probably fine to leave it like this for now.
		m.alias = "gl_FragData";
		if (location != 0)
			SPIRV_CROSS_THROW("Arrayed output variable used, but location is not 0. "
			                  "This is unimplemented in SPIRV-Cross.");

		if (is_legacy_es())
			require_extension_internal("GL_EXT_draw_buffers");
	}
	else
		SPIRV_CROSS_THROW("Array-of-array output variable used. This cannot be implemented in legacy GLSL.");

	var.compat_builtin = true; // We don't want to declare this variable, but use the name as-is.
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x100(%rbp)
addq $0x8, %rdi
addq $0x30, %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, %esi
callq 0xead0
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
addq $0x60, %rdi
movl $0x1e, %esi
callq 0xef50
testb $0x1, %al
jne 0x6f877
jmp 0x6f884
movq -0x18(%rbp), %rax
movl 0xa4(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x100(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0xea90
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
addq $0x20, %rdi
callq 0x8690
testb $0x1, %al
jne 0x6f8b1
jmp 0x6f986
leaq -0x48(%rbp), %rdi
leaq 0xd293b(%rip), %rsi     # 0x1421f7
leaq -0x1c(%rbp), %rdx
leaq 0xd87de(%rip), %rcx     # 0x1480a5
callq 0xa0740
movq -0x18(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x7430
leaq -0x48(%rbp), %rdi
callq 0x7708
movq -0x100(%rbp), %rdi
callq 0xa0800
testb $0x1, %al
jne 0x6f8f7
jmp 0x6f981
cmpl $0x0, -0x1c(%rbp)
je 0x6f981
leaq -0x69(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x7650
movq -0x108(%rbp), %rdx
leaq 0xd28e5(%rip), %rsi     # 0x142204
leaq -0x68(%rbp), %rdi
callq 0x7520
jmp 0x6f92a
movq -0x100(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x589d0
jmp 0x6f93c
leaq -0x68(%rbp), %rdi
callq 0x7708
leaq -0x69(%rbp), %rdi
callq 0x73d0
jmp 0x6f981
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x6f973
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x7708
leaq -0x69(%rbp), %rdi
callq 0x73d0
jmp 0x6fc13
jmp 0x6fc02
movq -0x28(%rbp), %rdi
addq $0x20, %rdi
callq 0x8650
cmpq $0x1, %rax
jne 0x6fb36
movq -0x18(%rbp), %rdi
leaq 0xd2870(%rip), %rsi     # 0x142218
callq 0x7510
cmpl $0x0, -0x1c(%rbp)
je 0x6fa87
movb $0x1, -0xa2(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x118(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x7650
movq -0x110(%rbp), %rdx
leaq 0xd2834(%rip), %rsi     # 0x142224
leaq -0xa0(%rbp), %rdi
callq 0x7520
jmp 0x6f9fe
movq -0x118(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x9c50
jmp 0x6fa13
movq -0x118(%rbp), %rdi
movb $0x0, -0xa2(%rbp)
leaq 0x13e3b0(%rip), %rsi    # 0x1addd8
leaq -0x65d9f(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x6fc1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x6fa5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x7708
leaq -0xa1(%rbp), %rdi
callq 0x73d0
testb $0x1, -0xa2(%rbp)
jne 0x6fa76
jmp 0x6fa82
movq -0x118(%rbp), %rdi
callq 0x72c0
jmp 0x6fc13
movq -0x100(%rbp), %rdi
callq 0xa0800
testb $0x1, %al
jne 0x6fa9c
jmp 0x6fb31
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x7650
movq -0x120(%rbp), %rdx
leaq 0xd2747(%rip), %rsi     # 0x142204
leaq -0xc8(%rbp), %rdi
callq 0x7520
jmp 0x6facb
movq -0x100(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x589d0
jmp 0x6fae0
leaq -0xc8(%rbp), %rdi
callq 0x7708
leaq -0xc9(%rbp), %rdi
callq 0x73d0
jmp 0x6fb31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x6fb20
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x7708
leaq -0xc9(%rbp), %rdi
callq 0x73d0
jmp 0x6fc13
jmp 0x6fc00
movb $0x1, -0xf2(%rbp)
movl $0x10, %edi
callq 0x71a0
movq %rax, -0x130(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x7650
movq -0x128(%rbp), %rdx
leaq 0xd2710(%rip), %rsi     # 0x14227f
leaq -0xf0(%rbp), %rdi
callq 0x7520
jmp 0x6fb7d
movq -0x130(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x9c50
jmp 0x6fb92
movq -0x130(%rbp), %rdi
movb $0x0, -0xf2(%rbp)
leaq 0x13e231(%rip), %rsi    # 0x1addd8
leaq -0x65f1e(%rip), %rdx    # 0x9c90
callq 0x7610
jmp 0x6fc1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x6fbdb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x7708
leaq -0xf1(%rbp), %rdi
callq 0x73d0
testb $0x1, -0xf2(%rbp)
jne 0x6fbf2
jmp 0x6fbfe
movq -0x130(%rbp), %rdi
callq 0x72c0
jmp 0x6fc13
jmp 0x6fc02
movq -0x10(%rbp), %rax
movb $0x1, 0x38(%rax)
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x7640
nopl (%rax)