#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 */
int __ieee754_rem_pio2(double, double *);
double __kernel_cos(double, double);
double __kernel_sin(double, double, int);
double ieee_sin(double x) {
  double y[2], z = 0.0;
  int n, ix;
  ix = *(int *)&x;
  ix &= 0x7fffffff;
  if (ix <= 0x3fe921fb)
    return __kernel_sin(x, z, 0);
  else if (ix >= 0x7ff00000)
    return x - x;
  else {
    n = __ieee754_rem_pio2(x, y);
    switch (n & 3) {
    case 0:
      return __kernel_sin(y[0], y[1], 1);
    case 1:
      return __kernel_cos(y[0], y[1]);
    case 2:
      return -__kernel_sin(y[0], y[1], 1);
    default:
      return -__kernel_cos(y[0], y[1]);
    }
  }
}


x86 assembly (clang, -O0):
<ieee_sin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
and    $0x7fffffff,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x3fe921fb,-0x30(%rbp)
jg     117e <ieee_sin+0x4e>
movsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
xor    %edi,%edi
call   1030 <__kernel_sin@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127d <ieee_sin+0x14d>
cmpl   $0x7ff00000,-0x30(%rbp)
jl     119f <ieee_sin+0x6f>
movsd  -0x10(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127d <ieee_sin+0x14d>
movsd  -0x10(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1040 <__ieee754_rem_pio2@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x34(%rbp)
je     11e6 <ieee_sin+0xb6>
jmp    11c4 <ieee_sin+0x94>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1204 <ieee_sin+0xd4>
jmp    11d5 <ieee_sin+0xa5>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     121d <ieee_sin+0xed>
jmp    1252 <ieee_sin+0x122>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127d <ieee_sin+0x14d>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1050 <__kernel_cos@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127d <ieee_sin+0x14d>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127d <ieee_sin+0x14d>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1050 <__kernel_cos@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ieee_sin>:
movq   %xmm0,%rax
and    $0x7fffffff,%eax
cmp    $0x3fe921fb,%eax
ja     114b <ieee_sin+0x1b>
xorps  %xmm1,%xmm1
xor    %edi,%edi
jmp    1030 <__kernel_sin@plt>
sub    $0x18,%rsp
cmp    $0x7ff00000,%eax
jb     115f <ieee_sin+0x2f>
subsd  %xmm0,%xmm0
add    $0x18,%rsp
ret
mov    %rsp,%rdi
call   1040 <__ieee754_rem_pio2@plt>
and    $0x3,%eax
cmp    $0x2,%eax
je     1192 <ieee_sin+0x62>
cmp    $0x1,%eax
je     11a9 <ieee_sin+0x79>
test   %eax,%eax
jne    11be <ieee_sin+0x8e>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
add    $0x18,%rsp
ret
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
jmp    11ce <ieee_sin+0x9e>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1050 <__kernel_cos@plt>
add    $0x18,%rsp
ret
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
call   1050 <__kernel_cos@plt>
xorps  0xe2b(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @ieee_sin(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca [2 x double]
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store double %0, double* %3
store double 0.000000e+00, double* %5
%8 = bitcast double* %3 to i32*
%9 = load i32, i32* %8
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = and i32 %10, 2147483647
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp sle i32 %12, 1072243195
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load double, double* %3
%16 = load double, double* %5
%17 = call double @__kernel_sin(double %15, double %16, i32 0)
store double %17, double* %2
br label %57
18: ; preds = %1
%19 = load i32, i32* %7
%20 = icmp sge i32 %19, 2146435072
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load double, double* %3
%23 = load double, double* %3
%24 = fsub double %22, %23
store double %24, double* %2
br label %57
25: ; preds = %18
%26 = load double, double* %3
%27 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%28 = call i32 @__ieee754_rem_pio2(double %26, double* %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = and i32 %29, 3
switch i32 %30, label %50 [
i32 0, label %31
i32 1, label %37
i32 2, label %43
]
31: ; preds = %25
%32 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%33 = load double, double* %32
%34 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%35 = load double, double* %34
%36 = call double @__kernel_sin(double %33, double %35, i32 1)
store double %36, double* %2
br label %57
37: ; preds = %25
%38 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%39 = load double, double* %38
%40 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%41 = load double, double* %40
%42 = call double @__kernel_cos(double %39, double %41)
store double %42, double* %2
br label %57
43: ; preds = %25
%44 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%45 = load double, double* %44
%46 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%47 = load double, double* %46
%48 = call double @__kernel_sin(double %45, double %47, i32 1)
%49 = fneg double %48
store double %49, double* %2
br label %57
50: ; preds = %25
%51 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%52 = load double, double* %51
%53 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 1
%54 = load double, double* %53
%55 = call double @__kernel_cos(double %52, double %54)
%56 = fneg double %55
store double %56, double* %2
br label %57
57: ; preds = %50, %43, %37, %31, %21, %14
%58 = load double, double* %2
ret double %58
}

LLVM IR (-O2):
define double @ieee_sin(double %0) {
%2 = alloca [2 x double]
%3 = bitcast [2 x double]* %2 to i8*
%4 = bitcast double %0 to i64
%5 = trunc i64 %4 to i32
%6 = and i32 %5, 2147483647
%7 = icmp ult i32 %6, 1072243196
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call double @__kernel_sin(double %0, double 0.000000e+00, i32 0)
br label %40
10: ; preds = %1
%11 = icmp ugt i32 %6, 2146435071
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = fsub double %0, %0
br label %40
14: ; preds = %10
%15 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%16 = call i32 @__ieee754_rem_pio2(double %0, double* %15)
%17 = and i32 %16, 3
switch i32 %17, label %34 [
i32 0, label %18
i32 1, label %23
i32 2, label %28
]
18: ; preds = %14
%19 = load double, double* %15
%20 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 1
%21 = load double, double* %20
%22 = call double @__kernel_sin(double %19, double %21, i32 1)
br label %40
23: ; preds = %14
%24 = load double, double* %15
%25 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 1
%26 = load double, double* %25
%27 = call double @__kernel_cos(double %24, double %26)
br label %40
28: ; preds = %14
%29 = load double, double* %15
%30 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 1
%31 = load double, double* %30
%32 = call double @__kernel_sin(double %29, double %31, i32 1)
%33 = fneg double %32
br label %40
34: ; preds = %14
%35 = load double, double* %15
%36 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 1
%37 = load double, double* %36
%38 = call double @__kernel_cos(double %35, double %37)
%39 = fneg double %38
br label %40
40: ; preds = %34, %28, %23, %18, %12, %8
%41 = phi double [ %9, %8 ], [ %13, %12 ], [ %39, %34 ], [ %33, %28 ], [ %27, %23 ], [ %22, %18 ]
ret double %41
}