// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::emit_mix_op(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
void CompilerGLSL::emit_mix_op(uint32_t result_type, uint32_t id, uint32_t left, uint32_t right, uint32_t lerp)
{
	auto &lerptype = expression_type(lerp);
	auto &restype = get<SPIRType>(result_type);

	string mix_op;
	bool has_boolean_mix = backend.boolean_mix_support &&
	                       ((options.es && options.version >= 310) || (!options.es && options.version >= 450));
	bool trivial_mix = to_trivial_mix_op(restype, mix_op, left, right, lerp);

	// Cannot use boolean mix when the lerp argument is just one boolean,
	// fall back to regular trinary statements.
	if (lerptype.vecsize == 1)
		has_boolean_mix = false;

	// If we can reduce the mix to a simple cast, do so.
	// This helps for cases like int(bool), uint(bool) which is implemented with
	// OpSelect bool 1 0.
	if (trivial_mix)
	{
		emit_unary_func_op(result_type, id, lerp, mix_op.c_str());
	}
	else if (!has_boolean_mix && lerptype.basetype == SPIRType::Boolean)
	{
		// Boolean mix not supported on desktop without extension.
		// Was added in OpenGL 4.5 with ES 3.1 compat.
		//
		// Could use GL_EXT_shader_integer_mix on desktop at least,
		// but Apple doesn't support it. :(
		// Just implement it as ternary expressions.
		auto expr = to_ternary_expression(get<SPIRType>(result_type), lerp, right, left);
		emit_op(result_type, id, expr, should_forward(left) && should_forward(right) && should_forward(lerp));
		inherit_expression_dependencies(id, left);
		inherit_expression_dependencies(id, right);
		inherit_expression_dependencies(id, lerp);
	}
	else
		emit_trinary_func_op(result_type, id, left, right, lerp, "mix");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x98(%rbp)
movl -0x1c(%rbp), %esi
callq 0x1f760
movq -0x98(%rbp), %rdi
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %esi
callq 0xea90
movq %rax, -0x30(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x7530
movq -0x98(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x62a(%rcx)
movb %al, -0x89(%rbp)
je 0x7ad20
movq -0x98(%rbp), %rax
testb $0x1, 0x43c(%rax)
je 0x7acd6
movq -0x98(%rbp), %rcx
movb $0x1, %al
cmpl $0x136, 0x438(%rcx)     # imm = 0x136
movb %al, -0x99(%rbp)
jae 0x7ad14
movq -0x98(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x43c(%rcx)
movb %al, -0x9a(%rbp)
jne 0x7ad08
movq -0x98(%rbp), %rax
cmpl $0x1c2, 0x438(%rax)     # imm = 0x1C2
setae %al
movb %al, -0x9a(%rbp)
movb -0x9a(%rbp), %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
movb %al, -0x89(%rbp)
movq -0x98(%rbp), %rdi
movb -0x89(%rbp), %al
andb $0x1, %al
movb %al, -0x51(%rbp)
movq -0x30(%rbp), %rsi
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x1c(%rbp), %r9d
leaq -0x50(%rbp), %rdx
callq 0x72f90
movb %al, -0x9b(%rbp)
jmp 0x7ad52
movb -0x9b(%rbp), %al
andb $0x1, %al
movb %al, -0x52(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, 0x14(%rax)
jne 0x7ad7e
movb $0x0, -0x51(%rbp)
jmp 0x7ad7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x7af8e
testb $0x1, -0x52(%rbp)
je 0x7add0
movl -0xc(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0xa0(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x7160
movq -0x98(%rbp), %rdi
movl -0xa8(%rbp), %esi
movl -0xa4(%rbp), %edx
movl -0xa0(%rbp), %ecx
movq %rax, %r8
callq 0x79220
jmp 0x7adcb
jmp 0x7af7c
testb $0x1, -0x51(%rbp)
jne 0x7af4c
movq -0x28(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x7af4c
movq -0x98(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0xea90
movq %rax, -0xb0(%rbp)
jmp 0x7ae00
movq -0xb0(%rbp), %rdx
movq -0x98(%rbp), %rsi
movl -0x1c(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x14(%rbp), %r9d
leaq -0x88(%rbp), %rdi
callq 0x73240
jmp 0x7ae27
movq -0x98(%rbp), %rdi
movl -0xc(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0x14(%rbp), %esi
callq 0x78810
movb %al, -0xb1(%rbp)
jmp 0x7ae50
movb -0xb1(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xbd(%rbp)
jne 0x7ae65
jmp 0x7aeb6
movq -0x98(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x78810
movb %al, -0xbe(%rbp)
jmp 0x7ae7c
movb -0xbe(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xbd(%rbp)
jne 0x7ae91
jmp 0x7aeb6
movq -0x98(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x78810
movb %al, -0xbf(%rbp)
jmp 0x7aea8
movb -0xbf(%rbp), %al
movb %al, -0xbd(%rbp)
jmp 0x7aeb6
movl -0xb8(%rbp), %edx
movl -0xbc(%rbp), %esi
movq -0x98(%rbp), %rdi
movb -0xbd(%rbp), %al
movzbl %al, %r8d
andl $0x1, %r8d
leaq -0x88(%rbp), %rcx
xorl %r9d, %r9d
callq 0x784f0
jmp 0x7aee8
movq -0x98(%rbp), %rdi
movl -0x10(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x25500
jmp 0x7aefc
movq -0x98(%rbp), %rdi
movl -0x10(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x25500
jmp 0x7af10
movq -0x98(%rbp), %rdi
movl -0x10(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x25500
jmp 0x7af24
leaq -0x88(%rbp), %rdi
callq 0x7708
jmp 0x7af7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x7708
jmp 0x7af8e
movq -0x98(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x1c(%rbp), %r9d
leaq 0xc6ae3(%rip), %r10     # 0x141a4e
movq %rsp, %rax
movq %r10, (%rax)
callq 0x798c0
jmp 0x7af78
jmp 0x7af7a
jmp 0x7af7c
leaq -0x50(%rbp), %rdi
callq 0x7708
addq $0xd0, %rsp
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x7708
movq -0x60(%rbp), %rdi
callq 0x7640