#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 */
struct grid {
  int dummy;
};

/* Variables and functions */
int grid_at(struct grid *, int const, int const);
int /*<<< orphan*/ grid_set(struct grid *, int const, int const, int);
int process_cell(struct grid *grid, const int x, const int y,
                 struct grid *new_grid) {
  unsigned neighbors = grid_at(grid, x - 1, y - 1) + grid_at(grid, x - 1, y) +
                       grid_at(grid, x - 1, y + 1) + grid_at(grid, x, y - 1) +
                       grid_at(grid, x, y + 1) + grid_at(grid, x + 1, y - 1) +
                       grid_at(grid, x + 1, y) + grid_at(grid, x + 1, y + 1);
  if (grid_at(grid, x, y)) {
    if (neighbors < 2 || neighbors > 3)
      grid_set(new_grid, x, y, 0);
    else
      grid_set(new_grid, x, y, 1);
  } else {
    if (neighbors == 3)
      grid_set(new_grid, x, y, 1);
    else
      grid_set(new_grid, x, y, 0);
  }
  return grid_at(new_grid, x, y);
}


x86 assembly (clang, -O0):
<process_cell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1040 <grid_at@plt>
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <grid_at@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
call   1040 <grid_at@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1040 <grid_at@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
call   1040 <grid_at@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
call   1040 <grid_at@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
call   1040 <grid_at@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%edx
add    $0x1,%edx
call   1040 <grid_at@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <grid_at@plt>
cmp    $0x0,%eax
je     1276 <process_cell+0x156>
cmpl   $0x2,-0x1c(%rbp)
jb     1247 <process_cell+0x127>
cmpl   $0x3,-0x1c(%rbp)
jbe    125d <process_cell+0x13d>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
xor    %ecx,%ecx
call   1030 <grid_set@plt>
jmp    1271 <process_cell+0x151>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    $0x1,%ecx
call   1030 <grid_set@plt>
jmp    12af <process_cell+0x18f>
cmpl   $0x3,-0x1c(%rbp)
jne    1299 <process_cell+0x179>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    $0x1,%ecx
call   1030 <grid_set@plt>
jmp    12aa <process_cell+0x18a>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
xor    %ecx,%ecx
call   1030 <grid_set@plt>
jmp    12af <process_cell+0x18f>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <grid_at@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_cell>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x10(%rsp)
mov    %edx,%ebx
mov    %rbx,0x8(%rsp)
mov    %esi,%r12d
mov    %rdi,%r15
lea    -0x1(%r12),%r14d
lea    -0x1(%rbx),%edx
mov    %edx,(%rsp)
mov    %r14d,%esi
call   1040 <grid_at@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <grid_at@plt>
mov    %eax,%r13d
add    %ebp,%r13d
lea    0x1(%rbx),%edx
mov    %r15,%rdi
mov    %r14d,%esi
mov    %edx,%r14d
mov    %edx,0x4(%rsp)
call   1040 <grid_at@plt>
mov    %eax,%ebp
add    %r13d,%ebp
mov    %r15,%rdi
mov    %r12d,%esi
mov    (%rsp),%r13d
mov    %r13d,%edx
call   1040 <grid_at@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r14d,%edx
call   1040 <grid_at@plt>
mov    %eax,%ebp
add    %ebx,%ebp
lea    0x1(%r12),%r14d
mov    %r15,%rdi
mov    %r14d,%esi
mov    %r13d,%edx
call   1040 <grid_at@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r15,%rdi
mov    %r14d,%esi
mov    0x8(%rsp),%r13
mov    %r13d,%edx
call   1040 <grid_at@plt>
mov    %eax,%ebp
add    %ebx,%ebp
mov    %r15,%rdi
mov    %r14d,%esi
mov    0x4(%rsp),%edx
call   1040 <grid_at@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
call   1040 <grid_at@plt>
xor    %ecx,%ecx
cmp    $0x3,%ebx
sete   %cl
and    $0xfffffffe,%ebx
xor    %edx,%edx
cmp    $0x2,%ebx
sete   %dl
test   %eax,%eax
cmove  %ecx,%edx
movzbl %dl,%ecx
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
call   1030 <grid_set@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <grid_at@plt>

