#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 */
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ printf(char *, unsigned int, int);
int main() {
  unsigned int x, y, idx, H = 1024, W = 1024;
  int *tmps = (int *)malloc(H * W * sizeof(int));
  for (x = 1; x < H; x++) {
    for (y = 1; y < W; y++) {
      idx = x * W + y;
      tmps[idx % 4096] = idx;
    }
  }
  for (x = 1; x < 8; x++)
    printf("tmps[%d]=%d\n", x, tmps[x]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x400,-0x14(%rbp)
movl   $0x400,-0x18(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    11be <main+0x9e>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11ab <main+0x8b>
mov    -0x8(%rbp),%eax
imul   -0x18(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
and    $0xfff,%ecx
mov    %ecx,%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <main+0x4f>
jmp    11b0 <main+0x90>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115c <main+0x3c>
movl   $0x1,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jae    11f6 <main+0xd6>
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    (%rax,%rcx,4),%edx
lea    0xe1d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c5 <main+0xa5>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x400000,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x1,%eax
movdqa 0xec1(%rip),%xmm8
movdqa 0xec8(%rip),%xmm9
mov    $0x7,%ecx
movq   %rcx,%xmm2
movdqa 0xec5(%rip),%xmm10
movdqa 0xecd(%rip),%xmm4
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rcx
shl    $0xa,%rcx
movq   %rax,%xmm5
pshufd $0x44,%xmm5,%xmm5
psllq  $0xa,%xmm5
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
movq   %rdx,%xmm6
pshufd $0x44,%xmm6,%xmm7
movdqa %xmm7,%xmm0
por    %xmm8,%xmm0
movdqa %xmm7,%xmm1
por    %xmm9,%xmm1
por    %xmm2,%xmm6
movdqa %xmm7,%xmm3
por    %xmm10,%xmm3
paddq  %xmm4,%xmm7
movsd  %xmm6,%xmm7
paddq  %xmm5,%xmm1
paddq  %xmm5,%xmm0
paddq  %xmm5,%xmm3
paddq  %xmm5,%xmm7
shufps $0x88,%xmm7,%xmm3
movq   %xmm0,%rsi
movd   %esi,%xmm6
and    $0xff9,%esi
shufps $0x88,%xmm1,%xmm0
movss  %xmm6,%xmm0
movups %xmm0,(%rbx,%rsi,4)
movups %xmm3,0x10(%rbx,%rsi,4)
add    $0x8,%rdx
cmp    $0x3f8,%rdx
jne    1190 <main+0x70>
mov    %rcx,%rdx
or     $0x3f9,%rdx
mov    %edx,%esi
and    $0xff9,%esi
mov    %edx,(%rbx,%rsi,4)
mov    %rcx,%rdx
or     $0x3fa,%rdx
mov    %edx,%esi
and    $0xffa,%esi
mov    %edx,(%rbx,%rsi,4)
mov    %rcx,%rdx
or     $0x3fb,%rdx
mov    %edx,%esi
and    $0xffb,%esi
mov    %edx,(%rbx,%rsi,4)
mov    %rcx,%rdx
or     $0x3fc,%rdx
mov    %edx,%esi
and    $0xffc,%esi
mov    %edx,(%rbx,%rsi,4)
mov    %rcx,%rdx
or     $0x3fd,%rdx
mov    %edx,%esi
and    $0xffd,%esi
mov    %edx,(%rbx,%rsi,4)
mov    %rcx,%rdx
or     $0x3fe,%rdx
mov    %edx,%esi
and    $0xffe,%esi
mov    %edx,(%rbx,%rsi,4)
or     $0x3ff,%rcx
mov    %ecx,%edx
and    $0xfff,%edx
mov    %ecx,(%rbx,%rdx,4)
add    $0x1,%rax
cmp    $0x400,%rax
jne    1170 <main+0x50>
mov    0x4(%rbx),%edx
lea    0xd94(%rip),%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    0x8(%rbx),%edx
mov    %r14,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    0xc(%rbx),%edx
mov    %r14,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    0x10(%rbx),%edx
mov    %r14,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    0x14(%rbx),%edx
mov    %r14,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    0x18(%rbx),%edx
mov    %r14,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
mov    0x1c(%rbx),%edx
mov    %r14,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"tmps[%d]=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %1
store i32 1024, i32* %5
store i32 1024, i32* %6
%8 = load i32, i32* %5
%9 = load i32, i32* %6
%10 = mul i32 %8, %9
%11 = zext i32 %10 to i64
%12 = mul i64 %11, 4
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %7
store i32 1, i32* %2
br label %16
16: ; preds = %41, %0
%17 = load i32, i32* %2
%18 = load i32, i32* %5
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %44
20: ; preds = %16
store i32 1, i32* %3
br label %21
21: ; preds = %37, %20
%22 = load i32, i32* %3
%23 = load i32, i32* %6
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %40
25: ; preds = %21
%26 = load i32, i32* %2
%27 = load i32, i32* %6
%28 = mul i32 %26, %27
%29 = load i32, i32* %3
%30 = add i32 %28, %29
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = load i32*, i32** %7
%33 = load i32, i32* %4
%34 = urem i32 %33, 4096
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %32, i64 %35
store i32 %31, i32* %36
br label %37
37: ; preds = %25
%38 = load i32, i32* %3
%39 = add i32 %38, 1
store i32 %39, i32* %3
br label %21
40: ; preds = %21
br label %41
41: ; preds = %40
%42 = load i32, i32* %2
%43 = add i32 %42, 1
store i32 %43, i32* %2
br label %16
44: ; preds = %16
store i32 1, i32* %2
br label %45
45: ; preds = %56, %44
%46 = load i32, i32* %2
%47 = icmp ult i32 %46, 8
br i1 %47, label %48, label %59
48: ; preds = %45
%49 = load i32, i32* %2
%50 = load i32*, i32** %7
%51 = load i32, i32* %2
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds i32, i32* %50, i64 %52
%54 = load i32, i32* %53
%55 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %49, i32 %54)
br label %56
56: ; preds = %48
%57 = load i32, i32* %2
%58 = add i32 %57, 1
store i32 %58, i32* %2
br label %45
59: ; preds = %45
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"tmps[%d]=%d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4194304)
%2 = inttoptr i64 %1 to i32*
br label %3
3: ; preds = %0, %30
%4 = phi i64 [ 1, %0 ], [ %59, %30 ]
%5 = shl i64 %4, 10
%6 = insertelement <4 x i64> poison, i64 %5, i64 0
%7 = shufflevector <4 x i64> %6, <4 x i64> poison, <4 x i32> zeroinitializer
%8 = insertelement <4 x i64> poison, i64 %5, i64 0
%9 = shufflevector <4 x i64> %8, <4 x i64> poison, <4 x i32> zeroinitializer
br label %10
10: ; preds = %10, %3
%11 = phi i64 [ 0, %3 ], [ %28, %10 ]
%12 = insertelement <4 x i64> poison, i64 %11, i64 0
%13 = shufflevector <4 x i64> %12, <4 x i64> poison, <4 x i32> zeroinitializer
%14 = or <4 x i64> %13, <i64 1, i64 2, i64 3, i64 4>
%15 = or <4 x i64> %13, <i64 5, i64 6, i64 7, i64 poison>
%16 = add <4 x i64> %13, <i64 poison, i64 poison, i64 poison, i64 8>
%17 = shufflevector <4 x i64> %15, <4 x i64> %16, <4 x i32> <i32 0, i32 1, i32 2, i32 7>
%18 = add nuw nsw <4 x i64> %14, %9
%19 = add nuw nsw <4 x i64> %17, %7
%20 = extractelement <4 x i64> %18, i64 0
%21 = and i64 %20, 4089
%22 = getelementptr inbounds i32, i32* %2, i64 %21
%23 = trunc <4 x i64> %18 to <4 x i32>
%24 = trunc <4 x i64> %19 to <4 x i32>
%25 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> %23, <4 x i32>* %25
%26 = getelementptr inbounds i32, i32* %22, i64 4
%27 = bitcast i32* %26 to <4 x i32>*
store <4 x i32> %24, <4 x i32>* %27
%28 = add nuw i64 %11, 8
%29 = icmp eq i64 %28, 1016
br i1 %29, label %30, label %10
30: ; preds = %10
%31 = or i64 %5, 1017
%32 = and i64 %31, 4089
%33 = getelementptr inbounds i32, i32* %2, i64 %32
%34 = trunc i64 %31 to i32
store i32 %34, i32* %33
%35 = or i64 %5, 1018
%36 = and i64 %35, 4090
%37 = getelementptr inbounds i32, i32* %2, i64 %36
%38 = trunc i64 %35 to i32
store i32 %38, i32* %37
%39 = or i64 %5, 1019
%40 = and i64 %39, 4091
%41 = getelementptr inbounds i32, i32* %2, i64 %40
%42 = trunc i64 %39 to i32
store i32 %42, i32* %41
%43 = or i64 %5, 1020
%44 = and i64 %43, 4092
%45 = getelementptr inbounds i32, i32* %2, i64 %44
%46 = trunc i64 %43 to i32
store i32 %46, i32* %45
%47 = or i64 %5, 1021
%48 = and i64 %47, 4093
%49 = getelementptr inbounds i32, i32* %2, i64 %48
%50 = trunc i64 %47 to i32
store i32 %50, i32* %49
%51 = or i64 %5, 1022
%52 = and i64 %51, 4094
%53 = getelementptr inbounds i32, i32* %2, i64 %52
%54 = trunc i64 %51 to i32
store i32 %54, i32* %53
%55 = or i64 %5, 1023
%56 = and i64 %55, 4095
%57 = getelementptr inbounds i32, i32* %2, i64 %56
%58 = trunc i64 %55 to i32
store i32 %58, i32* %57
%59 = add nuw nsw i64 %4, 1
%60 = icmp eq i64 %59, 1024
br i1 %60, label %61, label %3
61: ; preds = %30
%62 = getelementptr inbounds i32, i32* %2, i64 1
%63 = load i32, i32* %62
%64 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 1, i32 %63)
%65 = getelementptr inbounds i32, i32* %2, i64 2
%66 = load i32, i32* %65
%67 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 2, i32 %66)
%68 = getelementptr inbounds i32, i32* %2, i64 3
%69 = load i32, i32* %68
%70 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 3, i32 %69)
%71 = getelementptr inbounds i32, i32* %2, i64 4
%72 = load i32, i32* %71
%73 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 4, i32 %72)
%74 = getelementptr inbounds i32, i32* %2, i64 5
%75 = load i32, i32* %74
%76 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 5, i32 %75)
%77 = getelementptr inbounds i32, i32* %2, i64 6
%78 = load i32, i32* %77
%79 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 6, i32 %78)
%80 = getelementptr inbounds i32, i32* %2, i64 7
%81 = load i32, i32* %80
%82 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 7, i32 %81)
ret i32 0
}