#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*/ printf(char *, ...);
int checkNeighbours(char **currGrid, char **nextGrid, int y, int x, int size) {
  char neighbourCount = 0;
  int i;
  int k;
  int stopX;
  int stopY;
  int origX = x;
  int origY = y;
  if (y + 1 <= size - 1)
    stopY = y + 1;
  else
    stopY = y;
  if (x + 1 <= size - 1)
    stopX = x + 1;
  else
    stopX = x;
  if (y - 1 >= 0)
    y = y - 1;
  if (x - 1 >= 0)
    x = x - 1;
  k = x;
  i = y;
  if ('*' == currGrid[origY][origX]) {
    printf("checking neighbours for: [%d, %d]\n", origY, origX);
  }
  do {
    do {
      if ('*' == currGrid[origY][origX]) {
        printf("checking [%d, %d] which contains %c\n", i, k, currGrid[i][k]);
      }
      if (('*' == currGrid[i][k]) && (0 == ((i == origY) && (k == origX)))) {
        neighbourCount++;
        printf("^neighbour^\n");
      }
      k++;
    } while (k <= stopX);
    k = x;
    i++;
  } while (i <= stopY);
  if (neighbourCount > 0) {
    printf("while ends\n\n");
  }
  if ('*' == currGrid[origY][origX]) {
    printf("neighbourCount == %d\n", neighbourCount);
    printf("y == %d, x == %d\n", y, x);
    printf("origY == %d, origX == %d\n", origY, origX);
    printf("stopY == %d, stopX == %d\n\n", stopY, stopX);
    if (neighbourCount > 3 || neighbourCount < 2) {
      nextGrid[origY][origX] = '-';
      printf("* changes to - @ [%d, %d]\n\n", origY, origX);
      return 1;
    } else
      return 0;
  } else {
    if (3 == neighbourCount) {
      nextGrid[origY][origX] = '*';
      printf("- changes to * @ [%d, %d]\n\n", origY, origX);
      return 2;
    } else
      return 0;
  }
}


