#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*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ store_kernel(int *, int *, int const);
int test_stores(int *, int *, int const);
int main() {
  const int num_vals = 1024;
  int *store_vals = (int *)malloc(sizeof(int) * num_vals);
  int *store_loc = (int *)malloc(sizeof(int) * num_vals);
  for (int i = 0; i < num_vals; i++) {
    store_vals[i] = i;
    store_loc[i] = -1;
  }
  store_kernel(store_vals, store_loc, num_vals);
  int num_failures = test_stores(store_vals, store_loc, num_vals);
  if (num_failures != 0) {
    fprintf(stdout, "Test failed with %d errors.", num_failures);
    return -1;
  }
  fprintf(stdout, "Test passed!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x400,-0x8(%rbp)
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x400,-0x1c(%rbp)
jge    11b1 <main+0x71>
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1179 <main+0x39>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   1030 <store_kernel@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   1050 <test_stores@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1208 <main+0xc8>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xe0b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1226 <main+0xe6>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x1000,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
add    $0x1000,%rax
cmp    %rax,%r14
jae    11cc <main+0x8c>
mov    %r14,%rax
add    $0x1000,%rax
cmp    %rax,%rbx
jae    11cc <main+0x8c>
xor    %eax,%eax
nopl   0x0(%rax)
mov    %eax,(%r14,%rax,4)
movl   $0xffffffff,(%rbx,%rax,4)
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%r14,%rax,4)
movl   $0xffffffff,0x4(%rbx,%rax,4)
ff
lea    0x2(%rax),%ecx
mov    %ecx,0x8(%r14,%rax,4)
movl   $0xffffffff,0x8(%rbx,%rax,4)
ff
lea    0x3(%rax),%ecx
mov    %ecx,0xc(%r14,%rax,4)
movl   $0xffffffff,0xc(%rbx,%rax,4)
ff
add    $0x4,%rax
cmp    $0x400,%rax
jne    1180 <main+0x40>
jmp    125a <main+0x11a>
movdqa 0xe2c(%rip),%xmm0
xor    %eax,%eax
movdqa 0xe32(%rip),%xmm1
pcmpeqd %xmm2,%xmm2
movdqa 0xe36(%rip),%xmm3
movdqa 0xe3e(%rip),%xmm4
movdqa 0xe46(%rip),%xmm5
nopw   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm6
paddd  %xmm1,%xmm6
movdqu %xmm0,(%r14,%rax,4)
movdqu %xmm6,0x10(%r14,%rax,4)
movdqu %xmm2,(%rbx,%rax,4)
movdqu %xmm2,0x10(%rbx,%rax,4)
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
movdqa %xmm0,%xmm7
paddd  %xmm4,%xmm7
movdqu %xmm6,0x20(%r14,%rax,4)
movdqu %xmm7,0x30(%r14,%rax,4)
movdqu %xmm2,0x20(%rbx,%rax,4)
movdqu %xmm2,0x30(%rbx,%rax,4)
add    $0x10,%rax
paddd  %xmm5,%xmm0
cmp    $0x400,%rax
jne    1200 <main+0xc0>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <store_kernel@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <test_stores@plt>
mov    0x2d5f(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
je     129e <main+0x15e>
lea    0xdc2(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    12ae <main+0x16e>
lea    0xdc7(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [28 x i8] c"Test failed with %d errors.\00"
@.str.1 = [14 x i8] c"Test passed!\0A\00"
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 1024, i32* %2
%7 = call i64 @malloc(i32 4096)
%8 = inttoptr i64 %7 to i32*
store i32* %8, i32** %3
%9 = call i64 @malloc(i32 4096)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %4
store i32 0, i32* %5
br label %11
11: ; preds = %24, %0
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 1024
br i1 %13, label %14, label %27
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i32*, i32** %3
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
store i32 %15, i32* %19
%20 = load i32*, i32** %4
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
store i32 -1, i32* %23
br label %24
24: ; preds = %14
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %11
27: ; preds = %11
%28 = load i32*, i32** %3
%29 = load i32*, i32** %4
%30 = call i32 @store_kernel(i32* %28, i32* %29, i32 1024)
%31 = load i32*, i32** %3
%32 = load i32*, i32** %4
%33 = call i32 @test_stores(i32* %31, i32* %32, i32 1024)
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %27
%37 = load i32, i32* @stdout
%38 = load i32, i32* %6
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %38)
store i32 -1, i32* %1
br label %43
40: ; preds = %27
%41 = load i32, i32* @stdout
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %43
43: ; preds = %40, %36
%44 = load i32, i32* %1
ret i32 %44
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [28 x i8] c"Test failed with %d errors.\00"
@.str.1 = [14 x i8] c"Test passed!\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4096)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i64 @malloc(i32 4096)
%4 = inttoptr i64 %3 to i32*
%5 = inttoptr i64 %3 to i8*
%6 = inttoptr i64 %1 to i8*
%7 = getelementptr i32, i32* %2, i64 1024
%8 = bitcast i32* %7 to i8*
%9 = getelementptr i32, i32* %4, i64 1024
%10 = bitcast i32* %9 to i8*
%11 = icmp ult i8* %6, %10
%12 = icmp ult i8* %5, %8
%13 = and i1 %11, %12
br i1 %13, label %45, label %14
14: ; preds = %0, %14
%15 = phi i64 [ %37, %14 ], [ 0, %0 ]
%16 = phi <4 x i32> [ %38, %14 ], [ <i32 0, i32 1, i32 2, i32 3>, %0 ]
%17 = add <4 x i32> %16, <i32 4, i32 4, i32 4, i32 4>
%18 = getelementptr inbounds i32, i32* %2, i64 %15
%19 = bitcast i32* %18 to <4 x i32>*
store <4 x i32> %16, <4 x i32>* %19
%20 = getelementptr inbounds i32, i32* %18, i64 4
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> %17, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %4, i64 %15
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32>* %23
%24 = getelementptr inbounds i32, i32* %22, i64 4
%25 = bitcast i32* %24 to <4 x i32>*
store <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32>* %25
%26 = or i64 %15, 8
%27 = add <4 x i32> %16, <i32 8, i32 8, i32 8, i32 8>
%28 = add <4 x i32> %16, <i32 12, i32 12, i32 12, i32 12>
%29 = getelementptr inbounds i32, i32* %2, i64 %26
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> %27, <4 x i32>* %30
%31 = getelementptr inbounds i32, i32* %29, i64 4
%32 = bitcast i32* %31 to <4 x i32>*
store <4 x i32> %28, <4 x i32>* %32
%33 = getelementptr inbounds i32, i32* %4, i64 %26
%34 = bitcast i32* %33 to <4 x i32>*
store <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32>* %34
%35 = getelementptr inbounds i32, i32* %33, i64 4
%36 = bitcast i32* %35 to <4 x i32>*
store <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, <4 x i32>* %36
%37 = add nuw nsw i64 %15, 16
%38 = add <4 x i32> %16, <i32 16, i32 16, i32 16, i32 16>
%39 = icmp eq i64 %37, 1024
br i1 %39, label %40, label %14
40: ; preds = %14, %45
%41 = tail call i32 @store_kernel(i32* %2, i32* %4, i32 1024)
%42 = tail call i32 @test_stores(i32* %2, i32* %4, i32 1024)
%43 = icmp eq i32 %42, 0
%44 = load i32, i32* @stdout
br i1 %43, label %66, label %64
45: ; preds = %0, %45
%46 = phi i64 [ %62, %45 ], [ 0, %0 ]
%47 = getelementptr inbounds i32, i32* %2, i64 %46
%48 = trunc i64 %46 to i32
store i32 %48, i32* %47
%49 = getelementptr inbounds i32, i32* %4, i64 %46
store i32 -1, i32* %49
%50 = or i64 %46, 1
%51 = getelementptr inbounds i32, i32* %2, i64 %50
%52 = trunc i64 %50 to i32
store i32 %52, i32* %51
%53 = getelementptr inbounds i32, i32* %4, i64 %50
store i32 -1, i32* %53
%54 = or i64 %46, 2
%55 = getelementptr inbounds i32, i32* %2, i64 %54
%56 = trunc i64 %54 to i32
store i32 %56, i32* %55
%57 = getelementptr inbounds i32, i32* %4, i64 %54
store i32 -1, i32* %57
%58 = or i64 %46, 3
%59 = getelementptr inbounds i32, i32* %2, i64 %58
%60 = trunc i64 %58 to i32
store i32 %60, i32* %59
%61 = getelementptr inbounds i32, i32* %4, i64 %58
store i32 -1, i32* %61
%62 = add nuw nsw i64 %46, 4
%63 = icmp eq i64 %62, 1024
br i1 %63, label %40, label %45
64: ; preds = %40
%65 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %42)
br label %68
66: ; preds = %40
%67 = tail call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %68
68: ; preds = %66, %64
%69 = phi i32 [ -1, %64 ], [ 0, %66 ]
ret i32 %69
}