#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 */
typedef int clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int clock();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  printf("Starting\n");
  int SIZE = 1000;
  int MINOR_LOOPS = 1000;
  int LOOPS = 10;
  double a[SIZE][SIZE];
  int n;
  for (n = 0; n < LOOPS; n++) {
    int i, j;
    for (i = 0; i < SIZE; i++) {
      for (j = 0; j < SIZE; j++) {
        a[i][j] = 0;
      }
    }
    clock_t start, diff;
    start = clock();
    int k;
    for (k = 0; k < MINOR_LOOPS; k++) {
      a[0][0] = 1;
      for (i = 1; i < SIZE - 1; i++) {
        for (j = 1; j < SIZE - 1; j++) {
          a[i][j] = (a[i][j] + a[i - 1][j] + a[i + 1][j] + a[i][j + 1] +
                     a[i][j - 1]) /
                    5;
        }
      }
    }
    diff = clock() - start;
    int msec = diff * 1000 / CLOCKS_PER_SEC;
    printf("Time taken %f seconds\n", msec / 1000.0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x3e8,-0x8(%rbp)
movl   $0x3e8,-0xc(%rbp)
movl   $0xa,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rdx
imul   %rdx,%rdx
lea    0xf(,%rdx,8),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    13b9 <main+0x299>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120a <main+0xea>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f7 <main+0xd7>
mov    -0x50(%rbp),%rax
mov    -0x58(%rbp),%rdx
movslq -0x30(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x34(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ba <main+0x9a>
jmp    11fc <main+0xdc>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a7 <main+0x87>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    136b <main+0x24b>
mov    -0x50(%rbp),%rax
mov    -0x58(%rbp),%rcx
imul   $0x0,%rcx,%rcx
movsd  0xdcd(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1358 <main+0x238>
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1345 <main+0x225>
mov    -0x50(%rbp),%rax
mov    -0x58(%rbp),%rdx
movslq -0x30(%rbp),%rsi
imul   %rdx,%rsi
shl    $0x3,%rsi
mov    %rax,%rcx
add    %rsi,%rcx
movslq -0x34(%rbp),%rsi
movsd  (%rcx,%rsi,8),%xmm0
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rsi
imul   %rdx,%rsi
shl    $0x3,%rsi
mov    %rax,%rcx
add    %rsi,%rcx
movslq -0x34(%rbp),%rsi
addsd  (%rcx,%rsi,8),%xmm0
mov    -0x30(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rsi
imul   %rdx,%rsi
shl    $0x3,%rsi
mov    %rax,%rcx
add    %rsi,%rcx
movslq -0x34(%rbp),%rsi
addsd  (%rcx,%rsi,8),%xmm0
movslq -0x30(%rbp),%rsi
imul   %rdx,%rsi
shl    $0x3,%rsi
mov    %rax,%rcx
add    %rsi,%rcx
mov    -0x34(%rbp),%esi
add    $0x1,%esi
movslq %esi,%rsi
addsd  (%rcx,%rsi,8),%xmm0
movslq -0x30(%rbp),%rsi
imul   %rdx,%rsi
shl    $0x3,%rsi
mov    %rax,%rcx
add    %rsi,%rcx
mov    -0x34(%rbp),%esi
sub    $0x1,%esi
movslq %esi,%rsi
addsd  (%rcx,%rsi,8),%xmm0
movsd  0xcf5(%rip),%xmm1
divsd  %xmm1,%xmm0
movslq -0x30(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    125f <main+0x13f>
jmp    134a <main+0x22a>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1247 <main+0x127>
jmp    135d <main+0x23d>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    121b <main+0xfb>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x38(%rbp),%eax
mov    %eax,-0x3c(%rbp)
imul   $0x3e8,-0x3c(%rbp),%eax
mov    0x2c62(%rip),%rcx
cltd
idivl  (%rcx)
mov    %eax,-0x44(%rbp)
cvtsi2sdl -0x44(%rbp),%xmm0
movsd  0xc67(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xc7e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1194 <main+0x74>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7a1208,%rsp
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
lea    0x3e88(%rsp),%rbx
movabs $0x3ff0000000000000,%rbp
mov    0x2e72(%rip),%r13
lea    0xe93(%rip),%r15
xor    %r14d,%r14d
mov    $0x7a1200,%edx
mov    %rsp,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %eax,%r12d
xor    %eax,%eax
movsd  0xe5d(%rip),%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,(%rsp)
mov    $0x1,%ecx
mov    %rbx,%rdx
nopl   0x0(%rax)
imul   $0x1f40,%rcx,%rsi
add    $0x1,%rcx
movsd  (%rsp,%rsi,1),%xmm1
movsd  0x8(%rsp,%rsi,1),%xmm0
mov    $0xfffffffffffffc1a,%rsi
nopl   (%rax)
addsd  -0x1f50(%rdx,%rsi,8),%xmm0
ff ff
addsd  0x1f30(%rdx,%rsi,8),%xmm0
movsd  -0x8(%rdx,%rsi,8),%xmm2
addsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm0,-0x10(%rdx,%rsi,8)
movapd %xmm0,%xmm1
movapd %xmm2,%xmm0
inc    %rsi
jne    11e0 <main+0xa0>
add    $0x1f40,%rdx
cmp    $0x3e7,%rcx
jne    11c0 <main+0x80>
add    $0x1,%eax
cmp    $0x3e8,%eax
jne    11b0 <main+0x70>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r12d,%eax
imul   $0x3e8,%eax,%eax
cltd
idivl  0x0(%r13)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xdaf(%rip),%xmm0
mov    %r15,%rdi
mov    $0x1,%al
call   1050 <printf@plt>
add    $0x1,%r14d
cmp    $0xa,%r14d
jne    1180 <main+0x40>
xor    %eax,%eax
add    $0x7a1208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Starting\0A\00"
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [23 x i8] c"Time taken %f seconds\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %1
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 1000, i32* %2
store i32 1000, i32* %3
store i32 10, i32* %4
%16 = load i32, i32* %2
%17 = zext i32 %16 to i64
%18 = load i32, i32* %2
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %5
%21 = mul nuw i64 %17, %19
%22 = alloca double, i64 %21
store i64 %17, i64* %6
store i64 %19, i64* %7
store i32 0, i32* %8
br label %23
23: ; preds = %153, %0
%24 = load i32, i32* %8
%25 = load i32, i32* %4
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %156
27: ; preds = %23
store i32 0, i32* %9
br label %28
28: ; preds = %49, %27
%29 = load i32, i32* %9
%30 = load i32, i32* %2
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %52
32: ; preds = %28
store i32 0, i32* %10
br label %33
33: ; preds = %45, %32
%34 = load i32, i32* %10
%35 = load i32, i32* %2
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %33
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = mul nsw i64 %39, %19
%41 = getelementptr inbounds double, double* %22, i64 %40
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
store double 0.000000e+00, double* %44
br label %45
45: ; preds = %37
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %33
48: ; preds = %33
br label %49
49: ; preds = %48
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %28
52: ; preds = %28
%53 = call i32 (...) @clock()
store i32 %53, i32* %11
store i32 0, i32* %13
br label %54
54: ; preds = %138, %52
%55 = load i32, i32* %13
%56 = load i32, i32* %3
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %141
58: ; preds = %54
%59 = mul nsw i64 0, %19
%60 = getelementptr inbounds double, double* %22, i64 %59
%61 = getelementptr inbounds double, double* %60, i64 0
store double 1.000000e+00, double* %61
store i32 1, i32* %9
br label %62
62: ; preds = %134, %58
%63 = load i32, i32* %9
%64 = load i32, i32* %2
%65 = sub nsw i32 %64, 1
%66 = icmp slt i32 %63, %65
br i1 %66, label %67, label %137
67: ; preds = %62
store i32 1, i32* %10
br label %68
68: ; preds = %130, %67
%69 = load i32, i32* %10
%70 = load i32, i32* %2
%71 = sub nsw i32 %70, 1
%72 = icmp slt i32 %69, %71
br i1 %72, label %73, label %133
73: ; preds = %68
%74 = load i32, i32* %9
%75 = sext i32 %74 to i64
%76 = mul nsw i64 %75, %19
%77 = getelementptr inbounds double, double* %22, i64 %76
%78 = load i32, i32* %10
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %77, i64 %79
%81 = load double, double* %80
%82 = load i32, i32* %9
%83 = sub nsw i32 %82, 1
%84 = sext i32 %83 to i64
%85 = mul nsw i64 %84, %19
%86 = getelementptr inbounds double, double* %22, i64 %85
%87 = load i32, i32* %10
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %86, i64 %88
%90 = load double, double* %89
%91 = fadd double %81, %90
%92 = load i32, i32* %9
%93 = add nsw i32 %92, 1
%94 = sext i32 %93 to i64
%95 = mul nsw i64 %94, %19
%96 = getelementptr inbounds double, double* %22, i64 %95
%97 = load i32, i32* %10
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds double, double* %96, i64 %98
%100 = load double, double* %99
%101 = fadd double %91, %100
%102 = load i32, i32* %9
%103 = sext i32 %102 to i64
%104 = mul nsw i64 %103, %19
%105 = getelementptr inbounds double, double* %22, i64 %104
%106 = load i32, i32* %10
%107 = add nsw i32 %106, 1
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds double, double* %105, i64 %108
%110 = load double, double* %109
%111 = fadd double %101, %110
%112 = load i32, i32* %9
%113 = sext i32 %112 to i64
%114 = mul nsw i64 %113, %19
%115 = getelementptr inbounds double, double* %22, i64 %114
%116 = load i32, i32* %10
%117 = sub nsw i32 %116, 1
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds double, double* %115, i64 %118
%120 = load double, double* %119
%121 = fadd double %111, %120
%122 = fdiv double %121, 5.000000e+00
%123 = load i32, i32* %9
%124 = sext i32 %123 to i64
%125 = mul nsw i64 %124, %19
%126 = getelementptr inbounds double, double* %22, i64 %125
%127 = load i32, i32* %10
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds double, double* %126, i64 %128
store double %122, double* %129
br label %130
130: ; preds = %73
%131 = load i32, i32* %10
%132 = add nsw i32 %131, 1
store i32 %132, i32* %10
br label %68
133: ; preds = %68
br label %134
134: ; preds = %133
%135 = load i32, i32* %9
%136 = add nsw i32 %135, 1
store i32 %136, i32* %9
br label %62
137: ; preds = %62
br label %138
138: ; preds = %137
%139 = load i32, i32* %13
%140 = add nsw i32 %139, 1
store i32 %140, i32* %13
br label %54
141: ; preds = %54
%142 = call i32 (...) @clock()
%143 = load i32, i32* %11
%144 = sub nsw i32 %142, %143
store i32 %144, i32* %12
%145 = load i32, i32* %12
%146 = mul nsw i32 %145, 1000
%147 = load i32, i32* @CLOCKS_PER_SEC
%148 = sdiv i32 %146, %147
store i32 %148, i32* %14
%149 = load i32, i32* %14
%150 = sitofp i32 %149 to double
%151 = fdiv double %150, 1.000000e+03
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %151)
br label %153
153: ; preds = %141
%154 = load i32, i32* %8
%155 = add nsw i32 %154, 1
store i32 %155, i32* %8
br label %23
156: ; preds = %23
store i32 0, i32* %1
%157 = load i8*, i8** %5
%158 = load i32, i32* %1
ret i32 %158
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [23 x i8] c"Time taken %f seconds\0A\00"
@str = [9 x i8] c"Starting\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%2 = alloca [1000000 x double]
%3 = bitcast [1000000 x double]* %2 to i8*
%4 = getelementptr inbounds [1000000 x double], [1000000 x double]* %2, i64 0, i64 0
br label %5
5: ; preds = %0, %46
%6 = phi i32 [ 0, %0 ], [ %55, %46 ]
%7 = tail call i32 (...) @clock()
br label %8
8: ; preds = %5, %43
%9 = phi i32 [ 0, %5 ], [ %44, %43 ]
store double 1.000000e+00, double* %4
br label %10
10: ; preds = %8, %41
%11 = phi i64 [ 1, %8 ], [ %17, %41 ]
%12 = mul nuw nsw i64 %11, 1000
%13 = getelementptr inbounds [1000000 x double], [1000000 x double]* %2, i64 0, i64 %12
%14 = mul i64 %11, 1000
%15 = add i64 %14, -1000
%16 = getelementptr inbounds [1000000 x double], [1000000 x double]* %2, i64 0, i64 %15
%17 = add nuw nsw i64 %11, 1
%18 = mul nuw nsw i64 %17, 1000
%19 = getelementptr inbounds [1000000 x double], [1000000 x double]* %2, i64 0, i64 %18
%20 = getelementptr inbounds double, double* %13, i64 1
%21 = load double, double* %20
%22 = load double, double* %13
br label %23
23: ; preds = %10, %23
%24 = phi double [ %22, %10 ], [ %39, %23 ]
%25 = phi double [ %21, %10 ], [ %36, %23 ]
%26 = phi i64 [ 1, %10 ], [ %34, %23 ]
%27 = getelementptr inbounds double, double* %13, i64 %26
%28 = getelementptr inbounds double, double* %16, i64 %26
%29 = load double, double* %28
%30 = fadd double %25, %29
%31 = getelementptr inbounds double, double* %19, i64 %26
%32 = load double, double* %31
%33 = fadd double %30, %32
%34 = add nuw nsw i64 %26, 1
%35 = getelementptr inbounds double, double* %13, i64 %34
%36 = load double, double* %35
%37 = fadd double %33, %36
%38 = fadd double %37, %24
%39 = fdiv double %38, 5.000000e+00
store double %39, double* %27
%40 = icmp eq i64 %34, 999
br i1 %40, label %41, label %23
41: ; preds = %23
%42 = icmp eq i64 %17, 999
br i1 %42, label %43, label %10
43: ; preds = %41
%44 = add nuw nsw i32 %9, 1
%45 = icmp eq i32 %44, 1000
br i1 %45, label %46, label %8
46: ; preds = %43
%47 = tail call i32 (...) @clock()
%48 = sub nsw i32 %47, %7
%49 = mul nsw i32 %48, 1000
%50 = load i32, i32* @CLOCKS_PER_SEC
%51 = sdiv i32 %49, %50
%52 = sitofp i32 %51 to double
%53 = fdiv double %52, 1.000000e+03
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), double %53)
%55 = add nuw nsw i32 %6, 1
%56 = icmp eq i32 %55, 10
br i1 %56, label %57, label %5
57: ; preds = %46
ret i32 0
}