x86 assembly (clang, -O0):
<checkNeighbours>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movb   $0x0,-0x25(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     115c <checkNeighbours+0x4c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1162 <checkNeighbours+0x52>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1184 <checkNeighbours+0x74>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118a <checkNeighbours+0x7a>
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cmp    $0x0,%eax
jl     11a2 <checkNeighbours+0x92>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
cmp    $0x0,%eax
jl     11ba <checkNeighbours+0xaa>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2a,%eax
cmp    %ecx,%eax
jne    11fb <checkNeighbours+0xeb>
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1200 <checkNeighbours+0xf0>
jmp    1205 <checkNeighbours+0xf5>
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2a,%eax
cmp    %ecx,%eax
jne    124e <checkNeighbours+0x13e>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2a,%eax
cmp    %ecx,%eax
jne    12b4 <checkNeighbours+0x1a4>
mov    -0x2c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x40(%rbp),%ecx
mov    %al,-0x41(%rbp)
jne    128c <checkNeighbours+0x17c>
mov    -0x30(%rbp),%eax
cmp    -0x3c(%rbp),%eax
sete   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
and    $0x1,%al
movzbl %al,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    12b4 <checkNeighbours+0x1a4>
mov    -0x25(%rbp),%al
add    $0x1,%al
mov    %al,-0x25(%rbp)
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jle    1205 <checkNeighbours+0xf5>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x38(%rbp),%eax
jle    1200 <checkNeighbours+0xf0>
movsbl -0x25(%rbp),%eax
cmp    $0x0,%eax
jle    12ff <checkNeighbours+0x1ef>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2a,%eax
cmp    %ecx,%eax
jne    13c8 <checkNeighbours+0x2b8>
movsbl -0x25(%rbp),%esi
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xd39(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x25(%rbp),%eax
cmp    $0x3,%eax
jg     1388 <checkNeighbours+0x278>
movsbl -0x25(%rbp),%eax
cmp    $0x2,%eax
jge    13bc <checkNeighbours+0x2ac>
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1414 <checkNeighbours+0x304>
movl   $0x0,-0x4(%rbp)
jmp    1414 <checkNeighbours+0x304>
movsbl -0x25(%rbp),%ecx
mov    $0x3,%eax
cmp    %ecx,%eax
jne    140d <checkNeighbours+0x2fd>
mov    -0x18(%rbp),%rax
movslq -0x40(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x2a,(%rax,%rcx,1)
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xce1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1414 <checkNeighbours+0x304>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkNeighbours>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,0x38(%rsp)
mov    %rdi,%rbx
add    $0xffffffff,%r8d
xor    %r13d,%r13d
cmp    %edx,%r8d
setg   %r13b
add    %edx,%r13d
xor    %r12d,%r12d
cmp    %ecx,%r8d
setg   %r12b
add    %ecx,%r12d
xor    %eax,%eax
test   %edx,%edx
setg   %al
mov    %edx,%ecx
sub    %eax,%ecx
mov    %ecx,0x14(%rsp)
xor    %eax,%eax
test   %r14d,%r14d
setg   %al
mov    %r14d,%ecx
sub    %eax,%ecx
mov    %ecx,0xc(%rsp)
movslq %edx,%rbp
mov    (%rdi,%rbp,8),%rax
movslq %r14d,%rcx
mov    %rcx,0x18(%rsp)
cmpb   $0x2a,(%rax,%rcx,1)
jne    11a3 <checkNeighbours+0x83>
lea    0xe6a(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,0x2c(%rsp)
mov    %r14d,0x30(%rsp)
mov    0xc(%rsp),%eax
movslq %eax,%rcx
mov    %rcx,0x40(%rsp)
cmp    %r12d,%ecx
mov    %r12d,0x24(%rsp)
cmovg  %eax,%r12d
add    $0x1,%r12d
mov    0x14(%rsp),%eax
movslq %eax,%r14
cmp    %r13d,%r14d
mov    %r13d,0x28(%rsp)
cmovg  %eax,%r13d
add    $0x1,%r13d
mov    %r13d,0x34(%rsp)
movl   $0x0,0x10(%rsp)
jmp    11fb <checkNeighbours+0xdb>
nop
add    $0x1,%r14
cmp    %r14d,0x34(%rsp)
je     1278 <checkNeighbours+0x158>
mov    0xc(%rsp),%r15d
mov    0x40(%rsp),%r13
jmp    1233 <checkNeighbours+0x113>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%eax
add    $0x1,%al
mov    %eax,0x10(%rsp)
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%r13
add    $0x1,%r15d
cmp    %r15d,%r12d
je     11f0 <checkNeighbours+0xd0>
mov    (%rbx,%rbp,8),%rax
mov    0x18(%rsp),%rcx
cmpb   $0x2a,(%rax,%rcx,1)
jne    125f <checkNeighbours+0x13f>
mov    (%rbx,%r14,8),%rax
movsbl (%rax,%r13,1),%ecx
lea    0xdd1(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx,%r14,8),%rax
cmpb   $0x2a,(%rax,%r13,1)
jne    1226 <checkNeighbours+0x106>
cmp    %rbp,%r14
jne    1210 <checkNeighbours+0xf0>
cmp    %r13,0x18(%rsp)
je     1226 <checkNeighbours+0x106>
jmp    1210 <checkNeighbours+0xf0>
mov    0x10(%rsp),%r13d
test   %r13b,%r13b
jle    128e <checkNeighbours+0x16e>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx,%rbp,8),%rax
mov    0x18(%rsp),%rcx
cmpb   $0x2a,(%rax,%rcx,1)
mov    0x30(%rsp),%r14d
mov    0x2c(%rsp),%r15d
mov    0x28(%rsp),%ebx
jne    1319 <checkNeighbours+0x1f9>
movsbl %r13b,%esi
lea    0xd92(%rip),%rdi
xor    %r12d,%r12d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd97(%rip),%rdi
mov    0x14(%rsp),%esi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd93(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd99(%rip),%rdi
mov    %ebx,%esi
mov    0x24(%rsp),%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xfc,%r13b
cmp    $0xfe,%r13b
jae    134f <checkNeighbours+0x22f>
mov    $0x1,%r12d
lea    0xd90(%rip),%rdi
mov    $0x2d,%al
jmp    1331 <checkNeighbours+0x211>
xor    %r12d,%r12d
cmp    $0x3,%r13b
jne    134f <checkNeighbours+0x22f>
mov    $0x2,%r12d
lea    0xd92(%rip),%rdi
mov    $0x2a,%al
mov    0x38(%rsp),%rcx
mov    (%rcx,%rbp,8),%rcx
mov    0x18(%rsp),%rdx
mov    %al,(%rcx,%rdx,1)
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"checking neighbours for: [%d, %d]\0A\00"
@.str.1 = [37 x i8] c"checking [%d, %d] which contains %c\0A\00"
@.str.2 = [13 x i8] c"^neighbour^\0A\00"
@.str.3 = [13 x i8] c"while ends\0A\0A\00"
@.str.4 = [22 x i8] c"neighbourCount == %d\0A\00"
@.str.5 = [18 x i8] c"y == %d, x == %d\0A\00"
@.str.6 = [26 x i8] c"origY == %d, origX == %d\0A\00"
@.str.7 = [27 x i8] c"stopY == %d, stopX == %d\0A\0A\00"
@.str.8 = [28 x i8] c"* changes to - @ [%d, %d]\0A\0A\00"
@.str.9 = [28 x i8] c"- changes to * @ [%d, %d]\0A\0A\00"
define i32 @checkNeighbours(i8** %0, i8** %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8** %0, i8*** %7
store i8** %1, i8*** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i8 0, i8* %12
%19 = load i32, i32* %10
store i32 %19, i32* %17
%20 = load i32, i32* %9
store i32 %20, i32* %18
%21 = load i32, i32* %9
%22 = add nsw i32 %21, 1
%23 = load i32, i32* %11
%24 = sub nsw i32 %23, 1
%25 = icmp sle i32 %22, %24
br i1 %25, label %26, label %29
26: ; preds = %5
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %16
br label %31
29: ; preds = %5
%30 = load i32, i32* %9
store i32 %30, i32* %16
br label %31
31: ; preds = %29, %26
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %11
%35 = sub nsw i32 %34, 1
%36 = icmp sle i32 %33, %35
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %15
br label %42
40: ; preds = %31
%41 = load i32, i32* %10
store i32 %41, i32* %15
br label %42
42: ; preds = %40, %37
%43 = load i32, i32* %9
%44 = sub nsw i32 %43, 1
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* %9
%48 = sub nsw i32 %47, 1
store i32 %48, i32* %9
br label %49
49: ; preds = %46, %42
%50 = load i32, i32* %10
%51 = sub nsw i32 %50, 1
%52 = icmp sge i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* %10
%55 = sub nsw i32 %54, 1
store i32 %55, i32* %10
br label %56
56: ; preds = %53, %49
%57 = load i32, i32* %10
store i32 %57, i32* %14
%58 = load i32, i32* %9
store i32 %58, i32* %13
%59 = load i8**, i8*** %7
%60 = load i32, i32* %18
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8*, i8** %59, i64 %61
%63 = load i8*, i8** %62
%64 = load i32, i32* %17
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 42, %68
br i1 %69, label %70, label %74
70: ; preds = %56
%71 = load i32, i32* %18
%72 = load i32, i32* %17
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %71, i32 %72)
br label %74
74: ; preds = %70, %56
br label %75
75: ; preds = %141, %74
br label %76
76: ; preds = %133, %75
%77 = load i8**, i8*** %7
%78 = load i32, i32* %18
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8*, i8** %77, i64 %79
%81 = load i8*, i8** %80
%82 = load i32, i32* %17
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
%85 = load i8, i8* %84
%86 = sext i8 %85 to i32
%87 = icmp eq i32 42, %86
br i1 %87, label %88, label %102
88: ; preds = %76
%89 = load i32, i32* %13
%90 = load i32, i32* %14
%91 = load i8**, i8*** %7
%92 = load i32, i32* %13
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = load i32, i32* %14
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %95, i64 %97
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %89, i32 %90, i32 %100)
br label %102
102: ; preds = %88, %76
%103 = load i8**, i8*** %7
%104 = load i32, i32* %13
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8*, i8** %103, i64 %105
%107 = load i8*, i8** %106
%108 = load i32, i32* %14
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i8, i8* %107, i64 %109
%111 = load i8, i8* %110
%112 = sext i8 %111 to i32
%113 = icmp eq i32 42, %112
br i1 %113, label %114, label %130
114: ; preds = %102
%115 = load i32, i32* %13
%116 = load i32, i32* %18
%117 = icmp eq i32 %115, %116
br i1 %117, label %118, label %122
118: ; preds = %114
%119 = load i32, i32* %14
%120 = load i32, i32* %17
%121 = icmp eq i32 %119, %120
br label %122
122: ; preds = %118, %114
%123 = phi i1 [ false, %114 ], [ %121, %118 ]
%124 = zext i1 %123 to i32
%125 = icmp eq i32 0, %124
br i1 %125, label %126, label %130
126: ; preds = %122
%127 = load i8, i8* %12
%128 = add i8 %127, 1
store i8 %128, i8* %12
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %130
130: ; preds = %126, %122, %102
%131 = load i32, i32* %14
%132 = add nsw i32 %131, 1
store i32 %132, i32* %14
br label %133
133: ; preds = %130
%134 = load i32, i32* %14
%135 = load i32, i32* %15
%136 = icmp sle i32 %134, %135
br i1 %136, label %76, label %137
137: ; preds = %133
%138 = load i32, i32* %10
store i32 %138, i32* %14
%139 = load i32, i32* %13
%140 = add nsw i32 %139, 1
store i32 %140, i32* %13
br label %141
141: ; preds = %137
%142 = load i32, i32* %13
%143 = load i32, i32* %16
%144 = icmp sle i32 %142, %143
br i1 %144, label %75, label %145
145: ; preds = %141
%146 = load i8, i8* %12
%147 = sext i8 %146 to i32
%148 = icmp sgt i32 %147, 0
br i1 %148, label %149, label %151
149: ; preds = %145
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %151
151: ; preds = %149, %145
%152 = load i8**, i8*** %7
%153 = load i32, i32* %18
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds i8*, i8** %152, i64 %154
%156 = load i8*, i8** %155
%157 = load i32, i32* %17
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i8, i8* %156, i64 %158
%160 = load i8, i8* %159
%161 = sext i8 %160 to i32
%162 = icmp eq i32 42, %161
br i1 %162, label %163, label %196
163: ; preds = %151
%164 = load i8, i8* %12
%165 = sext i8 %164 to i32
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %165)
%167 = load i32, i32* %9
%168 = load i32, i32* %10
%169 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %167, i32 %168)
%170 = load i32, i32* %18
%171 = load i32, i32* %17
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %170, i32 %171)
%173 = load i32, i32* %16
%174 = load i32, i32* %15
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %173, i32 %174)
%176 = load i8, i8* %12
%177 = sext i8 %176 to i32
%178 = icmp sgt i32 %177, 3
br i1 %178, label %183, label %179
179: ; preds = %163
%180 = load i8, i8* %12
%181 = sext i8 %180 to i32
%182 = icmp slt i32 %181, 2
br i1 %182, label %183, label %195
183: ; preds = %179, %163
%184 = load i8**, i8*** %8
%185 = load i32, i32* %18
%186 = sext i32 %185 to i64
%187 = getelementptr inbounds i8*, i8** %184, i64 %186
%188 = load i8*, i8** %187
%189 = load i32, i32* %17
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds i8, i8* %188, i64 %190
store i8 45, i8* %191
%192 = load i32, i32* %18
%193 = load i32, i32* %17
%194 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i32 %192, i32 %193)
store i32 1, i32* %6
br label %213
195: ; preds = %179
store i32 0, i32* %6
br label %213
196: ; preds = %151
%197 = load i8, i8* %12
%198 = sext i8 %197 to i32
%199 = icmp eq i32 3, %198
br i1 %199, label %200, label %212
200: ; preds = %196
%201 = load i8**, i8*** %8
%202 = load i32, i32* %18
%203 = sext i32 %202 to i64
%204 = getelementptr inbounds i8*, i8** %201, i64 %203
%205 = load i8*, i8** %204
%206 = load i32, i32* %17
%207 = sext i32 %206 to i64
%208 = getelementptr inbounds i8, i8* %205, i64 %207
store i8 42, i8* %208
%209 = load i32, i32* %18
%210 = load i32, i32* %17
%211 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), i32 %209, i32 %210)
store i32 2, i32* %6
br label %213
212: ; preds = %196
store i32 0, i32* %6
br label %213
213: ; preds = %212, %200, %195, %183
%214 = load i32, i32* %6
ret i32 %214
}

