#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 */
int fabs(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
double sqrt(double);
int main() {
  double a, x, y;
  int n;
  printf("Entrez a : ");
  scanf("%lf", &a);
  printf("Precision : ");
  scanf("%d", &n);
  x = a;
  y = 0;
  while (fabs(x - y) >= 1. / n) {
    y = x;
    x = 0.5 * (x + a / x);
  }
  printf("La racine de %f est %f (au lieu de %f) \n", a, x, sqrt(a));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea9(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x24(%rbp),%xmm2
movsd  0xe3f(%rip),%xmm1
divsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jb     1202 <main+0xc2>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe14(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11a1 <main+0x61>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <sqrt@plt>
movsd  -0x38(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
lea    0xdfc(%rip),%rdi
mov    $0x3,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
lea    0x18(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xeb4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xeb3(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
call   1040 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
cvtsi2sdl 0x14(%rsp),%xmm1
movsd  0xe54(%rip),%xmm2
divsd  %xmm1,%xmm2
ucomisd %xmm2,%xmm0
jae    11be <main+0x7e>
movsd  0x8(%rsp),%xmm1
jmp    1221 <main+0xe1>
movsd  0x8(%rsp),%xmm2
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  0x18(%rsp),%xmm0
divsd  %xmm2,%xmm0
addsd  %xmm2,%xmm0
mulsd  0xe22(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
subsd  %xmm2,%xmm0
call   1040 <fabs@plt>
movsd  0xe03(%rip),%xmm2
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl 0x14(%rsp),%xmm1
divsd  %xmm1,%xmm2
movsd  0x8(%rsp),%xmm1
ucomisd %xmm2,%xmm0
movapd %xmm1,%xmm2
jae    11d0 <main+0x90>
movsd  0x18(%rsp),%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jb     123a <main+0xfa>
xorps  %xmm2,%xmm2
sqrtsd %xmm3,%xmm2
jmp    125f <main+0x11f>
movapd %xmm3,%xmm0
movsd  %xmm1,0x8(%rsp)
movsd  %xmm3,0x20(%rsp)
call   1060 <sqrt@plt>
movsd  0x20(%rsp),%xmm3
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
lea    0xdca(%rip),%rdi
movapd %xmm3,%xmm0
mov    $0x3,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Entrez a : \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [13 x i8] c"Precision : \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [41 x i8] c"La racine de %f est %f (au lieu de %f) \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%10 = load double, double* %2
store double %10, double* %3
store double 0.000000e+00, double* %4
br label %11
11: ; preds = %21, %0
%12 = load double, double* %3
%13 = load double, double* %4
%14 = fsub double %12, %13
%15 = call i32 @fabs(double %14)
%16 = sitofp i32 %15 to double
%17 = load i32, i32* %5
%18 = sitofp i32 %17 to double
%19 = fdiv double 1.000000e+00, %18
%20 = fcmp oge double %16, %19
br i1 %20, label %21, label %29
21: ; preds = %11
%22 = load double, double* %3
store double %22, double* %4
%23 = load double, double* %3
%24 = load double, double* %2
%25 = load double, double* %3
%26 = fdiv double %24, %25
%27 = fadd double %23, %26
%28 = fmul double 5.000000e-01, %27
store double %28, double* %3
br label %11
29: ; preds = %11
%30 = load double, double* %2
%31 = load double, double* %3
%32 = load double, double* %2
%33 = call double @sqrt(double %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), double %30, double %31, double %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Entrez a : \00"
@.str.1 = [4 x i8] c"%lf\00"
@.str.2 = [13 x i8] c"Precision : \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [41 x i8] c"La racine de %f est %f (au lieu de %f) \0A\00"
define i32 @main() {
%1 = alloca double
%2 = alloca i32
%3 = bitcast double* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%9 = load double, double* %1
%10 = call i32 @fabs(double %9)
%11 = sitofp i32 %10 to double
%12 = load i32, i32* %2
%13 = sitofp i32 %12 to double
%14 = fdiv double 1.000000e+00, %13
%15 = fcmp ugt double %14, %11
br i1 %15, label %29, label %16
16: ; preds = %0, %16
%17 = phi double [ %21, %16 ], [ %9, %0 ]
%18 = load double, double* %1
%19 = fdiv double %18, %17
%20 = fadd double %17, %19
%21 = fmul double %20, 5.000000e-01
%22 = fsub double %21, %17
%23 = call i32 @fabs(double %22)
%24 = sitofp i32 %23 to double
%25 = load i32, i32* %2
%26 = sitofp i32 %25 to double
%27 = fdiv double 1.000000e+00, %26
%28 = fcmp ugt double %27, %24
br i1 %28, label %29, label %16
29: ; preds = %16, %0
%30 = phi double [ %9, %0 ], [ %21, %16 ]
%31 = load double, double* %1
%32 = call double @sqrt(double %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), double %31, double %30, double %32)
ret i32 0
}