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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x400,-0x8(%rbp)
movl   $0x200,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x20,%esi
mov    $0x1800,%edx
call   1070 <posix_memalign@plt>
lea    -0x20(%rbp),%rdi
mov    $0x20,%esi
mov    $0x1800,%edx
call   1070 <posix_memalign@plt>
movl   $0x200,-0x24(%rbp)
cmpl   $0x600,-0x24(%rbp)
jge    11d2 <main+0x82>
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0xffffffff,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119a <main+0x4a>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x200,%ecx
mov    %ecx,%edx
call   1040 <store_kernel@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x400,%edx
mov    $0x200,%ecx
call   1040 <store_kernel@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x400,%edx
mov    $0x200,%ecx
call   1060 <test_stores@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x28(%rbp)
je     1259 <main+0x109>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1277 <main+0x127>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
mov    $0x20,%esi
mov    $0x1800,%edx
call   1070 <posix_memalign@plt>
mov    %rsp,%rdi
mov    $0x20,%esi
mov    $0x1800,%edx
call   1070 <posix_memalign@plt>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
lea    0x800(%rdi),%rax
lea    0x1800(%rsi),%rcx
cmp    %rcx,%rax
jae    11f8 <main+0xa8>
lea    0x1800(%rdi),%rax
lea    0x800(%rsi),%rcx
cmp    %rax,%rcx
jae    11f8 <main+0xa8>
mov    $0x200,%eax
nop
mov    %eax,(%rdi,%rax,4)
movl   $0xffffffff,(%rsi,%rax,4)
lea    0x1(%rax),%ecx
mov    %ecx,0x4(%rdi,%rax,4)
movl   $0xffffffff,0x4(%rsi,%rax,4)
ff
lea    0x2(%rax),%ecx
mov    %ecx,0x8(%rdi,%rax,4)
movl   $0xffffffff,0x8(%rsi,%rax,4)
ff
lea    0x3(%rax),%ecx
mov    %ecx,0xc(%rdi,%rax,4)
movl   $0xffffffff,0xc(%rsi,%rax,4)
ff
add    $0x4,%rax
cmp    $0x600,%rax
jne    11b0 <main+0x60>
jmp    12a0 <main+0x150>
movdqa 0xe00(%rip),%xmm0
xor    %eax,%eax
movdqa 0xe06(%rip),%xmm1
pcmpeqd %xmm2,%xmm2
movdqa 0xe0a(%rip),%xmm3
movdqa 0xe12(%rip),%xmm4
movdqa 0xe1a(%rip),%xmm5
cs nopw 0x0(%rax,%rax,1)
movdqa %xmm0,%xmm6
paddd  %xmm1,%xmm6
movdqu %xmm0,0x800(%rdi,%rax,4)
movdqu %xmm6,0x810(%rdi,%rax,4)
movdqu %xmm2,0x800(%rsi,%rax,4)
movdqu %xmm2,0x810(%rsi,%rax,4)
movdqa %xmm0,%xmm6
paddd  %xmm3,%xmm6
movdqa %xmm0,%xmm7
paddd  %xmm4,%xmm7
movdqu %xmm6,0x820(%rdi,%rax,4)
movdqu %xmm7,0x830(%rdi,%rax,4)
movdqu %xmm2,0x820(%rsi,%rax,4)
movdqu %xmm2,0x830(%rsi,%rax,4)
add    $0x10,%rax
paddd  %xmm5,%xmm0
cmp    $0x400,%rax
jne    1230 <main+0xe0>
mov    $0x200,%edx
mov    $0x200,%ecx
call   1040 <store_kernel@plt>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
mov    $0x400,%edx
mov    $0x200,%ecx
call   1040 <store_kernel@plt>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rsi
mov    $0x400,%edx
mov    $0x200,%ecx
call   1060 <test_stores@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
test   %ebx,%ebx
je     1318 <main+0x1c8>
lea    0xd48(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1328 <main+0x1d8>
lea    0xd4e(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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