LLVM IR (-O2):
@.str = [35 x i8] c"checking neighbours for: [%d, %d]\0A\00"
@.str.1 = [37 x i8] c"checking [%d, %d] which contains %c\0A\00"
@.str.4 = [22 x i8] c"neighbourCount == %d\0A\00"
@.str.5 = [18 x i8] c"y == %d, x == %d\0A\00"
@.str.6 = [26 x i8] c"origY == %d, origX == %d\0A\00"
@.str.7 = [27 x i8] c"stopY == %d, stopX == %d\0A\0A\00"
@.str.8 = [28 x i8] c"* changes to - @ [%d, %d]\0A\0A\00"
@.str.9 = [28 x i8] c"- changes to * @ [%d, %d]\0A\0A\00"
@str = [12 x i8] c"while ends\0A\00"
@str.10 = [12 x i8] c"^neighbour^\00"
define i32 @checkNeighbours(i8** nocapture %0, i8** nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = add nsw i32 %4, -1
%7 = icmp sgt i32 %6, %2
%8 = zext i1 %7 to i32
%9 = add i32 %8, %2
%10 = icmp sgt i32 %6, %3
%11 = zext i1 %10 to i32
%12 = add i32 %11, %3
%13 = icmp sgt i32 %2, 0
%14 = sext i1 %13 to i32
%15 = add i32 %14, %2
%16 = icmp sgt i32 %3, 0
%17 = sext i1 %16 to i32
%18 = add i32 %17, %3
%19 = sext i32 %2 to i64
%20 = getelementptr inbounds i8*, i8** %0, i64 %19
%21 = load i8*, i8** %20
%22 = sext i32 %3 to i64
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 42
br i1 %25, label %26, label %28
26: ; preds = %5
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3)
br label %28
28: ; preds = %26, %5
%29 = sext i32 %18 to i64
%30 = call i32 @llvm.smax.i32(i32 %18, i32 %12)
%31 = add i32 %30, 1
%32 = sext i32 %15 to i64
%33 = call i32 @llvm.smax.i32(i32 %15, i32 %9)
%34 = add i32 %33, 1
br label %35
35: ; preds = %71, %28
%36 = phi i64 [ %72, %71 ], [ %32, %28 ]
%37 = phi i8 [ %67, %71 ], [ 0, %28 ]
%38 = getelementptr inbounds i8*, i8** %0, i64 %36
%39 = icmp ne i64 %36, %19
%40 = trunc i64 %36 to i32
br label %41
41: ; preds = %66, %35
%42 = phi i64 [ %68, %66 ], [ %29, %35 ]
%43 = phi i8 [ %67, %66 ], [ %37, %35 ]
%44 = load i8*, i8** %20
%45 = getelementptr inbounds i8, i8* %44, i64 %22
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 42
br i1 %47, label %48, label %55
48: ; preds = %41
%49 = load i8*, i8** %38
%50 = getelementptr inbounds i8, i8* %49, i64 %42
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = trunc i64 %42 to i32
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %53, i32 %52)
br label %55
55: ; preds = %48, %41
%56 = load i8*, i8** %38
%57 = getelementptr inbounds i8, i8* %56, i64 %42
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 42
br i1 %59, label %60, label %66
60: ; preds = %55
%61 = icmp ne i64 %42, %22
%62 = select i1 %39, i1 true, i1 %61
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = add i8 %43, 1
%65 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
br label %66
66: ; preds = %63, %60, %55
%67 = phi i8 [ %64, %63 ], [ %43, %60 ], [ %43, %55 ]
%68 = add nsw i64 %42, 1
%69 = trunc i64 %68 to i32
%70 = icmp eq i32 %31, %69
br i1 %70, label %71, label %41
71: ; preds = %66
%72 = add nsw i64 %36, 1
%73 = trunc i64 %72 to i32
%74 = icmp eq i32 %34, %73
br i1 %74, label %75, label %35
75: ; preds = %71
%76 = sext i8 %67 to i32
%77 = icmp sgt i8 %67, 0
br i1 %77, label %78, label %80
78: ; preds = %75
%79 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %80
80: ; preds = %78, %75
%81 = load i8*, i8** %20
%82 = getelementptr inbounds i8, i8* %81, i64 %22
%83 = load i8, i8* %82
%84 = icmp eq i8 %83, 42
br i1 %84, label %85, label %92
85: ; preds = %80
%86 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %76)
%87 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %15, i32 %18)
%88 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %2, i32 %3)
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i32 %9, i32 %12)
%90 = add i8 %67, -4
%91 = icmp ult i8 %90, -2
br i1 %91, label %94, label %102
92: ; preds = %80
%93 = icmp eq i8 %67, 3
br i1 %93, label %94, label %102
94: ; preds = %92, %85
%95 = phi i8 [ 45, %85 ], [ 42, %92 ]
%96 = phi i8* [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), %85 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0), %92 ]
%97 = phi i32 [ 1, %85 ], [ 2, %92 ]
%98 = getelementptr inbounds i8*, i8** %1, i64 %19
%99 = load i8*, i8** %98
%100 = getelementptr inbounds i8, i8* %99, i64 %22
store i8 %95, i8* %100
%101 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %96, i32 %2, i32 %3)
br label %102
102: ; preds = %94, %92, %85
%103 = phi i32 [ 0, %85 ], [ 0, %92 ], [ %97, %94 ]
ret i32 %103
}