LLVM IR (-O0):
%struct.grid = type { i32 }
define i32 @process_cell(%struct.grid* %0, i32 %1, i32 %2, %struct.grid* %3) {
%5 = alloca %struct.grid*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.grid*
%9 = alloca i32
store %struct.grid* %0, %struct.grid** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store %struct.grid* %3, %struct.grid** %8
%10 = load %struct.grid*, %struct.grid** %5
%11 = load i32, i32* %6
%12 = sub nsw i32 %11, 1
%13 = load i32, i32* %7
%14 = sub nsw i32 %13, 1
%15 = call i32 @grid_at(%struct.grid* %10, i32 %12, i32 %14)
%16 = load %struct.grid*, %struct.grid** %5
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 1
%19 = load i32, i32* %7
%20 = call i32 @grid_at(%struct.grid* %16, i32 %18, i32 %19)
%21 = add nsw i32 %15, %20
%22 = load %struct.grid*, %struct.grid** %5
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 1
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
%27 = call i32 @grid_at(%struct.grid* %22, i32 %24, i32 %26)
%28 = add nsw i32 %21, %27
%29 = load %struct.grid*, %struct.grid** %5
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = sub nsw i32 %31, 1
%33 = call i32 @grid_at(%struct.grid* %29, i32 %30, i32 %32)
%34 = add nsw i32 %28, %33
%35 = load %struct.grid*, %struct.grid** %5
%36 = load i32, i32* %6
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
%39 = call i32 @grid_at(%struct.grid* %35, i32 %36, i32 %38)
%40 = add nsw i32 %34, %39
%41 = load %struct.grid*, %struct.grid** %5
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
%44 = load i32, i32* %7
%45 = sub nsw i32 %44, 1
%46 = call i32 @grid_at(%struct.grid* %41, i32 %43, i32 %45)
%47 = add nsw i32 %40, %46
%48 = load %struct.grid*, %struct.grid** %5
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
%51 = load i32, i32* %7
%52 = call i32 @grid_at(%struct.grid* %48, i32 %50, i32 %51)
%53 = add nsw i32 %47, %52
%54 = load %struct.grid*, %struct.grid** %5
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
%59 = call i32 @grid_at(%struct.grid* %54, i32 %56, i32 %58)
%60 = add nsw i32 %53, %59
store i32 %60, i32* %9
%61 = load %struct.grid*, %struct.grid** %5
%62 = load i32, i32* %6
%63 = load i32, i32* %7
%64 = call i32 @grid_at(%struct.grid* %61, i32 %62, i32 %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %66, label %83
66: ; preds = %4
%67 = load i32, i32* %9
%68 = icmp ult i32 %67, 2
br i1 %68, label %72, label %69
69: ; preds = %66
%70 = load i32, i32* %9
%71 = icmp ugt i32 %70, 3
br i1 %71, label %72, label %77
72: ; preds = %69, %66
%73 = load %struct.grid*, %struct.grid** %8
%74 = load i32, i32* %6
%75 = load i32, i32* %7
%76 = call i32 @grid_set(%struct.grid* %73, i32 %74, i32 %75, i32 0)
br label %82
77: ; preds = %69
%78 = load %struct.grid*, %struct.grid** %8
%79 = load i32, i32* %6
%80 = load i32, i32* %7
%81 = call i32 @grid_set(%struct.grid* %78, i32 %79, i32 %80, i32 1)
br label %82
82: ; preds = %77, %72
br label %97
83: ; preds = %4
%84 = load i32, i32* %9
%85 = icmp eq i32 %84, 3
br i1 %85, label %86, label %91
86: ; preds = %83
%87 = load %struct.grid*, %struct.grid** %8
%88 = load i32, i32* %6
%89 = load i32, i32* %7
%90 = call i32 @grid_set(%struct.grid* %87, i32 %88, i32 %89, i32 1)
br label %96
91: ; preds = %83
%92 = load %struct.grid*, %struct.grid** %8
%93 = load i32, i32* %6
%94 = load i32, i32* %7
%95 = call i32 @grid_set(%struct.grid* %92, i32 %93, i32 %94, i32 0)
br label %96
96: ; preds = %91, %86
br label %97
97: ; preds = %96, %82
%98 = load %struct.grid*, %struct.grid** %8
%99 = load i32, i32* %6
%100 = load i32, i32* %7
%101 = call i32 @grid_at(%struct.grid* %98, i32 %99, i32 %100)
ret i32 %101
}

LLVM IR (-O2):
%struct.grid = type { i32 }
define i32 @process_cell(%struct.grid* %0, i32 %1, i32 %2, %struct.grid* %3) {
%5 = add nsw i32 %1, -1
%6 = add nsw i32 %2, -1
%7 = tail call i32 @grid_at(%struct.grid* %0, i32 %5, i32 %6)
%8 = tail call i32 @grid_at(%struct.grid* %0, i32 %5, i32 %2)
%9 = add nsw i32 %8, %7
%10 = add nsw i32 %2, 1
%11 = tail call i32 @grid_at(%struct.grid* %0, i32 %5, i32 %10)
%12 = add nsw i32 %9, %11
%13 = tail call i32 @grid_at(%struct.grid* %0, i32 %1, i32 %6)
%14 = add nsw i32 %12, %13
%15 = tail call i32 @grid_at(%struct.grid* %0, i32 %1, i32 %10)
%16 = add nsw i32 %14, %15
%17 = add nsw i32 %1, 1
%18 = tail call i32 @grid_at(%struct.grid* %0, i32 %17, i32 %6)
%19 = add nsw i32 %16, %18
%20 = tail call i32 @grid_at(%struct.grid* %0, i32 %17, i32 %2)
%21 = add nsw i32 %19, %20
%22 = tail call i32 @grid_at(%struct.grid* %0, i32 %17, i32 %10)
%23 = add nsw i32 %21, %22
%24 = tail call i32 @grid_at(%struct.grid* %0, i32 %1, i32 %2)
%25 = icmp eq i32 %24, 0
%26 = icmp eq i32 %23, 3
%27 = and i32 %23, -2
%28 = icmp eq i32 %27, 2
%29 = select i1 %25, i1 %26, i1 %28
%30 = zext i1 %29 to i32
%31 = tail call i32 @grid_set(%struct.grid* %3, i32 %1, i32 %2, i32 %30)
%32 = tail call i32 @grid_at(%struct.grid* %3, i32 %1, i32 %2)
ret i32 %32
}