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


x86 assembly (clang, -O0):
<sin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
and    $0x7fffffff,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x3fe921fb,-0x30(%rbp)
jg     1181 <sin+0x51>
movsd  -0x8(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rsi
xor    %edi,%edi
call   1030 <__kernel_sin@plt>
jmp    129f <sin+0x16f>
cmpl   $0x7ff00000,-0x30(%rbp)
jl     11a5 <sin+0x75>
movsd  -0x8(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    129f <sin+0x16f>
movsd  -0x8(%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     11ec <sin+0xbc>
jmp    11ca <sin+0x9a>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
je     1209 <sin+0xd9>
jmp    11db <sin+0xab>
mov    -0x34(%rbp),%eax
sub    $0x2,%eax
je     1221 <sin+0xf1>
jmp    1265 <sin+0x135>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
jmp    129f <sin+0x16f>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x10(%rbp),%rdi
call   1050 <__kernel_cos@plt>
jmp    129f <sin+0x16f>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
call   1030 <__kernel_sin@plt>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    129f <sin+0x16f>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
mov    -0x10(%rbp),%rdi
call   1050 <__kernel_cos@plt>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sin>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movq   %xmm0,%rax
shr    $0x20,%rax
and    $0x7fffffff,%eax
cmp    $0x3fe921fb,%eax
ja     115f <sin+0x2f>
xorps  %xmm1,%xmm1
xor    %edi,%edi
mov    %rbx,%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <__kernel_sin@plt>
cmp    $0x7ff00000,%eax
jb     1173 <sin+0x43>
subsd  %xmm0,%xmm0
movsd  %xmm0,(%rbx)
jmp    11f8 <sin+0xc8>
mov    %rsp,%rdi
call   1040 <__ieee754_rem_pio2@plt>
and    $0x3,%eax
cmp    $0x2,%eax
je     11a6 <sin+0x76>
cmp    $0x1,%eax
je     11c0 <sin+0x90>
test   %eax,%eax
jne    11d5 <sin+0xa5>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x1,%edi
mov    %rbx,%rsi
call   1030 <__kernel_sin@plt>
jmp    11f8 <sin+0xc8>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    $0x1,%edi
mov    %rbx,%rsi
call   1030 <__kernel_sin@plt>
jmp    11e8 <sin+0xb8>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %rbx,%rdi
call   1050 <__kernel_cos@plt>
jmp    11f8 <sin+0xc8>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mov    %rbx,%rdi
call   1050 <__kernel_cos@plt>
movsd  (%rbx),%xmm0
xorpd  0xe0c(%rip),%xmm0
movlpd %xmm0,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

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