#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 **alloc_2d_array(int, int);
void next_state(bool ***arr, int xc, int yc, int neighbors,
                int (*f)(bool **, int, int, int, int)) {
  int a;
  bool **tmp = alloc_2d_array(xc, yc);
  for (int i = 0; i < xc; i++) {
    for (int j = 0; j < yc; j++) {
      if ((a = f(*arr, i, j, xc, yc)) > neighbors) {
        tmp[i][j] = true;
      } else if (a < neighbors) {
        tmp[i][j] = false;
      }
    }
  }
  *arr = tmp;
}


x86 assembly (clang, -O0):
<next_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <alloc_2d_array@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ee <next_state+0xde>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11db <next_state+0xcb>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
call   *%rax
mov    %eax,-0x24(%rbp)
cmp    -0x14(%rbp),%eax
jle    11a0 <next_state+0x90>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    11c8 <next_state+0xb8>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c3 <next_state+0xb3>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x38(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    11c8 <next_state+0xb8>
jmp    11cd <next_state+0xbd>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1152 <next_state+0x42>
jmp    11e0 <next_state+0xd0>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    113f <next_state+0x2f>
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_state>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x20(%rsp)
mov    %ecx,%ebp
mov    %esi,%ebx
mov    %rdi,%r12
mov    %esi,%edi
mov    %edx,0xc(%rsp)
mov    %edx,%esi
call   1030 <alloc_2d_array@plt>
mov    %rax,0x10(%rsp)
test   %ebx,%ebx
jle    11ba <next_state+0xaa>
mov    0xc(%rsp),%r14d
mov    %ebx,%eax
mov    %rax,0x18(%rsp)
xor    %r13d,%r13d
jmp    116b <next_state+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    0x18(%rsp),%r13
je     11ba <next_state+0xaa>
cmpl   $0x0,0xc(%rsp)
jle    1160 <next_state+0x50>
xor    %r15d,%r15d
jmp    1196 <next_state+0x86>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    (%rax,%r13,8),%rax
mov    %ecx,(%rax,%r15,4)
add    $0x1,%r15
cmp    %r15,%r14
je     1160 <next_state+0x50>
mov    (%r12),%rdi
mov    %r13d,%esi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %r14d,%r8d
call   *0x20(%rsp)
mov    $0x1,%ecx
cmp    %ebp,%eax
jg     1180 <next_state+0x70>
xor    %ecx,%ecx
cmp    %ebp,%eax
jl     1180 <next_state+0x70>
jmp    118d <next_state+0x7d>
mov    0x10(%rsp),%rax
mov    %rax,(%r12)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @next_state(i32*** %0, i32 %1, i32 %2, i32 %3, i32 (i32**, i32, i32, i32, i32)* %4) {
%6 = alloca i32***
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32 (i32**, i32, i32, i32, i32)*
%11 = alloca i32
%12 = alloca i32**
%13 = alloca i32
%14 = alloca i32
store i32*** %0, i32**** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 (i32**, i32, i32, i32, i32)* %4, i32 (i32**, i32, i32, i32, i32)** %10
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = call i32** @alloc_2d_array(i32 %15, i32 %16)
store i32** %17, i32*** %12
store i32 0, i32* %13
br label %18
18: ; preds = %66, %5
%19 = load i32, i32* %13
%20 = load i32, i32* %7
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %69
22: ; preds = %18
store i32 0, i32* %14
br label %23
23: ; preds = %62, %22
%24 = load i32, i32* %14
%25 = load i32, i32* %8
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %65
27: ; preds = %23
%28 = load i32 (i32**, i32, i32, i32, i32)*, i32 (i32**, i32, i32, i32, i32)** %10
%29 = load i32***, i32**** %6
%30 = load i32**, i32*** %29
%31 = load i32, i32* %13
%32 = load i32, i32* %14
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = call i32 %28(i32** %30, i32 %31, i32 %32, i32 %33, i32 %34)
store i32 %35, i32* %11
%36 = load i32, i32* %9
%37 = icmp sgt i32 %35, %36
br i1 %37, label %38, label %47
38: ; preds = %27
%39 = load i32**, i32*** %12
%40 = load i32, i32* %13
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32*, i32** %39, i64 %41
%43 = load i32*, i32** %42
%44 = load i32, i32* %14
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
store i32 1, i32* %46
br label %61
47: ; preds = %27
%48 = load i32, i32* %11
%49 = load i32, i32* %9
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %60
51: ; preds = %47
%52 = load i32**, i32*** %12
%53 = load i32, i32* %13
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32*, i32** %52, i64 %54
%56 = load i32*, i32** %55
%57 = load i32, i32* %14
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
store i32 0, i32* %59
br label %60
60: ; preds = %51, %47
br label %61
61: ; preds = %60, %38
br label %62
62: ; preds = %61
%63 = load i32, i32* %14
%64 = add nsw i32 %63, 1
store i32 %64, i32* %14
br label %23
65: ; preds = %23
br label %66
66: ; preds = %65
%67 = load i32, i32* %13
%68 = add nsw i32 %67, 1
store i32 %68, i32* %13
br label %18
69: ; preds = %18
%70 = load i32**, i32*** %12
%71 = load i32***, i32**** %6
store i32** %70, i32*** %71
ret void
}

LLVM IR (-O2):
define void @next_state(i32*** nocapture %0, i32 %1, i32 %2, i32 %3, i32 (i32**, i32, i32, i32, i32)* nocapture %4) {
%6 = tail call i32** @alloc_2d_array(i32 %1, i32 %2)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = icmp sgt i32 %2, 0
%10 = zext i32 %1 to i64
%11 = zext i32 %2 to i64
br label %12
12: ; preds = %8, %18
%13 = phi i64 [ 0, %8 ], [ %19, %18 ]
br i1 %9, label %14, label %18
14: ; preds = %12
%15 = getelementptr inbounds i32*, i32** %6, i64 %13
%16 = trunc i64 %13 to i32
br label %21
17: ; preds = %18, %5
store i32** %6, i32*** %0
ret void
18: ; preds = %33, %12
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %10
br i1 %20, label %17, label %12
21: ; preds = %14, %33
%22 = phi i64 [ 0, %14 ], [ %34, %33 ]
%23 = load i32**, i32*** %0
%24 = trunc i64 %22 to i32
%25 = tail call i32 %4(i32** %23, i32 %16, i32 %24, i32 %1, i32 %2)
%26 = icmp sgt i32 %25, %3
br i1 %26, label %29, label %27
27: ; preds = %21
%28 = icmp slt i32 %25, %3
br i1 %28, label %29, label %33
29: ; preds = %27, %21
%30 = phi i32 [ 1, %21 ], [ 0, %27 ]
%31 = load i32*, i32** %15
%32 = getelementptr inbounds i32, i32* %31, i64 %22
store i32 %30, i32* %32
br label %33
33: ; preds = %29, %27
%34 = add nuw nsw i64 %22, 1
%35 = icmp eq i64 %34, %11
br i1 %35, label %18, label %21
}