#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 f(double);
double fp(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
int main() {
  double x[101];
  int i;
  x[0] = 3;
  double a = 2;
  double b = 3;
  double error;
  double s;
  double minFp;
  printf("****************************************************************\n");
  printf("*  Estimacion de una solucion por el metodo de Newton-Raphson  *\n");
  printf("****************************************************************\n");
  for (i = 1; i <= 100; i++) {
    x[i] = x[i - 1] - (f(x[i - 1]) / fp(x[i - 1]));
    printf("iteracion %d\n estimacion:%.15lf\n", i, x[i]);
    s = x[i];
  }
  minFp = fp(a);
  error = (f(s)) / minFp;
  printf("error= %.18lf\n", error);
  system("PAUSE");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x370,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xea6(%rip),%xmm0
movsd  %xmm0,-0x330(%rbp)
ff
movsd  0xe9e(%rip),%xmm0
movsd  %xmm0,-0x340(%rbp)
ff
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,-0x348(%rbp)
ff
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x334(%rbp)
cmpl   $0x64,-0x334(%rbp)
jg     1294 <main+0x154>
mov    -0x334(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x330(%rbp,%rax,8),%xmm0
ff ff
movsd  %xmm0,-0x368(%rbp)
ff
mov    -0x334(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x330(%rbp,%rax,8),%xmm0
ff ff
call   1040 <f@plt>
movsd  %xmm0,-0x370(%rbp)
ff
mov    -0x334(%rbp),%eax
sub    $0x1,%eax
cltq
movsd  -0x330(%rbp,%rax,8),%xmm0
ff ff
call   1030 <fp@plt>
movsd  -0x370(%rbp),%xmm1
ff
movaps %xmm0,%xmm2
movsd  -0x368(%rbp),%xmm0
ff
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movslq -0x334(%rbp),%rax
movsd  %xmm0,-0x330(%rbp,%rax,8)
ff ff
mov    -0x334(%rbp),%esi
movslq -0x334(%rbp),%rax
movsd  -0x330(%rbp,%rax,8),%xmm0
ff ff
lea    0xe33(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movslq -0x334(%rbp),%rax
movsd  -0x330(%rbp,%rax,8),%xmm0
ff ff
movsd  %xmm0,-0x358(%rbp)
ff
mov    -0x334(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x334(%rbp)
jmp    11b6 <main+0x76>
movsd  -0x340(%rbp),%xmm0
ff
call   1030 <fp@plt>
movsd  %xmm0,-0x360(%rbp)
ff
movsd  -0x358(%rbp),%xmm0
ff
call   1040 <f@plt>
divsd  -0x360(%rbp),%xmm0
ff
movsd  %xmm0,-0x350(%rbp)
ff
movsd  -0x350(%rbp),%xmm0
ff
lea    0xde0(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
lea    0xde1(%rip),%rdi
call   1050 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x370,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xf29(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
movsd  0xe7e(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0xffffffffffffff9c,%rbx
lea    0xe7a(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movsd  0x8(%rsp),%xmm0
call   1050 <f@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <fp@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
lea    0x65(%rbx),%esi
mov    %r14,%rdi
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1070 <printf@plt>
inc    %rbx
jne    11a0 <main+0x50>
movsd  0xe18(%rip),%xmm0
call   1030 <fp@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <f@plt>
divsd  0x10(%rsp),%xmm0
lea    0xe1e(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xe1f(%rip),%rdi
call   1060 <system@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [66 x i8] c"****************************************************************\0A\00"
@.str.1 = [66 x i8] c"* Estimacion de una solucion por el metodo de Newton-Raphson *\0A\00"
@.str.2 = [33 x i8] c"iteracion %d\0A estimacion:%.15lf\0A\00"
@.str.3 = [15 x i8] c"error= %.18lf\0A\00"
@.str.4 = [6 x i8] c"PAUSE\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [101 x double]
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i32 0, i32* %1
%9 = getelementptr inbounds [101 x double], [101 x double]* %2, i64 0, i64 0
store double 3.000000e+00, double* %9
store double 2.000000e+00, double* %4
store double 3.000000e+00, double* %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %13
13: ; preds = %49, %0
%14 = load i32, i32* %3
%15 = icmp sle i32 %14, 100
br i1 %15, label %16, label %52
16: ; preds = %13
%17 = load i32, i32* %3
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [101 x double], [101 x double]* %2, i64 0, i64 %19
%21 = load double, double* %20
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [101 x double], [101 x double]* %2, i64 0, i64 %24
%26 = load double, double* %25
%27 = call double @f(double %26)
%28 = load i32, i32* %3
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [101 x double], [101 x double]* %2, i64 0, i64 %30
%32 = load double, double* %31
%33 = call double @fp(double %32)
%34 = fdiv double %27, %33
%35 = fsub double %21, %34
%36 = load i32, i32* %3
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [101 x double], [101 x double]* %2, i64 0, i64 %37
store double %35, double* %38
%39 = load i32, i32* %3
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [101 x double], [101 x double]* %2, i64 0, i64 %41
%43 = load double, double* %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %39, double %43)
%45 = load i32, i32* %3
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [101 x double], [101 x double]* %2, i64 0, i64 %46
%48 = load double, double* %47
store double %48, double* %7
br label %49
49: ; preds = %16
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %13
52: ; preds = %13
%53 = load double, double* %4
%54 = call double @fp(double %53)
store double %54, double* %8
%55 = load double, double* %7
%56 = call double @f(double %55)
%57 = load double, double* %8
%58 = fdiv double %56, %57
store double %58, double* %6
%59 = load double, double* %6
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), double %59)
%61 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@.str.2 = [33 x i8] c"iteracion %d\0A estimacion:%.15lf\0A\00"
@.str.3 = [15 x i8] c"error= %.18lf\0A\00"
@.str.4 = [6 x i8] c"PAUSE\00"
@str.5 = [65 x i8] c"* Estimacion de una solucion por el metodo de Newton-Raphson *\00"
@str.6 = [65 x i8] c"****************************************************************\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.6, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.5, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str.6, i64 0, i64 0))
br label %4
4: ; preds = %0, %4
%5 = phi double [ 3.000000e+00, %0 ], [ %10, %4 ]
%6 = phi i64 [ 1, %0 ], [ %13, %4 ]
%7 = tail call double @f(double %5)
%8 = tail call double @fp(double %5)
%9 = fdiv double %7, %8
%10 = fsub double %5, %9
%11 = trunc i64 %6 to i32
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %11, double %10)
%13 = add nuw nsw i64 %6, 1
%14 = icmp eq i64 %13, 101
br i1 %14, label %15, label %4
15: ; preds = %4
%16 = tail call double @fp(double 2.000000e+00)
%17 = tail call double @f(double %10)
%18 = fdiv double %17, %16
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), double %18)
%20 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}