#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ isnan(double);
int /*<<< orphan*/ printf(char *);
double signed_square(double x) {
  if (isnan(x)) {
    printf("IS NAN!!!\n");
    x = 0;
  }
  if (x > 0)
    return x * x;
  else
    return -x * x;
}


x86 assembly (clang, -O0):
<signed_square>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     1155 <signed_square+0x35>
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    117b <signed_square+0x5b>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a1 <signed_square+0x81>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signed_square>:
sub    $0x18,%rsp
movapd %xmm0,(%rsp)
call   1040 <isnan@plt>
movapd (%rsp),%xmm3
test   %rax,%rax
je     1148 <signed_square+0x28>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm3,%xmm3
movapd 0xeb0(%rip),%xmm1
xorpd  %xmm3,%xmm1
xorpd  %xmm0,%xmm0
cmpltsd %xmm3,%xmm0
movapd %xmm0,%xmm2
andpd  %xmm3,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
mulsd  %xmm3,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"IS NAN!!!\0A\00"
define double @signed_square(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = call i64 @isnan(double %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store double 0.000000e+00, double* %3
br label %9
9: ; preds = %7, %1
%10 = load double, double* %3
%11 = fcmp ogt double %10, 0.000000e+00
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load double, double* %3
%14 = load double, double* %3
%15 = fmul double %13, %14
store double %15, double* %2
br label %21
16: ; preds = %9
%17 = load double, double* %3
%18 = fneg double %17
%19 = load double, double* %3
%20 = fmul double %18, %19
store double %20, double* %2
br label %21
21: ; preds = %16, %12
%22 = load double, double* %2
ret double %22
}

LLVM IR (-O2):
@str = [10 x i8] c"IS NAN!!!\00"
define double @signed_square(double %0) {
%2 = tail call i64 @isnan(double %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = phi double [ 0.000000e+00, %4 ], [ %0, %1 ]
%8 = fcmp ogt double %7, 0.000000e+00
%9 = fneg double %7
%10 = select i1 %8, double %7, double %9
%11 = fmul double %7, %10
ret double %11
}