#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 */
short **allocate_matrix(short **, int const, int const);
int /*<<< orphan*/ dead_or_alive(short **, short **, int const, int const,
                                 int const, int const);
int /*<<< orphan*/ enforce_boundary_conditions(short **, int const, int const,
                                               int const);
int /*<<< orphan*/ free_matrix(short **, int const, int const);
int /*<<< orphan*/ init_matrix(short **, int const, int const, int const, int);
int /*<<< orphan*/ print_matrix(short **, int const, int const);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ swap(void *, void *);
int main(int argc, char *argv[]) {
  const int verbose = 1;
  const int size_x = 1024;
  const int size_y = size_x;
  const int num_guard_cells = 1;
  short **matrix_old;
  short **matrix_new;
  int i, j;
  matrix_old = allocate_matrix(matrix_old, size_x, size_y);
  matrix_new = allocate_matrix(matrix_new, size_x, size_y);
  int seed = 0;
  init_matrix(matrix_old, size_x, size_y, num_guard_cells, seed);
  if (verbose) {
    printf("Printing initial matrix: \n");
    print_matrix(matrix_old, size_x, size_y);
  }
  dead_or_alive(matrix_old, matrix_new, size_x, size_y, num_guard_cells,
                verbose);
  enforce_boundary_conditions(matrix_new, size_x, size_y, num_guard_cells);
  swap((void *)&matrix_old, (void *)&matrix_new);
  if (verbose) {
    printf("Printing evolved matrix: \n");
    print_matrix(matrix_old, size_x, size_y);
  }
  free_matrix(matrix_old, size_x, size_y);
  free_matrix(matrix_new, size_x, size_y);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x400,-0x18(%rbp)
movl   $0x400,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x400,%edx
mov    %edx,%esi
call   1070 <allocate_matrix@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x400,%edx
mov    %edx,%esi
call   1070 <allocate_matrix@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%r8d
mov    $0x400,%edx
mov    $0x1,%ecx
mov    %edx,%esi
call   1080 <init_matrix@plt>
lea    0xdff(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x400,%edx
mov    %edx,%esi
call   1090 <print_matrix@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x400,%ecx
mov    $0x1,%r9d
mov    %ecx,%edx
mov    %r9d,%r8d
call   1060 <dead_or_alive@plt>
mov    -0x30(%rbp),%rdi
mov    $0x400,%edx
mov    $0x1,%ecx
mov    %edx,%esi
call   1030 <enforce_boundary_conditions@plt>
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10a0 <swap@plt>
lea    0xdbf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x400,%edx
mov    %edx,%esi
call   1090 <print_matrix@plt>
mov    -0x28(%rbp),%rdi
mov    $0x400,%edx
mov    %edx,%esi
call   1040 <free_matrix@plt>
mov    -0x30(%rbp),%rdi
mov    $0x400,%edx
mov    %edx,%esi
call   1040 <free_matrix@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x400,%esi
mov    $0x400,%edx
call   1070 <allocate_matrix@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
mov    $0x400,%esi
mov    $0x400,%edx
call   1070 <allocate_matrix@plt>
mov    %rax,%r14
mov    %rax,0x10(%rsp)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    $0x400,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   1080 <init_matrix@plt>
lea    0xe2a(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    $0x400,%edx
call   1090 <print_matrix@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x400,%edx
mov    $0x400,%ecx
mov    $0x1,%r8d
mov    $0x1,%r9d
call   1060 <dead_or_alive@plt>
mov    %r14,%rdi
mov    $0x400,%esi
mov    $0x400,%edx
mov    $0x1,%ecx
call   1030 <enforce_boundary_conditions@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <swap@plt>
lea    0xddf(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rdi
mov    $0x400,%esi
mov    $0x400,%edx
call   1090 <print_matrix@plt>
mov    0x8(%rsp),%rdi
mov    $0x400,%esi
mov    $0x400,%edx
call   1050 <free_matrix@plt>
mov    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    $0x400,%edx
call   1050 <free_matrix@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Printing initial matrix: \0A\00"
@.str.1 = [27 x i8] c"Printing evolved matrix: \0A\00"
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 i16**
%11 = alloca i16**
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i32 1024, i32* %7
store i32 1024, i32* %8
store i32 1, i32* %9
%15 = load i16**, i16*** %10
%16 = call i16** @allocate_matrix(i16** %15, i32 1024, i32 1024)
store i16** %16, i16*** %10
%17 = load i16**, i16*** %11
%18 = call i16** @allocate_matrix(i16** %17, i32 1024, i32 1024)
store i16** %18, i16*** %11
store i32 0, i32* %14
%19 = load i16**, i16*** %10
%20 = load i32, i32* %14
%21 = call i32 @init_matrix(i16** %19, i32 1024, i32 1024, i32 1, i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%23 = load i16**, i16*** %10
%24 = call i32 @print_matrix(i16** %23, i32 1024, i32 1024)
%25 = load i16**, i16*** %10
%26 = load i16**, i16*** %11
%27 = call i32 @dead_or_alive(i16** %25, i16** %26, i32 1024, i32 1024, i32 1, i32 1)
%28 = load i16**, i16*** %11
%29 = call i32 @enforce_boundary_conditions(i16** %28, i32 1024, i32 1024, i32 1)
%30 = bitcast i16*** %10 to i8*
%31 = bitcast i16*** %11 to i8*
%32 = call i32 @swap(i8* %30, i8* %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%34 = load i16**, i16*** %10
%35 = call i32 @print_matrix(i16** %34, i32 1024, i32 1024)
%36 = load i16**, i16*** %10
%37 = call i32 @free_matrix(i16** %36, i32 1024, i32 1024)
%38 = load i16**, i16*** %11
%39 = call i32 @free_matrix(i16** %38, i32 1024, i32 1024)
ret i32 0
}

LLVM IR (-O2):
@str = [26 x i8] c"Printing initial matrix: \00"
@str.2 = [26 x i8] c"Printing evolved matrix: \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i16**
%4 = alloca i16**
%5 = bitcast i16*** %3 to i8*
%6 = bitcast i16*** %4 to i8*
%7 = tail call i16** @allocate_matrix(i16** undef, i32 1024, i32 1024)
store i16** %7, i16*** %3
%8 = tail call i16** @allocate_matrix(i16** undef, i32 1024, i32 1024)
store i16** %8, i16*** %4
%9 = tail call i32 @init_matrix(i16** %7, i32 1024, i32 1024, i32 1, i32 0)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @print_matrix(i16** %7, i32 1024, i32 1024)
%12 = tail call i32 @dead_or_alive(i16** %7, i16** %8, i32 1024, i32 1024, i32 1, i32 1)
%13 = tail call i32 @enforce_boundary_conditions(i16** %8, i32 1024, i32 1024, i32 1)
%14 = call i32 @swap(i8* %5, i8* %6)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.2, i64 0, i64 0))
%16 = load i16**, i16*** %3
%17 = call i32 @print_matrix(i16** %16, i32 1024, i32 1024)
%18 = load i16**, i16*** %3
%19 = call i32 @free_matrix(i16** %18, i32 1024, i32 1024)
%20 = load i16**, i16*** %4
%21 = call i32 @free_matrix(i16** %20, i32 1024, i32 1024)
ret i32 0
}