#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 absolute(double);
scalar_t__ isnan(double);
int /*<<< orphan*/ printf(char *, int, double);
double stub1(double, int);
double sum_iter_fn_while(double (*f)(double, int), double x) {
  double res = 0.0;
  double previous = 0.0;
  int i = 0;
  do {
    previous = absolute(res);
    res += (*f)(x, i);
    i++;
  } while (absolute(res - previous) > 0.00005);
  printf("Iteraciones hechas: %d\nDelta X = %lf\n", i,
         absolute(res - previous));
  if (isnan(res)) {
    (res > 0) ? (res = 1) : (res = -1);
  }
  return res;
}


x86 assembly (clang, -O0):
<sum_iter_fn_while>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <absolute@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  -0x10(%rbp),%xmm0
mov    -0x24(%rbp),%edi
call   *%rax
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1040 <absolute@plt>
movsd  0xe61(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1158 <sum_iter_fn_while+0x28>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1040 <absolute@plt>
mov    -0x28(%rbp),%esi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
call   1050 <isnan@plt>
cmp    $0x0,%rax
je     1212 <sum_iter_fn_while+0xe2>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1205 <sum_iter_fn_while+0xd5>
movsd  0xe15(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1212 <sum_iter_fn_while+0xe2>
movsd  0xdfb(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sum_iter_fn_while>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x18(%rsp)
mov    %rdi,%r14
xor    %ebx,%ebx
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
nopl   (%rax)
movsd  0x8(%rsp),%xmm0
call   1040 <absolute@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x18(%rsp),%xmm0
mov    %ebx,%edi
call   *%r14
addsd  0x8(%rsp),%xmm0
add    $0x1,%ebx
movsd  %xmm0,0x8(%rsp)
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
call   1040 <absolute@plt>
ucomisd 0xe6c(%rip),%xmm0
ja     1150 <sum_iter_fn_while+0x20>
movsd  0x10(%rsp),%xmm0
call   1040 <absolute@plt>
lea    0xe70(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xorpd  %xmm1,%xmm1
xor    %ebx,%ebx
movsd  0x8(%rsp),%xmm0
ucomisd %xmm1,%xmm0
seta   %bpl
call   1050 <isnan@plt>
test   %rax,%rax
je     11e2 <sum_iter_fn_while+0xb2>
mov    %bpl,%bl
lea    0xe31(%rip),%rax
movsd  (%rax,%rbx,8),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Iteraciones hechas: %d\0ADelta X = %lf\0A\00"
define double @sum_iter_fn_while(double (double, i32)* %0, double %1) {
%3 = alloca double (double, i32)*
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double (double, i32)* %0, double (double, i32)** %3
store double %1, double* %4
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %6
store i32 0, i32* %7
br label %8
8: ; preds = %19, %2
%9 = load double, double* %5
%10 = call double @absolute(double %9)
store double %10, double* %6
%11 = load double (double, i32)*, double (double, i32)** %3
%12 = load double, double* %4
%13 = load i32, i32* %7
%14 = call double %11(double %12, i32 %13)
%15 = load double, double* %5
%16 = fadd double %15, %14
store double %16, double* %5
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
store i32 %18, i32* %7
br label %19
19: ; preds = %8
%20 = load double, double* %5
%21 = load double, double* %6
%22 = fsub double %20, %21
%23 = call double @absolute(double %22)
%24 = fcmp ogt double %23, 5.000000e-05
br i1 %24, label %8, label %25
25: ; preds = %19
%26 = load i32, i32* %7
%27 = load double, double* %5
%28 = load double, double* %6
%29 = fsub double %27, %28
%30 = call double @absolute(double %29)
%31 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %26, double %30)
%32 = load double, double* %5
%33 = call i64 @isnan(double %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %25
%36 = load double, double* %5
%37 = fcmp ogt double %36, 0.000000e+00
br i1 %37, label %38, label %39
38: ; preds = %35
store double 1.000000e+00, double* %5
br label %40
39: ; preds = %35
store double -1.000000e+00, double* %5
br label %40
40: ; preds = %39, %38
%41 = phi double [ 1.000000e+00, %38 ], [ -1.000000e+00, %39 ]
br label %42
42: ; preds = %40, %25
%43 = load double, double* %5
ret double %43
}

LLVM IR (-O2):
@.str = [38 x i8] c"Iteraciones hechas: %d\0ADelta X = %lf\0A\00"
define double @sum_iter_fn_while(double (double, i32)* nocapture %0, double %1) {
br label %3
3: ; preds = %3, %2
%4 = phi double [ 0.000000e+00, %2 ], [ %8, %3 ]
%5 = phi i32 [ 0, %2 ], [ %9, %3 ]
%6 = tail call double @absolute(double %4)
%7 = tail call double %0(double %1, i32 %5)
%8 = fadd double %4, %7
%9 = add nuw nsw i32 %5, 1
%10 = fsub double %8, %6
%11 = tail call double @absolute(double %10)
%12 = fcmp ogt double %11, 5.000000e-05
br i1 %12, label %3, label %13
13: ; preds = %3
%14 = tail call double @absolute(double %10)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %9, double %14)
%16 = tail call i64 @isnan(double %8)
%17 = icmp eq i64 %16, 0
%18 = fcmp ogt double %8, 0.000000e+00
%19 = select i1 %18, double 1.000000e+00, double -1.000000e+00
%20 = select i1 %17, double %8, double %19
ret double %20
}