#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 *malloc(int);
int /*<<< orphan*/ printf(char *, double, double);
double sqrt(double);
int main(void) {
  int i, j;
  double s, r;
  s = 0.0;
  double *a1 = malloc(1000 * sizeof(double));
  double *a2 = malloc(1000 * sizeof(double));
  for (i = 0; i < 1000; i++) {
    a1[i] = s;
    s += 0.3374893482232;
    a2[i] = s;
  }
  s = 0.0;
  r = 0.0;
  for (j = 0; j < 5000; j++) {
    for (i = 0; i < 1000; i++) {
      s += (a1[i] - a2[i]) * (a1[i] + a2[i]) - sqrt(r + 1.0);
      r += 0.001;
    }
  }
  printf("s = %f, r = %f\n", s, r);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x1f40,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x1f40,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    11bb <main+0x8b>
movsd  -0x18(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  0xe7f(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116a <main+0x3a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x1388,-0xc(%rbp)
jge    12ac <main+0x17c>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jge    1299 <main+0x169>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
movslq -0x8(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xdcf(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  -0x40(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xd7f(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11e6 <main+0xb6>
jmp    129e <main+0x16e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d2 <main+0xa2>
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
lea    0xd5b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    $0x1f40,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x1f40,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
xorpd  %xmm0,%xmm0
mov    $0x3,%eax
movsd  0xe9b(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm0,-0x18(%r14,%rax,8)
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbx,%rax,8)
movsd  %xmm0,-0x10(%r14,%rax,8)
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbx,%rax,8)
movsd  %xmm0,-0x8(%r14,%rax,8)
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbx,%rax,8)
movsd  %xmm0,(%r14,%rax,8)
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x4,%rax
cmp    $0x3eb,%rax
jne    1170 <main+0x40>
xorpd  %xmm8,%xmm8
xor    %r15d,%r15d
movsd  0xe39(%rip),%xmm9
movsd  0xe39(%rip),%xmm6
xorpd  %xmm1,%xmm1
xorpd  %xmm2,%xmm2
jmp    1201 <main+0xd1>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15d
cmp    $0x1388,%r15d
je     1357 <main+0x227>
mov    $0x1,%ebp
jmp    12b7 <main+0x187>
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,(%rsp)
movsd  %xmm2,0x30(%rsp)
movsd  %xmm10,0x28(%rsp)
movsd  %xmm11,0x20(%rsp)
call   1050 <sqrt@plt>
movsd  0x20(%rsp),%xmm11
movsd  0x28(%rsp),%xmm10
movsd  0x30(%rsp),%xmm2
movsd  0xdc6(%rip),%xmm6
movsd  0xdb5(%rip),%xmm9
xorpd  %xmm8,%xmm8
movsd  (%rsp),%xmm1
movsd  0x18(%rsp),%xmm3
movsd  0x10(%rsp),%xmm7
movsd  0x8(%rsp),%xmm4
movapd %xmm7,%xmm5
subsd  %xmm4,%xmm5
addsd  %xmm4,%xmm7
mulsd  %xmm5,%xmm7
subsd  %xmm10,%xmm7
addsd  %xmm7,%xmm3
movapd %xmm2,%xmm4
subsd  %xmm11,%xmm4
addsd  %xmm11,%xmm2
mulsd  %xmm4,%xmm2
subsd  %xmm0,%xmm2
addsd  %xmm3,%xmm2
addsd  %xmm6,%xmm1
add    $0x2,%rbp
cmp    $0x3e9,%rbp
je     11f0 <main+0xc0>
movsd  -0x8(%r14,%rbp,8),%xmm3
movsd  -0x8(%rbx,%rbp,8),%xmm7
movapd %xmm1,%xmm0
addsd  %xmm9,%xmm0
ucomisd %xmm8,%xmm0
movsd  %xmm2,0x18(%rsp)
movsd  %xmm3,0x10(%rsp)
movsd  %xmm7,0x8(%rsp)
jb     1300 <main+0x1d0>
xorps  %xmm10,%xmm10
sqrtsd %xmm0,%xmm10
jmp    132a <main+0x1fa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,(%rsp)
call   1050 <sqrt@plt>
movsd  0xcfe(%rip),%xmm6
movsd  0xced(%rip),%xmm9
xorpd  %xmm8,%xmm8
movsd  (%rsp),%xmm1
movapd %xmm0,%xmm10
addsd  %xmm6,%xmm1
movsd  (%r14,%rbp,8),%xmm2
movsd  (%rbx,%rbp,8),%xmm11
movapd %xmm1,%xmm0
addsd  %xmm9,%xmm0
ucomisd %xmm8,%xmm0
jb     1210 <main+0xe0>
sqrtsd %xmm0,%xmm0
jmp    125d <main+0x12d>
lea    0xcba(%rip),%rdi
movapd %xmm2,%xmm0
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"s = %f, r = %f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca double*
%7 = alloca double*
store i32 0, i32* %1
store double 0.000000e+00, double* %4
%8 = call double* @malloc(i32 8000)
store double* %8, double** %6
%9 = call double* @malloc(i32 8000)
store double* %9, double** %7
store i32 0, i32* %2
br label %10
10: ; preds = %26, %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 1000
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = load double, double* %4
%15 = load double*, double** %6
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
store double %14, double* %18
%19 = load double, double* %4
%20 = fadd double %19, 0x3FD5996CEC577CEC
store double %20, double* %4
%21 = load double, double* %4
%22 = load double*, double** %7
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
store double %21, double* %25
br label %26
26: ; preds = %13
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %10
29: ; preds = %10
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %3
br label %30
30: ; preds = %73, %29
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 5000
br i1 %32, label %33, label %76
33: ; preds = %30
store i32 0, i32* %2
br label %34
34: ; preds = %69, %33
%35 = load i32, i32* %2
%36 = icmp slt i32 %35, 1000
br i1 %36, label %37, label %72
37: ; preds = %34
%38 = load double*, double** %6
%39 = load i32, i32* %2
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
%42 = load double, double* %41
%43 = load double*, double** %7
%44 = load i32, i32* %2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = fsub double %42, %47
%49 = load double*, double** %6
%50 = load i32, i32* %2
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds double, double* %49, i64 %51
%53 = load double, double* %52
%54 = load double*, double** %7
%55 = load i32, i32* %2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %54, i64 %56
%58 = load double, double* %57
%59 = fadd double %53, %58
%60 = load double, double* %5
%61 = fadd double %60, 1.000000e+00
%62 = call double @sqrt(double %61)
%63 = fneg double %62
%64 = call double @llvm.fmuladd.f64(double %48, double %59, double %63)
%65 = load double, double* %4
%66 = fadd double %65, %64
store double %66, double* %4
%67 = load double, double* %5
%68 = fadd double %67, 1.000000e-03
store double %68, double* %5
br label %69
69: ; preds = %37
%70 = load i32, i32* %2
%71 = add nsw i32 %70, 1
store i32 %71, i32* %2
br label %34
72: ; preds = %34
br label %73
73: ; preds = %72
%74 = load i32, i32* %3
%75 = add nsw i32 %74, 1
store i32 %75, i32* %3
br label %30
76: ; preds = %30
%77 = load double, double* %4
%78 = load double, double* %5
%79 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double %77, double %78)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"s = %f, r = %f\0A\00"
define i32 @main() {
%1 = tail call double* @malloc(i32 8000)
%2 = tail call double* @malloc(i32 8000)
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ 0, %0 ], [ %21, %3 ]
%5 = phi double [ 0.000000e+00, %0 ], [ %19, %3 ]
%6 = getelementptr inbounds double, double* %1, i64 %4
store double %5, double* %6
%7 = fadd double %5, 0x3FD5996CEC577CEC
%8 = getelementptr inbounds double, double* %2, i64 %4
store double %7, double* %8
%9 = or i64 %4, 1
%10 = getelementptr inbounds double, double* %1, i64 %9
store double %7, double* %10
%11 = fadd double %7, 0x3FD5996CEC577CEC
%12 = getelementptr inbounds double, double* %2, i64 %9
store double %11, double* %12
%13 = or i64 %4, 2
%14 = getelementptr inbounds double, double* %1, i64 %13
store double %11, double* %14
%15 = fadd double %11, 0x3FD5996CEC577CEC
%16 = getelementptr inbounds double, double* %2, i64 %13
store double %15, double* %16
%17 = or i64 %4, 3
%18 = getelementptr inbounds double, double* %1, i64 %17
store double %15, double* %18
%19 = fadd double %15, 0x3FD5996CEC577CEC
%20 = getelementptr inbounds double, double* %2, i64 %17
store double %19, double* %20
%21 = add nuw nsw i64 %4, 4
%22 = icmp eq i64 %21, 1000
br i1 %22, label %23, label %3
23: ; preds = %3, %58
%24 = phi i32 [ %59, %58 ], [ 0, %3 ]
%25 = phi double [ %55, %58 ], [ 0.000000e+00, %3 ]
%26 = phi double [ %54, %58 ], [ 0.000000e+00, %3 ]
br label %27
27: ; preds = %27, %23
%28 = phi i64 [ 0, %23 ], [ %56, %27 ]
%29 = phi double [ %25, %23 ], [ %55, %27 ]
%30 = phi double [ %26, %23 ], [ %54, %27 ]
%31 = getelementptr inbounds double, double* %1, i64 %28
%32 = load double, double* %31
%33 = getelementptr inbounds double, double* %2, i64 %28
%34 = load double, double* %33
%35 = fsub double %32, %34
%36 = fadd double %32, %34
%37 = fadd double %29, 1.000000e+00
%38 = tail call double @sqrt(double %37)
%39 = fneg double %38
%40 = tail call double @llvm.fmuladd.f64(double %35, double %36, double %39)
%41 = fadd double %30, %40
%42 = fadd double %29, 1.000000e-03
%43 = or i64 %28, 1
%44 = getelementptr inbounds double, double* %1, i64 %43
%45 = load double, double* %44
%46 = getelementptr inbounds double, double* %2, i64 %43
%47 = load double, double* %46
%48 = fsub double %45, %47
%49 = fadd double %45, %47
%50 = fadd double %42, 1.000000e+00
%51 = tail call double @sqrt(double %50)
%52 = fneg double %51
%53 = tail call double @llvm.fmuladd.f64(double %48, double %49, double %52)
%54 = fadd double %41, %53
%55 = fadd double %42, 1.000000e-03
%56 = add nuw nsw i64 %28, 2
%57 = icmp eq i64 %56, 1000
br i1 %57, label %58, label %27
58: ; preds = %27
%59 = add nuw nsw i32 %24, 1
%60 = icmp eq i32 %59, 5000
br i1 %60, label %61, label %23
61: ; preds = %58
%62 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), double %54, double %55)
ret i32 0
}