// File: rossy[P]crossc/SPIRV-Cross/spirv_glsl.cpp
// Function: spirv_cross::CompilerGLSL::to_trivial_mix_op(spirv_cross::SPIRType const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, unsigned int, unsigned int, unsigned int)
bool CompilerGLSL::to_trivial_mix_op(const SPIRType &type, string &op, uint32_t left, uint32_t right, uint32_t lerp)
{
	auto *cleft = maybe_get<SPIRConstant>(left);
	auto *cright = maybe_get<SPIRConstant>(right);
	auto &lerptype = expression_type(lerp);

	// If our targets aren't constants, we cannot use construction.
	if (!cleft || !cright)
		return false;

	// If our targets are spec constants, we cannot use construction.
	if (cleft->specialization || cright->specialization)
		return false;

	// We can only use trivial construction if we have a scalar
	// (should be possible to do it for vectors as well, but that is overkill for now).
	if (lerptype.basetype != SPIRType::Boolean || lerptype.vecsize > 1)
		return false;

	// If our bool selects between 0 and 1, we can cast from bool instead, making our trivial constructor.
	bool ret = false;
	switch (type.basetype)
	{
	case SPIRType::Int:
	case SPIRType::UInt:
		ret = cleft->scalar() == 0 && cright->scalar() == 1;
		break;

	case SPIRType::Half:
		ret = cleft->scalar_f16() == 0.0f && cright->scalar_f16() == 1.0f;
		break;

	case SPIRType::Float:
		ret = cleft->scalar_f32() == 0.0f && cright->scalar_f32() == 1.0f;
		break;

	case SPIRType::Double:
		ret = cleft->scalar_f64() == 0.0 && cright->scalar_f64() == 1.0;
		break;

	case SPIRType::Int64:
	case SPIRType::UInt64:
		ret = cleft->scalar_u64() == 0 && cright->scalar_u64() == 1;
		break;

	default:
		break;
	}

	if (ret)
		op = type_to_glsl_constructor(type);
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movl %r8d, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x78(%rbp)
movl -0x24(%rbp), %esi
callq 0xa2eb0
movq -0x78(%rbp), %rdi
movq %rax, -0x38(%rbp)
movl -0x28(%rbp), %esi
callq 0xa2eb0
movq -0x78(%rbp), %rdi
movq %rax, -0x40(%rbp)
movl -0x2c(%rbp), %esi
callq 0x1f760
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x72ff4
cmpq $0x0, -0x40(%rbp)
jne 0x72ffd
movb $0x0, -0x1(%rbp)
jmp 0x7322d
movq -0x38(%rbp), %rax
testb $0x1, 0x108(%rax)
jne 0x73017
movq -0x40(%rbp), %rax
testb $0x1, 0x108(%rax)
je 0x73020
movb $0x0, -0x1(%rbp)
jmp 0x7322d
movq -0x48(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x73034
movq -0x48(%rbp), %rax
cmpl $0x1, 0x14(%rax)
jbe 0x7303d
movb $0x0, -0x1(%rbp)
jmp 0x7322d
movb $0x0, -0x49(%rbp)
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
addl $-0x4, %eax
movl %eax, %ecx
movq %rcx, -0x80(%rbp)
subl $0x7, %eax
ja 0x731f6
movq -0x80(%rbp), %rax
leaq 0xcd2f7(%rip), %rcx     # 0x14035c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x38(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x2f560
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x81(%rbp)
jne 0x730a3
movq -0x40(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x2f560
cmpl $0x1, %eax
sete %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
andb $0x1, %al
movb %al, -0x49(%rbp)
jmp 0x731f8
movq -0x38(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa1980
xorl %eax, %eax
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movb %al, -0x82(%rbp)
jne 0x730f8
jp 0x730f8
movq -0x40(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa1980
movss 0xcb0d5(%rip), %xmm1    # 0x13e1bc
ucomiss %xmm1, %xmm0
sete %al
setnp %cl
andb %cl, %al
movb %al, -0x82(%rbp)
movb -0x82(%rbp), %al
andb $0x1, %al
movb %al, -0x49(%rbp)
jmp 0x731f8
movq -0x38(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa1ea0
xorl %eax, %eax
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movb %al, -0x83(%rbp)
jne 0x7314d
jp 0x7314d
movq -0x40(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa1ea0
movss 0xcb080(%rip), %xmm1    # 0x13e1bc
ucomiss %xmm1, %xmm0
sete %al
setnp %cl
andb %cl, %al
movb %al, -0x83(%rbp)
movb -0x83(%rbp), %al
andb $0x1, %al
movb %al, -0x49(%rbp)
jmp 0x731f8
movq -0x38(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa1f90
xorl %eax, %eax
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
movb %al, -0x84(%rbp)
jne 0x731a4
jp 0x731a4
movq -0x40(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa1f90
movsd 0xcd7fe(%rip), %xmm1    # 0x140990
ucomisd %xmm1, %xmm0
sete %al
setnp %cl
andb %cl, %al
movb %al, -0x84(%rbp)
movb -0x84(%rbp), %al
andb $0x1, %al
movb %al, -0x49(%rbp)
jmp 0x731f8
movq -0x38(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa2020
movq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x85(%rbp)
jne 0x731e9
movq -0x40(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0xa2020
cmpq $0x1, %rax
sete %al
movb %al, -0x85(%rbp)
movb -0x85(%rbp), %al
andb $0x1, %al
movb %al, -0x49(%rbp)
jmp 0x731f8
jmp 0x731f8
testb $0x1, -0x49(%rbp)
je 0x73225
movq -0x78(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x72bf0
movq -0x20(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x7430
leaq -0x70(%rbp), %rdi
callq 0x7708
movb -0x49(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)