#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 */
float fabs(double);
double factorial(int);
double pow(float, int);
double seno(float x, float tol) {
  double term, result = 0;
  int i = 1;
  do {
    term = pow(-1, i - 1) * pow(x, 2 * i - 1) / factorial(2 * i - 1);
    result += term;
    i++;
  } while (fabs(term) >= tol);
  return result;
}


x86 assembly (clang, -O0):
<seno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
sub    $0x1,%edi
movss  0xea1(%rip),%xmm0
call   1050 <pow@plt>
movsd  %xmm0,-0x30(%rbp)
movss  -0x4(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
shl    $0x1,%edi
sub    $0x1,%edi
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
shl    $0x1,%edi
sub    $0x1,%edi
call   1030 <factorial@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <fabs@plt>
ucomiss -0x8(%rbp),%xmm0
jae    1151 <seno+0x21>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seno>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movss  %xmm1,0x14(%rsp)
movss  %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  0xe98(%rip),%xmm0
mov    %ebp,%edi
call   1050 <pow@plt>
movsd  %xmm0,(%rsp)
movss  0x10(%rsp),%xmm0
mov    %ebx,%edi
call   1050 <pow@plt>
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %ebx,%edi
call   1030 <factorial@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movapd %xmm1,%xmm0
call   1040 <fabs@plt>
add    $0x2,%ebx
add    $0x1,%ebp
ucomiss 0x14(%rsp),%xmm0
jae    1160 <seno+0x30>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @seno(float %0, float %1) {
%3 = alloca float
%4 = alloca float
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store float %0, float* %3
store float %1, float* %4
store double 0.000000e+00, double* %6
store i32 1, i32* %7
br label %8
8: ; preds = %28, %2
%9 = load i32, i32* %7
%10 = sub nsw i32 %9, 1
%11 = call double @pow(float -1.000000e+00, i32 %10)
%12 = load float, float* %3
%13 = load i32, i32* %7
%14 = mul nsw i32 2, %13
%15 = sub nsw i32 %14, 1
%16 = call double @pow(float %12, i32 %15)
%17 = fmul double %11, %16
%18 = load i32, i32* %7
%19 = mul nsw i32 2, %18
%20 = sub nsw i32 %19, 1
%21 = call double @factorial(i32 %20)
%22 = fdiv double %17, %21
store double %22, double* %5
%23 = load double, double* %5
%24 = load double, double* %6
%25 = fadd double %24, %23
store double %25, double* %6
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %28
28: ; preds = %8
%29 = load double, double* %5
%30 = call float @fabs(double %29)
%31 = load float, float* %4
%32 = fcmp oge float %30, %31
br i1 %32, label %8, label %33
33: ; preds = %28
%34 = load double, double* %6
ret double %34
}

LLVM IR (-O2):
define double @seno(float %0, float %1) {
br label %3
3: ; preds = %3, %2
%4 = phi double [ 0.000000e+00, %2 ], [ %14, %3 ]
%5 = phi i32 [ 1, %2 ], [ %15, %3 ]
%6 = add nsw i32 %5, -1
%7 = tail call double @pow(float -1.000000e+00, i32 %6)
%8 = shl nuw nsw i32 %5, 1
%9 = add nsw i32 %8, -1
%10 = tail call double @pow(float %0, i32 %9)
%11 = fmul double %7, %10
%12 = tail call double @factorial(i32 %9)
%13 = fdiv double %11, %12
%14 = fadd double %4, %13
%15 = add nuw nsw i32 %5, 1
%16 = tail call float @fabs(double %13)
%17 = fcmp ult float %16, %1
br i1 %17, label %18, label %3
18: ; preds = %3
ret double %14
}