#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 */
double floor(double);
double gammasgn(double x) {
  double fx;
  if (x > 0) {
    return 1.0;
  } else {
    fx = floor(x);
    if (x - fx == 0.0) {
      return 0.0;
    } else if ((int)fx % 2) {
      return -1.0;
    } else {
      return 1.0;
    }
  }
}


x86 assembly (clang, -O0):
<gammasgn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1141 <gammasgn+0x31>
movsd  0xec9(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11af <gammasgn+0x9f>
movsd  -0x10(%rbp),%xmm0
call   1030 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117a <gammasgn+0x6a>
jp     117a <gammasgn+0x6a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11af <gammasgn+0x9f>
cvttsd2si -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11a2 <gammasgn+0x92>
movsd  0xe70(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11af <gammasgn+0x9f>
movsd  0xe56(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gammasgn>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1125 <gammasgn+0x15>
movsd  0xedd(%rip),%xmm1
jmp    115b <gammasgn+0x4b>
movsd  %xmm0,(%rsp)
call   1030 <floor@plt>
xorpd  %xmm1,%xmm1
movsd  (%rsp),%xmm2
subsd  %xmm0,%xmm2
ucomisd %xmm1,%xmm2
jne    1144 <gammasgn+0x34>
jnp    115b <gammasgn+0x4b>
cvttsd2si %xmm0,%eax
xor    %ecx,%ecx
test   $0x1,%al
sete   %cl
lea    0xeb2(%rip),%rax
movsd  (%rax,%rcx,8),%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @gammasgn(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %3
%5 = load double, double* %3
%6 = fcmp ogt double %5, 0.000000e+00
br i1 %6, label %7, label %8
7: ; preds = %1
store double 1.000000e+00, double* %2
br label %23
8: ; preds = %1
%9 = load double, double* %3
%10 = call double @llvm.floor.f64(double %9)
store double %10, double* %4
%11 = load double, double* %3
%12 = load double, double* %4
%13 = fsub double %11, %12
%14 = fcmp oeq double %13, 0.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %8
store double 0.000000e+00, double* %2
br label %23
16: ; preds = %8
%17 = load double, double* %4
%18 = fptosi double %17 to i32
%19 = srem i32 %18, 2
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16
store double -1.000000e+00, double* %2
br label %23
22: ; preds = %16
store double 1.000000e+00, double* %2
br label %23
23: ; preds = %22, %21, %15, %7
%24 = load double, double* %2
ret double %24
}

LLVM IR (-O2):
define double @gammasgn(double %0) {
%2 = fcmp ogt double %0, 0.000000e+00
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = tail call double @llvm.floor.f64(double %0)
%5 = fsub double %0, %4
%6 = fcmp oeq double %5, 0.000000e+00
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = fptosi double %4 to i32
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, double 1.000000e+00, double -1.000000e+00
br label %12
12: ; preds = %7, %3, %1
%13 = phi double [ 1.000000e+00, %1 ], [ 0.000000e+00, %3 ], [ %11, %7 ]
ret double %13
}