#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 uint32_t;

/* Variables and functions */
scalar_t__ calloc(int, int);
int main() {
  uint32_t grid_dim = 1000;
  uint32_t n_tests;
  uint32_t *counts = (uint32_t *)calloc(grid_dim * grid_dim, sizeof(uint32_t));
  for (n_tests = 0; n_tests < 100000; ++n_tests) {
    uint32_t y;
    for (y = 0; y < grid_dim; ++y) {
      uint32_t x;
      for (x = 0; x < grid_dim; ++x) {
        counts[y * grid_dim + x] += 1;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
mov    -0x8(%rbp),%edi
imul   -0x8(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x186a0,-0xc(%rbp)
jge    11c3 <main+0xb3>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11b0 <main+0xa0>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119d <main+0x8d>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1169 <main+0x59>
jmp    11a2 <main+0x92>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <main+0x46>
jmp    11b5 <main+0xa5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1142 <main+0x32>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0xf4240,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
xor    %ecx,%ecx
pcmpeqd %xmm0,%xmm0
jmp    113f <main+0x2f>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ecx
cmp    $0x186a0,%ecx
je     11bd <main+0xad>
mov    %rax,%rdx
xor    %esi,%esi
jmp    1164 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rsi
add    $0xfa0,%rdx
cmp    $0x3e8,%rsi
je     1130 <main+0x20>
mov    $0xc,%edi
nopl   0x0(%rax)
movdqu -0x30(%rdx,%rdi,4),%xmm1
movdqu -0x20(%rdx,%rdi,4),%xmm2
psubd  %xmm0,%xmm1
psubd  %xmm0,%xmm2
movdqu %xmm1,-0x30(%rdx,%rdi,4)
movdqu %xmm2,-0x20(%rdx,%rdi,4)
cmp    $0x3ec,%rdi
je     1150 <main+0x40>
movdqu -0x10(%rdx,%rdi,4),%xmm1
movdqu (%rdx,%rdi,4),%xmm2
psubd  %xmm0,%xmm1
psubd  %xmm0,%xmm2
movdqu %xmm1,-0x10(%rdx,%rdi,4)
movdqu %xmm2,(%rdx,%rdi,4)
add    $0x10,%rdi
jmp    1170 <main+0x60>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 1000, i32* %2
%7 = load i32, i32* %2
%8 = load i32, i32* %2
%9 = mul nsw i32 %7, %8
%10 = call i64 @calloc(i32 %9, i32 4)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %4
store i32 0, i32* %3
br label %12
12: ; preds = %44, %0
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 100000
br i1 %14, label %15, label %47
15: ; preds = %12
store i32 0, i32* %5
br label %16
16: ; preds = %40, %15
%17 = load i32, i32* %5
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %43
20: ; preds = %16
store i32 0, i32* %6
br label %21
21: ; preds = %36, %20
%22 = load i32, i32* %6
%23 = load i32, i32* %2
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = load i32, i32* %2
%29 = mul nsw i32 %27, %28
%30 = load i32, i32* %6
%31 = add nsw i32 %29, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %26, i64 %32
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
br label %36
36: ; preds = %25
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %21
39: ; preds = %21
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %16
43: ; preds = %16
br label %44
44: ; preds = %43
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
br label %12
47: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i64 @calloc(i32 1000000, i32 4)
%2 = inttoptr i64 %1 to i32*
br label %3
3: ; preds = %0, %39
%4 = phi i32 [ 0, %0 ], [ %40, %39 ]
br label %5
5: ; preds = %3, %36
%6 = phi i64 [ 0, %3 ], [ %37, %36 ]
%7 = mul nuw nsw i64 %6, 1000
br label %8
8: ; preds = %23, %5
%9 = phi i64 [ 0, %5 ], [ %35, %23 ]
%10 = add nuw nsw i64 %9, %7
%11 = getelementptr inbounds i32, i32* %2, i64 %10
%12 = bitcast i32* %11 to <4 x i32>*
%13 = load <4 x i32>, <4 x i32>* %12
%14 = getelementptr inbounds i32, i32* %11, i64 4
%15 = bitcast i32* %14 to <4 x i32>*
%16 = load <4 x i32>, <4 x i32>* %15
%17 = add nsw <4 x i32> %13, <i32 1, i32 1, i32 1, i32 1>
%18 = add nsw <4 x i32> %16, <i32 1, i32 1, i32 1, i32 1>
%19 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %17, <4 x i32>* %19
%20 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> %18, <4 x i32>* %20
%21 = or i64 %9, 8
%22 = icmp eq i64 %21, 1000
br i1 %22, label %36, label %23
23: ; preds = %8
%24 = add nuw nsw i64 %21, %7
%25 = getelementptr inbounds i32, i32* %2, i64 %24
%26 = bitcast i32* %25 to <4 x i32>*
%27 = load <4 x i32>, <4 x i32>* %26
%28 = getelementptr inbounds i32, i32* %25, i64 4
%29 = bitcast i32* %28 to <4 x i32>*
%30 = load <4 x i32>, <4 x i32>* %29
%31 = add nsw <4 x i32> %27, <i32 1, i32 1, i32 1, i32 1>
%32 = add nsw <4 x i32> %30, <i32 1, i32 1, i32 1, i32 1>
%33 = bitcast i32* %25 to <4 x i32>*
store <4 x i32> %31, <4 x i32>* %33
%34 = bitcast i32* %28 to <4 x i32>*
store <4 x i32> %32, <4 x i32>* %34
%35 = add nuw nsw i64 %9, 16
br label %8
36: ; preds = %8
%37 = add nuw nsw i64 %6, 1
%38 = icmp eq i64 %37, 1000
br i1 %38, label %39, label %5
39: ; preds = %36
%40 = add nuw nsw i32 %4, 1
%41 = icmp eq i32 %40, 100000
br i1 %41, label %42, label %3
42: ; preds = %39
ret i32 0
}