int test_sign(old, new) double old, new;
{
  if (old > 0.0 && new < 0.0) {
    if (old > 2.9 && new < -2.9)
      return 1;
    return (0);
  }
  if (old < 0.0 && new > 0.0) {
    if (old < -2.9 && new > 2.9)
      return -1;
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_sign>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1170 <test_sign+0x70>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1170 <test_sign+0x70>
movsd  -0x10(%rbp),%xmm0
movsd  0xecd(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1164 <test_sign+0x64>
movsd  0xeb3(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1164 <test_sign+0x64>
movl   $0x1,-0x4(%rbp)
jmp    11d9 <test_sign+0xd9>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <test_sign+0xd9>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11d2 <test_sign+0xd2>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11d2 <test_sign+0xd2>
movsd  0xe68(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11c6 <test_sign+0xc6>
movsd  -0x18(%rbp),%xmm0
movsd  0xe58(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c6 <test_sign+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <test_sign+0xd9>
movl   $0x0,-0x4(%rbp)
jmp    11d9 <test_sign+0xd9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sign>:
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm0
jbe    1130 <test_sign+0x30>
ucomisd %xmm1,%xmm2
jbe    1130 <test_sign+0x30>
ucomisd 0xef0(%rip),%xmm0
seta   %al
movsd  0xedd(%rip),%xmm0
ucomisd %xmm1,%xmm0
seta   %cl
and    %al,%cl
movzbl %cl,%eax
ret
xor    %eax,%eax
ucomisd %xmm0,%xmm2
jbe    1163 <test_sign+0x63>
xorpd  %xmm2,%xmm2
ucomisd %xmm2,%xmm1
jbe    1163 <test_sign+0x63>
movsd  0xeb6(%rip),%xmm2
ucomisd %xmm0,%xmm2
seta   %al
ucomisd 0xeaf(%rip),%xmm1
seta   %cl
and    %al,%cl
movzbl %cl,%eax
neg    %eax
ret

LLVM IR (-O0):
define i32 @test_sign(double %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp ogt double %6, 0.000000e+00
br i1 %7, label %8, label %19
8: ; preds = %2
%9 = load double, double* %5
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load double, double* %4
%13 = fcmp ogt double %12, 2.900000e+00
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load double, double* %5
%16 = fcmp olt double %15, -2.900000e+00
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 1, i32* %3
br label %34
18: ; preds = %14, %11
store i32 0, i32* %3
br label %34
19: ; preds = %8, %2
%20 = load double, double* %4
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = load double, double* %5
%24 = fcmp ogt double %23, 0.000000e+00
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load double, double* %4
%27 = fcmp olt double %26, -2.900000e+00
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load double, double* %5
%30 = fcmp ogt double %29, 2.900000e+00
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 -1, i32* %3
br label %34
32: ; preds = %28, %25
store i32 0, i32* %3
br label %34
33: ; preds = %22, %19
store i32 0, i32* %3
br label %34
34: ; preds = %33, %32, %31, %18, %17
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @test_sign(double %0, double %1) {
%3 = fcmp ogt double %0, 0.000000e+00
%4 = fcmp olt double %1, 0.000000e+00
%5 = and i1 %3, %4
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = fcmp ogt double %0, 2.900000e+00
%8 = fcmp olt double %1, -2.900000e+00
%9 = and i1 %7, %8
%10 = zext i1 %9 to i32
br label %20
11: ; preds = %2
%12 = fcmp olt double %0, 0.000000e+00
%13 = fcmp ogt double %1, 0.000000e+00
%14 = and i1 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = fcmp olt double %0, -2.900000e+00
%17 = fcmp ogt double %1, 2.900000e+00
%18 = and i1 %16, %17
%19 = sext i1 %18 to i32
br label %20
20: ; preds = %11, %15, %6
%21 = phi i32 [ %10, %6 ], [ %19, %15 ], [ 0, %11 ]
ret i32 %21
}