#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 count_neighbors(int **, int, int);
void iter_cell(int board[20][40], int next[20][40], int x, int y) {
  int current_state = board[x][y];
  int n_neighbors = count_neighbors(board, x, y);
  if (current_state == 1 && n_neighbors < 2)
    next[x][y] = 0;
  else if (current_state == 1 && n_neighbors > 3)
    next[x][y] = 0;
  else if (current_state == 1 && (n_neighbors == 2 || n_neighbors == 3))
    next[x][y] = 1;
  else if (current_state == 0 && n_neighbors == 3)
    next[x][y] = 1;
  else
    next[x][y] = 0;
}


x86 assembly (clang, -O0):
<iter_cell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <count_neighbors@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    118a <iter_cell+0x7a>
cmpl   $0x2,-0x20(%rbp)
jge    118a <iter_cell+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    1262 <iter_cell+0x152>
cmpl   $0x1,-0x1c(%rbp)
jne    11c0 <iter_cell+0xb0>
cmpl   $0x3,-0x20(%rbp)
jle    11c0 <iter_cell+0xb0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    125d <iter_cell+0x14d>
cmpl   $0x1,-0x1c(%rbp)
jne    1200 <iter_cell+0xf0>
cmpl   $0x2,-0x20(%rbp)
je     11de <iter_cell+0xce>
cmpl   $0x3,-0x20(%rbp)
jne    1200 <iter_cell+0xf0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    1258 <iter_cell+0x148>
cmpl   $0x0,-0x1c(%rbp)
jne    1236 <iter_cell+0x126>
cmpl   $0x3,-0x20(%rbp)
jne    1236 <iter_cell+0x126>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    1253 <iter_cell+0x143>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
imul   $0xa0,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    1258 <iter_cell+0x148>
jmp    125d <iter_cell+0x14d>
jmp    1262 <iter_cell+0x152>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iter_cell>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
movslq %edx,%rsi
movslq %ecx,%r15
lea    (%rsi,%rsi,4),%rbx
shl    $0x5,%rbx
lea    (%rdi,%rbx,1),%rax
mov    (%rax,%r15,4),%ebp
mov    %r15d,%edx
call   1030 <count_neighbors@plt>
cmp    $0x1,%ebp
jne    1142 <iter_cell+0x32>
cmp    $0x1,%eax
jle    114c <iter_cell+0x3c>
cmp    $0x1,%ebp
jne    1162 <iter_cell+0x52>
cmp    $0x4,%eax
jl     1162 <iter_cell+0x52>
add    %rbx,%r14
movl   $0x0,(%r14,%r15,4)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x1,%ebp
jne    117e <iter_cell+0x6e>
mov    %eax,%ecx
and    $0xfffffffe,%ecx
cmp    $0x2,%ecx
jne    117e <iter_cell+0x6e>
add    %rbx,%r14
movl   $0x1,(%r14,%r15,4)
jmp    1157 <iter_cell+0x47>
add    %rbx,%r14
lea    (%r14,%r15,4),%rcx
test   %ebp,%ebp
jne    1196 <iter_cell+0x86>
cmp    $0x3,%eax
jne    1196 <iter_cell+0x86>
movl   $0x1,(%rcx)
jmp    1157 <iter_cell+0x47>
movl   $0x0,(%rcx)
jmp    1157 <iter_cell+0x47>

