#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*/ cls();
int **createArray();
int /*<<< orphan*/ cudaMalloc(void **, int);
int /*<<< orphan*/ cudaSetDevice(int /*<<< orphan*/);
int /*<<< orphan*/ destroyArray(int **);
int /*<<< orphan*/ evolve(int **, int **, int **);
int /*<<< orphan*/ flipField(int **, int **, int, int);
int /*<<< orphan*/ printArray(int **);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  cudaSetDevice(0);
  int **arr = createArray();
  int **next = createArray();
  int **nbrs = createArray();
  int *devArr, *devNext, *devNbrs;
  cudaMalloc((void **)&devArr, sizeof(int) * 32 * 10);
  cudaMalloc((void **)&devNext, sizeof(int) * 32 * 10);
  cudaMalloc((void **)&devNbrs, sizeof(int) * 32 * 10);
  int i;
  flipField(arr, nbrs, 2, 2);
  flipField(arr, nbrs, 3, 3);
  flipField(arr, nbrs, 1, 4);
  flipField(arr, nbrs, 2, 4);
  flipField(arr, nbrs, 3, 4);
  for (i = 0; i < 20; i++) {
    cls();
    printArray(arr);
    evolve(arr, next, nbrs);
    usleep(100000);
  }
  destroyArray(arr);
  destroyArray(next);
  destroyArray(nbrs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
call   1080 <cudaSetDevice@plt>
mov    $0x0,%al
call   1030 <createArray@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <createArray@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <createArray@plt>
mov    %rax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x500,%esi
call   1050 <cudaMalloc@plt>
lea    -0x38(%rbp),%rdi
mov    $0x500,%esi
call   1050 <cudaMalloc@plt>
lea    -0x40(%rbp),%rdi
mov    $0x500,%esi
call   1050 <cudaMalloc@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x2,%ecx
mov    %ecx,%edx
call   10a0 <flipField@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x3,%ecx
mov    %ecx,%edx
call   10a0 <flipField@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
mov    $0x4,%ecx
call   10a0 <flipField@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x2,%edx
mov    $0x4,%ecx
call   10a0 <flipField@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x3,%edx
mov    $0x4,%ecx
call   10a0 <flipField@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0x14,-0x44(%rbp)
jge    12af <main+0x11f>
mov    $0x0,%al
call   1060 <cls@plt>
mov    -0x18(%rbp),%rdi
call   1090 <printArray@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1070 <evolve@plt>
mov    $0x186a0,%edi
call   10b0 <usleep@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    126c <main+0xdc>
mov    -0x18(%rbp),%rdi
call   1040 <destroyArray@plt>
mov    -0x20(%rbp),%rdi
call   1040 <destroyArray@plt>
mov    -0x28(%rbp),%rdi
call   1040 <destroyArray@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %edi,%edi
call   1080 <cudaSetDevice@plt>
xor    %eax,%eax
call   1030 <createArray@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <createArray@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <createArray@plt>
mov    %rax,%r15
lea    0x10(%rsp),%rdi
mov    $0x500,%esi
call   1050 <cudaMalloc@plt>
lea    0x8(%rsp),%rdi
mov    $0x500,%esi
call   1050 <cudaMalloc@plt>
mov    %rsp,%rdi
mov    $0x500,%esi
call   1050 <cudaMalloc@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
mov    $0x2,%ecx
call   10a0 <flipField@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
mov    $0x3,%ecx
call   10a0 <flipField@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    $0x4,%ecx
call   10a0 <flipField@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x2,%edx
mov    $0x4,%ecx
call   10a0 <flipField@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
mov    $0x4,%ecx
call   10a0 <flipField@plt>
mov    $0x14,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <cls@plt>
mov    %rbx,%rdi
call   1090 <printArray@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <evolve@plt>
mov    $0x186a0,%edi
call   10b0 <usleep@plt>
add    $0xffffffff,%ebp
jne    1260 <main+0xd0>
mov    %rbx,%rdi
call   1040 <destroyArray@plt>
mov    %r14,%rdi
call   1040 <destroyArray@plt>
mov    %r15,%rdi
call   1040 <destroyArray@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32**
%7 = alloca i32**
%8 = alloca i32**
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 @cudaSetDevice(i32 0)
%14 = call i32** (...) @createArray()
store i32** %14, i32*** %6
%15 = call i32** (...) @createArray()
store i32** %15, i32*** %7
%16 = call i32** (...) @createArray()
store i32** %16, i32*** %8
%17 = bitcast i32** %9 to i8**
%18 = call i32 @cudaMalloc(i8** %17, i32 1280)
%19 = bitcast i32** %10 to i8**
%20 = call i32 @cudaMalloc(i8** %19, i32 1280)
%21 = bitcast i32** %11 to i8**
%22 = call i32 @cudaMalloc(i8** %21, i32 1280)
%23 = load i32**, i32*** %6
%24 = load i32**, i32*** %8
%25 = call i32 @flipField(i32** %23, i32** %24, i32 2, i32 2)
%26 = load i32**, i32*** %6
%27 = load i32**, i32*** %8
%28 = call i32 @flipField(i32** %26, i32** %27, i32 3, i32 3)
%29 = load i32**, i32*** %6
%30 = load i32**, i32*** %8
%31 = call i32 @flipField(i32** %29, i32** %30, i32 1, i32 4)
%32 = load i32**, i32*** %6
%33 = load i32**, i32*** %8
%34 = call i32 @flipField(i32** %32, i32** %33, i32 2, i32 4)
%35 = load i32**, i32*** %6
%36 = load i32**, i32*** %8
%37 = call i32 @flipField(i32** %35, i32** %36, i32 3, i32 4)
store i32 0, i32* %12
br label %38
38: ; preds = %50, %2
%39 = load i32, i32* %12
%40 = icmp slt i32 %39, 20
br i1 %40, label %41, label %53
41: ; preds = %38
%42 = call i32 (...) @cls()
%43 = load i32**, i32*** %6
%44 = call i32 @printArray(i32** %43)
%45 = load i32**, i32*** %6
%46 = load i32**, i32*** %7
%47 = load i32**, i32*** %8
%48 = call i32 @evolve(i32** %45, i32** %46, i32** %47)
%49 = call i32 @usleep(i32 100000)
br label %50
50: ; preds = %41
%51 = load i32, i32* %12
%52 = add nsw i32 %51, 1
store i32 %52, i32* %12
br label %38
53: ; preds = %38
%54 = load i32**, i32*** %6
%55 = call i32 @destroyArray(i32** %54)
%56 = load i32**, i32*** %7
%57 = call i32 @destroyArray(i32** %56)
%58 = load i32**, i32*** %8
%59 = call i32 @destroyArray(i32** %58)
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = tail call i32 @cudaSetDevice(i32 0)
%7 = tail call i32** (...) @createArray()
%8 = tail call i32** (...) @createArray()
%9 = tail call i32** (...) @createArray()
%10 = bitcast i32** %3 to i8*
%11 = bitcast i32** %4 to i8*
%12 = bitcast i32** %5 to i8*
%13 = bitcast i32** %3 to i8**
%14 = call i32 @cudaMalloc(i8** %13, i32 1280)
%15 = bitcast i32** %4 to i8**
%16 = call i32 @cudaMalloc(i8** %15, i32 1280)
%17 = bitcast i32** %5 to i8**
%18 = call i32 @cudaMalloc(i8** %17, i32 1280)
%19 = call i32 @flipField(i32** %7, i32** %9, i32 2, i32 2)
%20 = call i32 @flipField(i32** %7, i32** %9, i32 3, i32 3)
%21 = call i32 @flipField(i32** %7, i32** %9, i32 1, i32 4)
%22 = call i32 @flipField(i32** %7, i32** %9, i32 2, i32 4)
%23 = call i32 @flipField(i32** %7, i32** %9, i32 3, i32 4)
br label %24
24: ; preds = %2, %24
%25 = phi i32 [ 0, %2 ], [ %30, %24 ]
%26 = call i32 (...) @cls()
%27 = call i32 @printArray(i32** %7)
%28 = call i32 @evolve(i32** %7, i32** %8, i32** %9)
%29 = call i32 @usleep(i32 100000)
%30 = add nuw nsw i32 %25, 1
%31 = icmp eq i32 %30, 20
br i1 %31, label %32, label %24
32: ; preds = %24
%33 = call i32 @destroyArray(i32** %7)
%34 = call i32 @destroyArray(i32** %8)
%35 = call i32 @destroyArray(i32** %9)
ret i32 0
}