#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 modf(double, double *);
double sinus(double arg, int quad) {
  double e, f;
  int k;
  double ysq;
  double x, y;
  double temp1, temp2;
  x = arg;
  if (x < 0) {
    x = -x;
    quad = quad + 2;
  }
  x = x * 0.636619772367581;
  if (x > 32764) {
    y = modf(x, &e);
    e = e + quad;
    modf(0.25 * e, &f);
    quad = e - 4 * f;
  } else {
    k = x;
    y = x - k;
    quad = (quad + k) & 03;
  }
  if (quad & 01)
    y = 1 - y;
  if (quad > 1)
    y = -y;
  ysq = y * y;
  temp1 = ((((0.145968840666577e3 * ysq + -0.138472724998245e5) * ysq +
             0.440103053537527e6) *
                ysq +
            -0.494290810090284e7) *
               ysq +
           0.135788409787738e8) *
          y;
  temp2 = ((((ysq + 0.132653490878614e3) * ysq + 0.946309610153821e4) * ysq +
            0.408179225234330e6) *
               ysq +
           0.864455865292253e7);
  return (temp1 / temp2);
}


x86 assembly (clang, -O0):
<sinus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jbe    1162 <sinus+0x52>
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
movsd  0xe9e(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe7f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ed <sinus+0xdd>
movsd  -0x38(%rbp),%xmm0
lea    -0x18(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe5f(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
lea    -0x20(%rbp),%rdi
call   1030 <modf@plt>
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  0xe37(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
jmp    1214 <sinus+0x104>
cvttsd2si -0x38(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0xc(%rbp),%eax
add    -0x24(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1235 <sinus+0x125>
movsd  0xdf5(%rip),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
cmpl   $0x1,-0xc(%rbp)
jle    1260 <sinus+0x150>
movsd  -0x40(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xde4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xde0(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdbb(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd9e(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd81(%rip),%xmm1
addsd  %xmm1,%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xd63(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd45(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd28(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xd0b(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
divsd  -0x50(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sinus>:
push   %rbx
sub    $0x30,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
lea    0x2(%rdi),%ebx
movapd 0xed8(%rip),%xmm2
xorpd  %xmm0,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm1,%xmm3
andpd  %xmm3,%xmm2
cmovbe %edi,%ebx
andnpd %xmm0,%xmm3
orpd   %xmm2,%xmm3
mulsd  0xec4(%rip),%xmm3
ucomisd 0xec4(%rip),%xmm3
jbe    11b8 <sinus+0xa8>
lea    0x18(%rsp),%rdi
movapd %xmm3,%xmm0
call   1030 <modf@plt>
movapd %xmm0,0x20(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
addsd  0x18(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xe9b(%rip),%xmm0
mulsd  %xmm1,%xmm0
lea    0x10(%rsp),%rdi
call   1030 <modf@plt>
movapd 0x20(%rsp),%xmm3
movsd  0x10(%rsp),%xmm0
mulsd  0xe81(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%ebx
test   $0x1,%bl
jne    11d2 <sinus+0xc2>
jmp    11e2 <sinus+0xd2>
cvttsd2si %xmm3,%eax
cvttpd2dq %xmm3,%xmm0
cvtdq2pd %xmm0,%xmm0
subsd  %xmm0,%xmm3
add    %eax,%ebx
and    $0x3,%ebx
test   $0x1,%bl
je     11e2 <sinus+0xd2>
movsd  0xe56(%rip),%xmm0
subsd  %xmm3,%xmm0
movapd %xmm0,%xmm3
cmp    $0x2,%ebx
jl     11ef <sinus+0xdf>
xorpd  0xe11(%rip),%xmm3
movapd %xmm3,%xmm1
mulsd  %xmm3,%xmm1
movsd  0xe39(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe35(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe31(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe2d(%rip),%xmm0
mulsd  %xmm1,%xmm0
addsd  0xe29(%rip),%xmm0
movsd  0xe29(%rip),%xmm2
addsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe21(%rip),%xmm2
mulsd  %xmm3,%xmm0
mulsd  %xmm1,%xmm2
addsd  0xe19(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xe15(%rip),%xmm2
divsd  %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @sinus(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
%13 = load double, double* %3
store double %13, double* %9
%14 = load double, double* %9
%15 = fcmp olt double %14, 0.000000e+00
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load double, double* %9
%18 = fneg double %17
store double %18, double* %9
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 2
store i32 %20, i32* %4
br label %21
21: ; preds = %16, %2
%22 = load double, double* %9
%23 = fmul double %22, 0x3FE45F306DC9C880
store double %23, double* %9
%24 = load double, double* %9
%25 = fcmp ogt double %24, 3.276400e+04
br i1 %25, label %26, label %40
26: ; preds = %21
%27 = load double, double* %9
%28 = call double @modf(double %27, double* %5)
store double %28, double* %10
%29 = load double, double* %5
%30 = load i32, i32* %4
%31 = sitofp i32 %30 to double
%32 = fadd double %29, %31
store double %32, double* %5
%33 = load double, double* %5
%34 = fmul double 2.500000e-01, %33
%35 = call double @modf(double %34, double* %6)
%36 = load double, double* %5
%37 = load double, double* %6
%38 = call double @llvm.fmuladd.f64(double -4.000000e+00, double %37, double %36)
%39 = fptosi double %38 to i32
store i32 %39, i32* %4
br label %51
40: ; preds = %21
%41 = load double, double* %9
%42 = fptosi double %41 to i32
store i32 %42, i32* %7
%43 = load double, double* %9
%44 = load i32, i32* %7
%45 = sitofp i32 %44 to double
%46 = fsub double %43, %45
store double %46, double* %10
%47 = load i32, i32* %4
%48 = load i32, i32* %7
%49 = add nsw i32 %47, %48
%50 = and i32 %49, 3
store i32 %50, i32* %4
br label %51
51: ; preds = %40, %26
%52 = load i32, i32* %4
%53 = and i32 %52, 1
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load double, double* %10
%57 = fsub double 1.000000e+00, %56
store double %57, double* %10
br label %58
58: ; preds = %55, %51
%59 = load i32, i32* %4
%60 = icmp sgt i32 %59, 1
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load double, double* %10
%63 = fneg double %62
store double %63, double* %10
br label %64
64: ; preds = %61, %58
%65 = load double, double* %10
%66 = load double, double* %10
%67 = fmul double %65, %66
store double %67, double* %8
%68 = load double, double* %8
%69 = call double @llvm.fmuladd.f64(double 0x40623F00BE243F75, double %68, double 0xC0CB0BA2E1463532)
%70 = load double, double* %8
%71 = call double @llvm.fmuladd.f64(double %69, double %70, double 0x411ADC9C36D28A9E)
%72 = load double, double* %8
%73 = call double @llvm.fmuladd.f64(double %71, double %72, double 0xC152DB0F0675312F)
%74 = load double, double* %8
%75 = call double @llvm.fmuladd.f64(double %73, double %74, double 0x4169E64B1F521D6F)
%76 = load double, double* %10
%77 = fmul double %75, %76
store double %77, double* %11
%78 = load double, double* %8
%79 = fadd double %78, 0x406094E965B3FC35
%80 = load double, double* %8
%81 = call double @llvm.fmuladd.f64(double %79, double %80, double 0x40C27B8C4D0E21DB)
%82 = load double, double* %8
%83 = call double @llvm.fmuladd.f64(double %81, double %82, double 0x4118E9CCE6A3D405)
%84 = load double, double* %8
%85 = call double @llvm.fmuladd.f64(double %83, double %84, double 0x41607CF9D4E4BDCA)
store double %85, double* %12
%86 = load double, double* %11
%87 = load double, double* %12
%88 = fdiv double %86, %87
ret double %88
}

LLVM IR (-O2):
define double @sinus(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = bitcast double* %3 to i8*
%6 = bitcast double* %4 to i8*
%7 = fcmp olt double %0, 0.000000e+00
%8 = fneg double %0
%9 = add nsw i32 %1, 2
%10 = select i1 %7, double %8, double %0
%11 = select i1 %7, i32 %9, i32 %1
%12 = fmul double %10, 0x3FE45F306DC9C880
%13 = fcmp ogt double %12, 3.276400e+04
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = call double @modf(double %12, double* %3)
%16 = load double, double* %3
%17 = sitofp i32 %11 to double
%18 = fadd double %16, %17
%19 = fmul double %18, 2.500000e-01
%20 = call double @modf(double %19, double* %4)
%21 = load double, double* %4
%22 = tail call double @llvm.fmuladd.f64(double %21, double -4.000000e+00, double %18)
%23 = fptosi double %22 to i32
br label %30
24: ; preds = %2
%25 = fptosi double %12 to i32
%26 = sitofp i32 %25 to double
%27 = fsub double %12, %26
%28 = add nsw i32 %11, %25
%29 = and i32 %28, 3
br label %30
30: ; preds = %24, %14
%31 = phi double [ %15, %14 ], [ %27, %24 ]
%32 = phi i32 [ %23, %14 ], [ %29, %24 ]
%33 = and i32 %32, 1
%34 = icmp eq i32 %33, 0
%35 = fsub double 1.000000e+00, %31
%36 = select i1 %34, double %31, double %35
%37 = icmp sgt i32 %32, 1
%38 = fneg double %36
%39 = select i1 %37, double %38, double %36
%40 = fmul double %39, %39
%41 = tail call double @llvm.fmuladd.f64(double %40, double 0x40623F00BE243F75, double 0xC0CB0BA2E1463532)
%42 = tail call double @llvm.fmuladd.f64(double %41, double %40, double 0x411ADC9C36D28A9E)
%43 = tail call double @llvm.fmuladd.f64(double %42, double %40, double 0xC152DB0F0675312F)
%44 = tail call double @llvm.fmuladd.f64(double %43, double %40, double 0x4169E64B1F521D6F)
%45 = fmul double %39, %44
%46 = fadd double %40, 0x406094E965B3FC35
%47 = tail call double @llvm.fmuladd.f64(double %46, double %40, double 0x40C27B8C4D0E21DB)
%48 = tail call double @llvm.fmuladd.f64(double %47, double %40, double 0x4118E9CCE6A3D405)
%49 = tail call double @llvm.fmuladd.f64(double %48, double %40, double 0x41607CF9D4E4BDCA)
%50 = fdiv double %45, %49
ret double %50
}