LLVM IR (-O0):
define void @iter_cell([40 x i32]* %0, [40 x i32]* %1, i32 %2, i32 %3) {
%5 = alloca [40 x i32]*
%6 = alloca [40 x i32]*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store [40 x i32]* %0, [40 x i32]** %5
store [40 x i32]* %1, [40 x i32]** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load [40 x i32]*, [40 x i32]** %5
%12 = load i32, i32* %7
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [40 x i32], [40 x i32]* %11, i64 %13
%15 = load i32, i32* %8
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [40 x i32], [40 x i32]* %14, i64 0, i64 %16
%18 = load i32, i32* %17
store i32 %18, i32* %9
%19 = load [40 x i32]*, [40 x i32]** %5
%20 = bitcast [40 x i32]* %19 to i32**
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = call i32 @count_neighbors(i32** %20, i32 %21, i32 %22)
store i32 %23, i32* %10
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %37
26: ; preds = %4
%27 = load i32, i32* %10
%28 = icmp slt i32 %27, 2
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = load [40 x i32]*, [40 x i32]** %6
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [40 x i32], [40 x i32]* %30, i64 %32
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [40 x i32], [40 x i32]* %33, i64 0, i64 %35
store i32 0, i32* %36
br label %93
37: ; preds = %26, %4
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %51
40: ; preds = %37
%41 = load i32, i32* %10
%42 = icmp sgt i32 %41, 3
br i1 %42, label %43, label %51
43: ; preds = %40
%44 = load [40 x i32]*, [40 x i32]** %6
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [40 x i32], [40 x i32]* %44, i64 %46
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [40 x i32], [40 x i32]* %47, i64 0, i64 %49
store i32 0, i32* %50
br label %92
51: ; preds = %40, %37
%52 = load i32, i32* %9
%53 = icmp eq i32 %52, 1
br i1 %53, label %54, label %68
54: ; preds = %51
%55 = load i32, i32* %10
%56 = icmp eq i32 %55, 2
br i1 %56, label %60, label %57
57: ; preds = %54
%58 = load i32, i32* %10
%59 = icmp eq i32 %58, 3
br i1 %59, label %60, label %68
60: ; preds = %57, %54
%61 = load [40 x i32]*, [40 x i32]** %6
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [40 x i32], [40 x i32]* %61, i64 %63
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [40 x i32], [40 x i32]* %64, i64 0, i64 %66
store i32 1, i32* %67
br label %91
68: ; preds = %57, %51
%69 = load i32, i32* %9
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %82
71: ; preds = %68
%72 = load i32, i32* %10
%73 = icmp eq i32 %72, 3
br i1 %73, label %74, label %82
74: ; preds = %71
%75 = load [40 x i32]*, [40 x i32]** %6
%76 = load i32, i32* %7
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [40 x i32], [40 x i32]* %75, i64 %77
%79 = load i32, i32* %8
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [40 x i32], [40 x i32]* %78, i64 0, i64 %80
store i32 1, i32* %81
br label %90
82: ; preds = %71, %68
%83 = load [40 x i32]*, [40 x i32]** %6
%84 = load i32, i32* %7
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [40 x i32], [40 x i32]* %83, i64 %85
%87 = load i32, i32* %8
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [40 x i32], [40 x i32]* %86, i64 0, i64 %88
store i32 0, i32* %89
br label %90
90: ; preds = %82, %74
br label %91
91: ; preds = %90, %60
br label %92
92: ; preds = %91, %43
br label %93
93: ; preds = %92, %29
ret void
}

LLVM IR (-O2):
define void @iter_cell([40 x i32]* %0, [40 x i32]* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = sext i32 %2 to i64
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [40 x i32], [40 x i32]* %0, i64 %5, i64 %6
%8 = load i32, i32* %7
%9 = bitcast [40 x i32]* %0 to i32**
%10 = tail call i32 @count_neighbors(i32** %9, i32 %2, i32 %3)
%11 = icmp eq i32 %8, 1
%12 = icmp slt i32 %10, 2
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = getelementptr inbounds [40 x i32], [40 x i32]* %1, i64 %5, i64 %6
store i32 0, i32* %15
br label %34
16: ; preds = %4
%17 = icmp sgt i32 %10, 3
%18 = select i1 %11, i1 %17, i1 false
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = getelementptr inbounds [40 x i32], [40 x i32]* %1, i64 %5, i64 %6
store i32 0, i32* %20
br label %34
21: ; preds = %16
%22 = and i32 %10, -2
%23 = icmp eq i32 %22, 2
%24 = select i1 %11, i1 %23, i1 false
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = getelementptr inbounds [40 x i32], [40 x i32]* %1, i64 %5, i64 %6
store i32 1, i32* %26
br label %34
27: ; preds = %21
%28 = icmp eq i32 %8, 0
%29 = icmp eq i32 %10, 3
%30 = select i1 %28, i1 %29, i1 false
%31 = getelementptr inbounds [40 x i32], [40 x i32]* %1, i64 %5, i64 %6
br i1 %30, label %32, label %33
32: ; preds = %27
store i32 1, i32* %31
br label %34
33: ; preds = %27
store i32 0, i32* %31
br label %34
34: ; preds = %19, %32, %33, %25, %14
ret void
}