#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*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ qd_abs(double *, double *);
int /*<<< orphan*/ qd_add(double *, double *, double *);
int /*<<< orphan*/ qd_copy(double *, double *);
int /*<<< orphan*/ qd_div(double *, double *, double *);
int /*<<< orphan*/ qd_mul(double *, double *, double *);
int /*<<< orphan*/ qd_mul_d(double *, double, double *);
int /*<<< orphan*/ qd_read(char *, double *);
int /*<<< orphan*/ qd_real(double, double *);
int /*<<< orphan*/ qd_sub(double *, double *, double *);
int /*<<< orphan*/ qd_write(double *, int);
int my_sqrt(void) {
  double n[4], x[4], y[4], z[4], e[4], a[4];
  const int max_steps = 9;
  char sqrt2[66] =
      "1.414213562373095048801688724209698078569671875376948073176679738\0";
  int i;
  qd_real(2.0, n);
  qd_copy(n, x);
  puts("\nrunning Newton's method for sqrt(2) ...");
  printf("applying qd_read to the string \n%s\n", sqrt2);
  qd_read(sqrt2, y);
  for (i = 0; i < 4; i++)
    printf("y[%d] = %22.14e\n", i, y[i]);
  printf(" sqrt2: ");
  qd_write(y, 64);
  printf("\n");
  printf("step 0: ");
  qd_write(x, 64);
  printf("\n");
  for (i = 1; i <= max_steps; i++) {
    qd_mul(x, x, z);
    qd_add(z, n, z);
    qd_div(z, x, z);
    qd_mul_d(z, 0.5, z);
    printf("step %d: ", i);
    qd_write(z, 64);
    qd_copy(z, x);
    qd_sub(x, y, e);
    qd_abs(e, a);
    printf("  error : ");
    qd_write(a, 3);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<my_sqrt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x9,-0xc4(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x42,%edx
call   1070 <memcpy@plt>
lea    -0x20(%rbp),%rdi
movsd  0xdf7(%rip),%xmm0
call   10c0 <qd_real@plt>
lea    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10e0 <qd_copy@plt>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
lea    -0x110(%rbp),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   10a0 <qd_read@plt>
movl   $0x0,-0x114(%rbp)
cmpl   $0x4,-0x114(%rbp)
jge    1298 <my_sqrt+0xc8>
mov    -0x114(%rbp),%esi
movslq -0x114(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm0
lea    0xe22(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    1256 <my_sqrt+0x86>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x40,%esi
call   10d0 <qd_write@plt>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    $0x40,%esi
call   10d0 <qd_write@plt>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x114(%rbp)
cmpl   $0x9,-0x114(%rbp)
jg     13e2 <my_sqrt+0x212>
lea    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   10b0 <qd_mul@plt>
lea    -0x80(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1080 <qd_add@plt>
lea    -0x80(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   10f0 <qd_div@plt>
lea    -0x80(%rbp),%rdi
lea    -0x80(%rbp),%rsi
movsd  0xcc2(%rip),%xmm0
call   1090 <qd_mul_d@plt>
mov    -0x114(%rbp),%esi
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    $0x40,%esi
call   10d0 <qd_write@plt>
lea    -0x80(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10e0 <qd_copy@plt>
lea    -0x40(%rbp),%rdi
lea    -0x60(%rbp),%rsi
lea    -0xa0(%rbp),%rdx
call   1030 <qd_sub@plt>
lea    -0xa0(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1050 <qd_abs@plt>
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    $0x3,%esi
call   10d0 <qd_write@plt>
lea    0xce7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    12f6 <my_sqrt+0x126>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_sqrt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
movaps 0xe58(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe3c(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe20(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe04(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movw   $0x38,0x60(%rsp)
movsd  0xde0(%rip),%xmm0
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <qd_real@plt>
lea    0xf0(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   10e0 <qd_copy@plt>
lea    0xe0b(%rip),%rdi
call   1050 <puts@plt>
lea    0xe28(%rip),%rdi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <qd_read@plt>
movsd  (%rsp),%xmm0
lea    0xe23(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%al
call   1070 <printf@plt>
movsd  0x8(%rsp),%xmm0
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%al
call   1070 <printf@plt>
movsd  0x10(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1,%al
call   1070 <printf@plt>
movsd  0x18(%rsp),%xmm0
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x1,%al
call   1070 <printf@plt>
lea    0xddd(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
mov    $0x40,%esi
call   10d0 <qd_write@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdc1(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
mov    $0x40,%esi
call   10d0 <qd_write@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xd0(%rsp),%rbx
lea    0xb0(%rsp),%r14
lea    0x90(%rsp),%r15
lea    0xd97(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10b0 <qd_mul@plt>
mov    %rbx,%rdi
lea    0x70(%rsp),%rsi
mov    %rbx,%rdx
call   1080 <qd_add@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10f0 <qd_div@plt>
mov    %rbx,%rdi
movsd  0xc91(%rip),%xmm0
mov    %rbx,%rsi
call   1090 <qd_mul_d@plt>
lea    0xd3c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x40,%esi
call   10d0 <qd_write@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10e0 <qd_copy@plt>
mov    %r12,%rdi
mov    %rsp,%rsi
mov    %r14,%rdx
call   1030 <qd_sub@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <qd_abs@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    $0x3,%esi
call   10d0 <qd_write@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
add    $0x1,%ebp
cmp    $0xa,%ebp
jne    1340 <my_sqrt+0x170>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.my_sqrt.sqrt2 = [66 x i8] c"1.414213562373095048801688724209698078569671875376948073176679738\00"
@.str = [41 x i8] c"\0Arunning Newton's method for sqrt(2) ...\00"
@.str.1 = [36 x i8] c"applying qd_read to the string \0A%s\0A\00"
@.str.2 = [17 x i8] c"y[%d] = %22.14e\0A\00"
@.str.3 = [9 x i8] c" sqrt2: \00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [9 x i8] c"step 0: \00"
@.str.6 = [10 x i8] c"step %d: \00"
@.str.7 = [11 x i8] c" error : \00"
define i32 @my_sqrt() {
%1 = alloca [4 x double]
%2 = alloca [4 x double]
%3 = alloca [4 x double]
%4 = alloca [4 x double]
%5 = alloca [4 x double]
%6 = alloca [4 x double]
%7 = alloca i32
%8 = alloca [66 x i8]
%9 = alloca i32
store i32 9, i32* %7
%10 = bitcast [66 x i8]* %8 to i8*
%11 = getelementptr inbounds [4 x double], [4 x double]* %1, i64 0, i64 0
%12 = call i32 @qd_real(double 2.000000e+00, double* %11)
%13 = getelementptr inbounds [4 x double], [4 x double]* %1, i64 0, i64 0
%14 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%15 = call i32 @qd_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 [66 x i8], [66 x i8]* %8, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [66 x i8], [66 x i8]* %8, i64 0, i64 0
%20 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%21 = call i32 @qd_read(i8* %19, double* %20)
store i32 0, i32* %9
br label %22
22: ; preds = %32, %0
%23 = load i32, i32* %9
%24 = icmp slt i32 %23, 4
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i32, i32* %9
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 %28
%30 = load double, double* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %26, double %30)
br label %32
32: ; preds = %25
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %22
35: ; preds = %22
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%37 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%38 = call i32 @qd_write(double* %37, i32 64)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%41 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%42 = call i32 @qd_write(double* %41, i32 64)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %9
br label %44
44: ; preds = %81, %35
%45 = load i32, i32* %9
%46 = icmp sle i32 %45, 9
br i1 %46, label %47, label %84
47: ; preds = %44
%48 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%49 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%50 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%51 = call i32 @qd_mul(double* %48, double* %49, double* %50)
%52 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%53 = getelementptr inbounds [4 x double], [4 x double]* %1, i64 0, i64 0
%54 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%55 = call i32 @qd_add(double* %52, double* %53, double* %54)
%56 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%57 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%58 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%59 = call i32 @qd_div(double* %56, double* %57, double* %58)
%60 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%61 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%62 = call i32 @qd_mul_d(double* %60, double 5.000000e-01, double* %61)
%63 = load i32, i32* %9
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %63)
%65 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%66 = call i32 @qd_write(double* %65, i32 64)
%67 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%68 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%69 = call i32 @qd_copy(double* %67, double* %68)
%70 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%71 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%72 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%73 = call i32 @qd_sub(double* %70, double* %71, double* %72)
%74 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%75 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%76 = call i32 @qd_abs(double* %74, double* %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%78 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
%79 = call i32 @qd_write(double* %78, i32 3)
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %81
81: ; preds = %47
%82 = load i32, i32* %9
%83 = add nsw i32 %82, 1
store i32 %83, i32* %9
br label %44
84: ; preds = %44
ret i32 0
}

LLVM IR (-O2):
@__const.my_sqrt.sqrt2 = [66 x i8] c"1.414213562373095048801688724209698078569671875376948073176679738\00"
@.str = [41 x i8] c"\0Arunning Newton's method for sqrt(2) ...\00"
@.str.1 = [36 x i8] c"applying qd_read to the string \0A%s\0A\00"
@.str.2 = [17 x i8] c"y[%d] = %22.14e\0A\00"
@.str.3 = [9 x i8] c" sqrt2: \00"
@.str.5 = [9 x i8] c"step 0: \00"
@.str.6 = [10 x i8] c"step %d: \00"
@.str.7 = [11 x i8] c" error : \00"
define i32 @my_sqrt() {
%1 = alloca [4 x double]
%2 = alloca [4 x double]
%3 = alloca [4 x double]
%4 = alloca [4 x double]
%5 = alloca [4 x double]
%6 = alloca [4 x double]
%7 = alloca [66 x i8]
%8 = bitcast [4 x double]* %1 to i8*
%9 = bitcast [4 x double]* %2 to i8*
%10 = bitcast [4 x double]* %3 to i8*
%11 = bitcast [4 x double]* %4 to i8*
%12 = bitcast [4 x double]* %5 to i8*
%13 = bitcast [4 x double]* %6 to i8*
%14 = getelementptr inbounds [66 x i8], [66 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [4 x double], [4 x double]* %1, i64 0, i64 0
%16 = call i32 @qd_real(double 2.000000e+00, double* %15)
%17 = getelementptr inbounds [4 x double], [4 x double]* %2, i64 0, i64 0
%18 = call i32 @qd_copy(double* %15, double* %17)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%21 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 0
%22 = call i32 @qd_read(i8* %14, double* %21)
%23 = load double, double* %21
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 0, double %23)
%25 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 1
%26 = load double, double* %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 1, double %26)
%28 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 2
%29 = load double, double* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 2, double %29)
%31 = getelementptr inbounds [4 x double], [4 x double]* %3, i64 0, i64 3
%32 = load double, double* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 3, double %32)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @qd_write(double* %21, i32 64)
%36 = call i32 @putchar(i32 10)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%38 = call i32 @qd_write(double* %17, i32 64)
%39 = call i32 @putchar(i32 10)
%40 = getelementptr inbounds [4 x double], [4 x double]* %4, i64 0, i64 0
%41 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%42 = getelementptr inbounds [4 x double], [4 x double]* %6, i64 0, i64 0
br label %43
43: ; preds = %0, %43
%44 = phi i32 [ 1, %0 ], [ %57, %43 ]
%45 = call i32 @qd_mul(double* %17, double* %17, double* %40)
%46 = call i32 @qd_add(double* %40, double* %15, double* %40)
%47 = call i32 @qd_div(double* %40, double* %17, double* %40)
%48 = call i32 @qd_mul_d(double* %40, double 5.000000e-01, double* %40)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %44)
%50 = call i32 @qd_write(double* %40, i32 64)
%51 = call i32 @qd_copy(double* %40, double* %17)
%52 = call i32 @qd_sub(double* %17, double* %21, double* %41)
%53 = call i32 @qd_abs(double* %41, double* %42)
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%55 = call i32 @qd_write(double* %42, i32 3)
%56 = call i32 @putchar(i32 10)
%57 = add nuw nsw i32 %44, 1
%58 = icmp eq i32 %57, 10
br i1 %58, label %59, label %43
59: ; preds = %43
ret i32 0
}