#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 sin(double x) {
  double y[2], z = 0.0;
  int n, ix;
  ix = *(1 + (const 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):
<sin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
and    $0x7fffffff,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x3fe921fb,-0x30(%rbp)
jg     117e <sin+0x4e>
movsd  -0x10(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
xor    %edi,%edi
call   1030 <__kernel_sin@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127d <sin+0x14d>
cmpl   $0x7ff00000,-0x30(%rbp)
jl     119f <sin+0x6f>
movsd  -0x10(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    127d <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 <sin+0xb6>
jmp    11c4 <sin+0x94>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1204 <sin+0xd4>
jmp    11d5 <sin+0xa5>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     121d <sin+0xed>
jmp    1252 <sin+0x122>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127d <sin+0x14d>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1050 <__kernel_cos@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    127d <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 <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):
<sin>:
movq   %xmm0,%rax
shr    $0x20,%rax
and    $0x7fffffff,%eax
cmp    $0x3fe921fb,%eax
ja     114f <sin+0x1f>
xorps  %xmm1,%xmm1
xor    %edi,%edi
jmp    1030 <__kernel_sin@plt>
sub    $0x18,%rsp
cmp    $0x7ff00000,%eax
jb     1163 <sin+0x33>
subsd  %xmm0,%xmm0
add    $0x18,%rsp
ret
mov    %rsp,%rdi
call   1040 <__ieee754_rem_pio2@plt>
and    $0x3,%eax
cmp    $0x2,%eax
je     1196 <sin+0x66>
cmp    $0x1,%eax
je     11ad <sin+0x7d>
test   %eax,%eax
jne    11c2 <sin+0x92>
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    11d2 <sin+0xa2>
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  0xe27(%rip),%xmm0
add    $0x18,%rsp
ret

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

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