#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 NAN;
double fabs(double);
scalar_t__ isinf(double);
scalar_t__ isnan(double);
double sd2eps(unsigned int);
double sinush(double num, unsigned int sigdig) {
  if (sigdig < 1) {
    return NAN;
  }
  if (isnan(num) || isinf(num)) {
    return num;
  }
  double x = num;
  double x2 = num * num;
  double result = x;
  double presult = 0;
  double k = 0;
  double fakt = 1;
  double eps = sd2eps(sigdig);
  while (fabs(result - presult) > eps) {
    x *= x2;
    k += 2;
    fakt *= k * (k + 1);
    presult = result;
    result = presult + x / fakt;
  }
  return result;
}


x86 assembly (clang, -O0):
<sinush>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jae    115f <sinush+0x2f>
mov    0x2ea7(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1275 <sinush+0x145>
movsd  -0x10(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
jne    1187 <sinush+0x57>
movsd  -0x10(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1196 <sinush+0x66>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1275 <sinush+0x145>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe2f(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <sd2eps@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movaps 0xe1c(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x50(%rbp),%xmm0
jbe    126b <sinush+0x13b>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdee(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  0xdcf(%rip),%xmm1
addsd  -0x40(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
divsd  -0x48(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11e3 <sinush+0xb3>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sinush>:
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     1160 <sinush+0x30>
mov    %edi,%ebx
movapd %xmm0,(%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
jne    1159 <sinush+0x29>
movapd (%rsp),%xmm0
call   1050 <isinf@plt>
test   %rax,%rax
je     1175 <sinush+0x45>
movapd (%rsp),%xmm5
jmp    116b <sinush+0x3b>
mov    0x2e91(%rip),%rax
movsd  (%rax),%xmm5
movapd %xmm5,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
mov    %ebx,%edi
call   1030 <sd2eps@plt>
movapd 0xe7c(%rip),%xmm1
movapd (%rsp),%xmm2
andpd  %xmm2,%xmm1
ucomisd %xmm0,%xmm1
jbe    1212 <sinush+0xe2>
movapd %xmm2,%xmm4
mulsd  %xmm2,%xmm4
xorpd  %xmm3,%xmm3
movsd  0xe68(%rip),%xmm10
movsd  0xe67(%rip),%xmm8
movapd 0xe46(%rip),%xmm9
movapd %xmm10,%xmm7
movapd %xmm2,%xmm6
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mulsd  %xmm4,%xmm6
addsd  %xmm8,%xmm3
movapd %xmm3,%xmm1
addsd  %xmm10,%xmm1
mulsd  %xmm3,%xmm1
mulsd  %xmm1,%xmm7
movapd %xmm6,%xmm5
divsd  %xmm7,%xmm5
addsd  %xmm2,%xmm5
movapd %xmm5,%xmm1
subsd  %xmm2,%xmm1
andpd  %xmm9,%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm5,%xmm2
ja     11d0 <sinush+0xa0>
jmp    116b <sinush+0x3b>
movapd %xmm2,%xmm5
jmp    116b <sinush+0x3b>

LLVM IR (-O0):
@NAN = global double 0.000000e+00
define double @sinush(double %0, i32 %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store double %0, double* %4
store i32 %1, i32* %5
%13 = load i32, i32* %5
%14 = icmp ult i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = load double, double* @NAN
store double %16, double* %3
br label %62
17: ; preds = %2
%18 = load double, double* %4
%19 = call i64 @isnan(double %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load double, double* %4
%23 = call i64 @isinf(double %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21, %17
%26 = load double, double* %4
store double %26, double* %3
br label %62
27: ; preds = %21
%28 = load double, double* %4
store double %28, double* %6
%29 = load double, double* %4
%30 = load double, double* %4
%31 = fmul double %29, %30
store double %31, double* %7
%32 = load double, double* %6
store double %32, double* %8
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store double 1.000000e+00, double* %11
%33 = load i32, i32* %5
%34 = call double @sd2eps(i32 %33)
store double %34, double* %12
br label %35
35: ; preds = %42, %27
%36 = load double, double* %8
%37 = load double, double* %9
%38 = fsub double %36, %37
%39 = call double @llvm.fabs.f64(double %38)
%40 = load double, double* %12
%41 = fcmp ogt double %39, %40
br i1 %41, label %42, label %60
42: ; preds = %35
%43 = load double, double* %7
%44 = load double, double* %6
%45 = fmul double %44, %43
store double %45, double* %6
%46 = load double, double* %10
%47 = fadd double %46, 2.000000e+00
store double %47, double* %10
%48 = load double, double* %10
%49 = load double, double* %10
%50 = fadd double %49, 1.000000e+00
%51 = fmul double %48, %50
%52 = load double, double* %11
%53 = fmul double %52, %51
store double %53, double* %11
%54 = load double, double* %8
store double %54, double* %9
%55 = load double, double* %9
%56 = load double, double* %6
%57 = load double, double* %11
%58 = fdiv double %56, %57
%59 = fadd double %55, %58
store double %59, double* %8
br label %35
60: ; preds = %35
%61 = load double, double* %8
store double %61, double* %3
br label %62
62: ; preds = %60, %25, %15
%63 = load double, double* %3
ret double %63
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
define double @sinush(double %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load double, double* @NAN
br label %32
6: ; preds = %2
%7 = tail call i64 @isnan(double %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %32
9: ; preds = %6
%10 = tail call i64 @isinf(double %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = fmul double %0, %0
%14 = tail call double @sd2eps(i32 %1)
%15 = tail call double @llvm.fabs.f64(double %0)
%16 = fcmp ogt double %15, %14
br i1 %16, label %17, label %32
17: ; preds = %12, %17
%18 = phi double [ %26, %17 ], [ 1.000000e+00, %12 ]
%19 = phi double [ %23, %17 ], [ 0.000000e+00, %12 ]
%20 = phi double [ %28, %17 ], [ %0, %12 ]
%21 = phi double [ %22, %17 ], [ %0, %12 ]
%22 = fmul double %13, %21
%23 = fadd double %19, 2.000000e+00
%24 = fadd double %23, 1.000000e+00
%25 = fmul double %23, %24
%26 = fmul double %18, %25
%27 = fdiv double %22, %26
%28 = fadd double %20, %27
%29 = fsub double %28, %20
%30 = tail call double @llvm.fabs.f64(double %29)
%31 = fcmp ogt double %30, %14
br i1 %31, label %17, label %32
32: ; preds = %17, %12, %6, %9, %4
%33 = phi double [ %5, %4 ], [ %0, %9 ], [ %0, %6 ], [ %0, %12 ], [ %28, %17 ]
ret double %33
}