#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 /*<<< orphan*/ dd_abs(double *, double *);
int /*<<< orphan*/ dd_copy(double *, double *);
int /*<<< orphan*/ dd_div(double *, double *, double *);
int /*<<< orphan*/ dd_inc(double *, double *);
int /*<<< orphan*/ dd_mlt_d(double *, double);
int /*<<< orphan*/ dd_mul(double *, double *, double *);
int /*<<< orphan*/ dd_read(char *, double *);
int /*<<< orphan*/ dd_sub(double *, double *, double *);
int /*<<< orphan*/ dd_write(double *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int my_sqrt(void) {
  double n[2], x[2], y[2], z[2], e[2], a[2];
  const int max_steps = 9;
  char sqrt2[34] = "1.4142135623730950488016887242097\0";
  int i;
  n[0] = 2.0;
  n[1] = 0.0;
  dd_copy(n, x);
  puts("\nrunning Newton's method for sqrt(2) ...");
  dd_read(sqrt2, y);
  printf("y hi = %22.14e  y lo = %22.14e\n", y[0], y[1]);
  printf("step 0: ");
  dd_write(x, 32);
  printf("\n");
  for (i = 1; i <= max_steps; i++) {
    dd_mul(x, x, z);
    dd_inc(z, n);
    dd_div(z, x, z);
    dd_mlt_d(z, 0.5);
    printf("step %d: ", i);
    dd_write(z, 32);
    dd_copy(z, x);
    dd_sub(x, y, e);
    dd_abs(e, a);
    printf("  error : ");
    dd_write(a, 3);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<my_sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x9,-0x64(%rbp)
lea    -0x90(%rbp),%rdi
lea    0xe30(%rip),%rsi
mov    $0x22,%edx
call   1090 <memcpy@plt>
movsd  0xe0e(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10d0 <dd_copy@plt>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
lea    -0x90(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10e0 <dd_read@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xe22(%rip),%rdi
mov    $0x2,%al
call   1070 <printf@plt>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    $0x20,%esi
call   10c0 <dd_write@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x94(%rbp)
cmpl   $0x9,-0x94(%rbp)
jg     134c <my_sqrt+0x18c>
lea    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   10b0 <dd_mul@plt>
lea    -0x40(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <dd_inc@plt>
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1050 <dd_div@plt>
lea    -0x40(%rbp),%rdi
movsd  0xd4c(%rip),%xmm0
call   1080 <dd_mlt_d@plt>
mov    -0x94(%rbp),%esi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x20,%esi
call   10c0 <dd_write@plt>
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10d0 <dd_copy@plt>
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1040 <dd_sub@plt>
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   10a0 <dd_abs@plt>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x3,%esi
call   10c0 <dd_write@plt>
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1274 <my_sqrt+0xb4>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_sqrt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
movaps 0xe48(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe2c(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movw   $0x37,0x40(%rsp)
movsd  0xe08(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
lea    0x80(%rsp),%r12
mov    %r12,%rsi
call   10d0 <dd_copy@plt>
lea    0xe19(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
call   10e0 <dd_read@plt>
movsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
lea    0xe1e(%rip),%rdi
mov    $0x2,%al
call   1080 <printf@plt>
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rdi
mov    $0x20,%esi
call   10c0 <dd_write@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%ebp
lea    0x70(%rsp),%rbx
lea    0x60(%rsp),%r14
lea    0x50(%rsp),%r15
lea    0xe0a(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10b0 <dd_mul@plt>
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
call   1070 <dd_inc@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <dd_div@plt>
mov    %rbx,%rdi
movsd  0xd44(%rip),%xmm0
call   1090 <dd_mlt_d@plt>
lea    0xdb4(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
call   10c0 <dd_write@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10d0 <dd_copy@plt>
mov    %r12,%rdi
mov    %rsp,%rsi
mov    %r14,%rdx
call   1050 <dd_sub@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <dd_abs@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
mov    $0x3,%esi
call   10c0 <dd_write@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    $0xa,%ebp
jne    1290 <my_sqrt+0xd0>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.my_sqrt.sqrt2 = [34 x i8] c"1.4142135623730950488016887242097\00"
@.str = [41 x i8] c"\0Arunning Newton's method for sqrt(2) ...\00"
@.str.1 = [32 x i8] c"y hi = %22.14e y lo = %22.14e\0A\00"
@.str.2 = [9 x i8] c"step 0: \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [10 x i8] c"step %d: \00"
@.str.5 = [11 x i8] c" error : \00"
define i32 @my_sqrt() {
%1 = alloca [2 x double]
%2 = alloca [2 x double]
%3 = alloca [2 x double]
%4 = alloca [2 x double]
%5 = alloca [2 x double]
%6 = alloca [2 x double]
%7 = alloca i32
%8 = alloca [34 x i8]
%9 = alloca i32
store i32 9, i32* %7
%10 = bitcast [34 x i8]* %8 to i8*
%11 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 0, i64 0
store double 2.000000e+00, double* %11
%12 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 0, i64 1
store double 0.000000e+00, double* %12
%13 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 0, i64 0
%14 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%15 = call i32 @dd_copy(double* %13, double* %14)
%16 = call i32 @puts(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [34 x i8], [34 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds [2 x double], [2 x double]* %3, i64 0, i64 0
%19 = call i32 @dd_read(i8* %17, double* %18)
%20 = getelementptr inbounds [2 x double], [2 x double]* %3, i64 0, i64 0
%21 = load double, double* %20
%22 = getelementptr inbounds [2 x double], [2 x double]* %3, i64 0, i64 1
%23 = load double, double* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double %21, double %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%27 = call i32 @dd_write(double* %26, i32 32)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %9
br label %29
29: ; preds = %64, %0
%30 = load i32, i32* %9
%31 = icmp sle i32 %30, 9
br i1 %31, label %32, label %67
32: ; preds = %29
%33 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%34 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%35 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%36 = call i32 @dd_mul(double* %33, double* %34, double* %35)
%37 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%38 = getelementptr inbounds [2 x double], [2 x double]* %1, i64 0, i64 0
%39 = call i32 @dd_inc(double* %37, double* %38)
%40 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%41 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%42 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%43 = call i32 @dd_div(double* %40, double* %41, double* %42)
%44 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%45 = call i32 @dd_mlt_d(double* %44, double 5.000000e-01)
%46 = load i32, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%49 = call i32 @dd_write(double* %48, i32 32)
%50 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%51 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%52 = call i32 @dd_copy(double* %50, double* %51)
%53 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%54 = getelementptr inbounds [2 x double], [2 x double]* %3, i64 0, i64 0
%55 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%56 = call i32 @dd_sub(double* %53, double* %54, double* %55)
%57 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%58 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 0
%59 = call i32 @dd_abs(double* %57, double* %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%61 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 0
%62 = call i32 @dd_write(double* %61, i32 3)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %64
64: ; preds = %32
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %29
67: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@__const.my_sqrt.sqrt2 = [34 x i8] c"1.4142135623730950488016887242097\00"
@.str = [41 x i8] c"\0Arunning Newton's method for sqrt(2) ...\00"
@.str.1 = [32 x i8] c"y hi = %22.14e y lo = %22.14e\0A\00"
@.str.2 = [9 x i8] c"step 0: \00"
@.str.4 = [10 x i8] c"step %d: \00"
@.str.5 = [11 x i8] c" error : \00"
define i32 @my_sqrt() {
%1 = alloca <2 x double>
%2 = alloca [2 x double]
%3 = alloca [2 x double]
%4 = alloca [2 x double]
%5 = alloca [2 x double]
%6 = alloca [2 x double]
%7 = alloca [34 x i8]
%8 = bitcast <2 x double>* %1 to i8*
%9 = bitcast [2 x double]* %2 to i8*
%10 = bitcast [2 x double]* %3 to i8*
%11 = bitcast [2 x double]* %4 to i8*
%12 = bitcast [2 x double]* %5 to i8*
%13 = bitcast [2 x double]* %6 to i8*
%14 = getelementptr inbounds [34 x i8], [34 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds <2 x double>, <2 x double>* %1, i64 0, i64 0
store <2 x double> <double 2.000000e+00, double 0.000000e+00>, <2 x double>* %1
%16 = getelementptr inbounds [2 x double], [2 x double]* %2, i64 0, i64 0
%17 = call i32 @dd_copy(double* %15, double* %16)
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds [2 x double], [2 x double]* %3, i64 0, i64 0
%20 = call i32 @dd_read(i8* %14, double* %19)
%21 = load double, double* %19
%22 = getelementptr inbounds [2 x double], [2 x double]* %3, i64 0, i64 1
%23 = load double, double* %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), double %21, double %23)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @dd_write(double* %16, i32 32)
%27 = call i32 @putchar(i32 10)
%28 = getelementptr inbounds [2 x double], [2 x double]* %4, i64 0, i64 0
%29 = getelementptr inbounds [2 x double], [2 x double]* %5, i64 0, i64 0
%30 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 0
br label %31
31: ; preds = %0, %31
%32 = phi i32 [ 1, %0 ], [ %45, %31 ]
%33 = call i32 @dd_mul(double* %16, double* %16, double* %28)
%34 = call i32 @dd_inc(double* %28, double* %15)
%35 = call i32 @dd_div(double* %28, double* %16, double* %28)
%36 = call i32 @dd_mlt_d(double* %28, double 5.000000e-01)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%38 = call i32 @dd_write(double* %28, i32 32)
%39 = call i32 @dd_copy(double* %28, double* %16)
%40 = call i32 @dd_sub(double* %16, double* %19, double* %29)
%41 = call i32 @dd_abs(double* %29, double* %30)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%43 = call i32 @dd_write(double* %30, i32 3)
%44 = call i32 @putchar(i32 10)
%45 = add nuw nsw i32 %32, 1
%46 = icmp eq i32 %45, 10
br i1 %46, label %47, label %31
47: ; preds = %31
ret i32 0
}