#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 atoi(char *);
int /*<<< orphan*/ fill_grid(int **, int, int);
int /*<<< orphan*/ free2d(int **, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sleep(int);
scalar_t__ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 4) {
    puts("Usage: ./serial rows cols stages [pattern]");
    puts("Default pattern is glider");
    puts("Pattern options are:");
    printf("-glider\n");
    printf("-lwss\n");
    return -1;
  }
  int w = atoi(argv[1]);
  int h = atoi(argv[2]);
  int max_stage = atoi(argv[3]);
  if (w < 10 || h < 10) {
    puts("Usage: ./serial rows cols stages [pattern]");
    puts("Number of rows and columns must be at least 10");
    return -1;
  }
  if (max_stage < 1) {
    puts("Usage: ./serial rows cols stages [pattern]");
    puts("Number of stages must be at least 1");
    return -1;
  }
  int **grid = (int **)malloc(sizeof(int *) * w);
  fill_grid(grid, w, h);
  int **tmp = (int **)malloc(sizeof(int *) * w);
  if (argc == 4 || strcmp(argv[4], "glider") == 0) {
    grid[5][5] = 1;
    grid[6][6] = 1;
    grid[7][4] = 1;
    grid[7][5] = 1;
    grid[7][6] = 1;
  } else if (strcmp(argv[4], "lwss") == 0) {
    grid[0][0] = 1;
    grid[0][3] = 1;
    grid[1][4] = 1;
    grid[2][0] = 1;
    grid[2][4] = 1;
    grid[3][4] = 1;
    grid[3][1] = 1;
    grid[3][2] = 1;
    grid[3][3] = 1;
  } else {
    puts("Invalid pattern");
    puts("Usage: ./serial rows cols [pattern]");
    puts("Default pattern is glider");
    puts("Pattern options are:");
    printf("-glider\n");
    printf("-lwss\n");
    free2d(grid, w);
    free2d(tmp, w);
    return -1;
  }
  int k = 0;
  while (k < max_stage) {
    printf("Time %d\n", k);
    fill_grid(tmp, w, h);
    int i = 0;
    for (; i < w; i++) {
      int j = 0;
      for (; j < h; j++) {
        int count = 0;
        int r1, r2, c1, c2;
        c1 = (j + 1) % h;
        c2 = (j - 1) % h;
        if (c2 < 0)
          c2 = c2 + h;
        r1 = (i + 1) % w;
        r2 = (i - 1) % w;
        if (r2 < 0)
          r2 = r2 + w;
        if (grid[i][c1] == 1)
          count++;
        if (grid[i][c2] == 1)
          count++;
        if (grid[r1][c1] == 1)
          count++;
        if (grid[r1][j] == 1)
          count++;
        if (grid[r1][c2] == 1)
          count++;
        if (grid[r2][c1] == 1)
          count++;
        if (grid[r2][j] == 1)
          count++;
        if (grid[r2][c2] == 1)
          count++;
        if (grid[i][j] == 0) {
          printf("-");
          if (count == 3)
            tmp[i][j] = 1;
        } else {
          printf("O");
          if (count < 2 || count > 3)
            tmp[i][j] = 0;
          else if (count == 2 || count == 3)
            tmp[i][j] = 1;
        }
      }
      puts("");
    }
    int t = 0;
    for (; t < w; t++) {
      memcpy(grid[t], tmp[t], sizeof(int) * h);
    }
    k++;
    puts("");
    sleep(1);
  }
  free2d(grid, w);
  free2d(tmp, w);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11fc <main+0x6c>
lea    0xe49(%rip),%rdi
call   1030 <puts@plt>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17a5 <main+0x615>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xa,-0x14(%rbp)
jl     1240 <main+0xb0>
cmpl   $0xa,-0x18(%rbp)
jge    1264 <main+0xd4>
lea    0xdb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17a5 <main+0x615>
cmpl   $0x1,-0x1c(%rbp)
jge    1292 <main+0x102>
lea    0xd8b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17a5 <main+0x615>
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <fill_grid@plt>
movslq -0x14(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     12ef <main+0x15f>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xd5e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    133f <main+0x1af>
mov    -0x28(%rbp),%rax
mov    0x28(%rax),%rax
movl   $0x1,0x14(%rax)
mov    -0x28(%rbp),%rax
mov    0x30(%rax),%rax
movl   $0x1,0x18(%rax)
mov    -0x28(%rbp),%rax
mov    0x38(%rax),%rax
movl   $0x1,0x10(%rax)
mov    -0x28(%rbp),%rax
mov    0x38(%rax),%rax
movl   $0x1,0x14(%rax)
mov    -0x28(%rbp),%rax
mov    0x38(%rax),%rax
movl   $0x1,0x18(%rax)
jmp    145a <main+0x2ca>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
lea    0xd6f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    13e5 <main+0x255>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movl   $0x1,0xc(%rax)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x1,0x10(%rax)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x1,(%rax)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
movl   $0x1,0x10(%rax)
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x1,0x10(%rax)
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x1,0x4(%rax)
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x1,0x8(%rax)
mov    -0x28(%rbp),%rax
mov    0x18(%rax),%rax
movl   $0x1,0xc(%rax)
jmp    1455 <main+0x2c5>
lea    0xcd6(%rip),%rdi
call   1030 <puts@plt>
lea    0xcda(%rip),%rdi
call   1030 <puts@plt>
lea    0xc27(%rip),%rdi
call   1030 <puts@plt>
lea    0xc35(%rip),%rdi
call   1030 <puts@plt>
lea    0xc3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <free2d@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <free2d@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    17a5 <main+0x615>
jmp    145a <main+0x2ca>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1786 <main+0x5f6>
mov    -0x34(%rbp),%esi
lea    0xc7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <fill_grid@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    171a <main+0x58a>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1700 <main+0x570>
movl   $0x0,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x18(%rbp)
mov    %edx,-0x4c(%rbp)
mov    -0x3c(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x18(%rbp)
mov    %edx,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    14e7 <main+0x357>
mov    -0x50(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x44(%rbp)
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    1514 <main+0x384>
mov    -0x48(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x4c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1537 <main+0x3a7>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x50(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    155a <main+0x3ca>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x4c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    157d <main+0x3ed>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    15a0 <main+0x410>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x50(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    15c3 <main+0x433>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x4c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    15e6 <main+0x456>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    1609 <main+0x479>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x50(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    162c <main+0x49c>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    167a <main+0x4ea>
lea    0xab2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x3,-0x40(%rbp)
jne    1675 <main+0x4e5>
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    16ed <main+0x55d>
lea    0xa80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x2,-0x40(%rbp)
jl     169c <main+0x50c>
cmpl   $0x3,-0x40(%rbp)
jle    16b8 <main+0x528>
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
jmp    16e8 <main+0x558>
cmpl   $0x2,-0x40(%rbp)
je     16cc <main+0x53c>
cmpl   $0x3,-0x40(%rbp)
jne    16e3 <main+0x553>
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x3c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
jmp    16e8 <main+0x558>
jmp    16ed <main+0x55d>
jmp    16f2 <main+0x562>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    14a7 <main+0x317>
lea    0x9f7(%rip),%rdi
call   1030 <puts@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1494 <main+0x304>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1762 <main+0x5d2>
mov    -0x28(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x30(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1721 <main+0x591>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
lea    0x98c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
jmp    1461 <main+0x2d1>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <free2d@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <free2d@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
cmp    $0x3,%edi
jg     11ef <main+0x4f>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
lea    0xe65(%rip),%rdi
call   1040 <puts@plt>
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
lea    0xf0c(%rip),%rdi
call   1040 <puts@plt>
lea    0xf08(%rip),%rdi
jmp    15ca <main+0x42a>
mov    %rsi,%rbp
mov    %edi,%r13d
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r12d
mov    0x18(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,(%rsp)
cmp    $0xa,%ebx
jl     1311 <main+0x171>
cmp    $0x9,%r12d
jle    1311 <main+0x171>
cmpl   $0x0,0xc(%rsp)
jle    15b7 <main+0x417>
mov    (%rsp),%r14
lea    0x0(,%r14,8),%r15d
mov    %r15d,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14d,%esi
mov    %r12,0x28(%rsp)
mov    %r12d,%edx
call   1070 <fill_grid@plt>
mov    %r15d,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
cmp    $0x4,%r13d
je     1329 <main+0x189>
mov    0x20(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1329 <main+0x189>
mov    0x20(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     15e3 <main+0x443>
lea    0xdfa(%rip),%rdi
call   1040 <puts@plt>
lea    0xdfe(%rip),%rdi
call   1040 <puts@plt>
lea    0xd60(%rip),%rdi
call   1040 <puts@plt>
lea    0xd6e(%rip),%rdi
call   1040 <puts@plt>
lea    0xe07(%rip),%rdi
call   1040 <puts@plt>
lea    0xe03(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    (%rsp),%rbx
mov    %ebx,%esi
call   10b0 <free2d@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   10b0 <free2d@plt>
jmp    15cf <main+0x42f>
lea    0xce8(%rip),%rdi
call   1040 <puts@plt>
lea    0xd36(%rip),%rdi
jmp    15ca <main+0x42a>
mov    0x28(%rbx),%rax
movl   $0x1,0x14(%rax)
mov    0x30(%rbx),%rax
movl   $0x1,0x18(%rax)
mov    0x38(%rbx),%rax
movabs $0x100000001,%rcx
mov    %rcx,0x10(%rax)
add    $0x18,%rax
movl   $0x1,(%rax)
mov    0x28(%rsp),%rbp
lea    0x0(,%rbp,4),%r12d
mov    %ebp,%r13d
mov    (%rsp),%r15d
neg    %r13
xor    %esi,%esi
mov    %r14,0x20(%rsp)
mov    %r12d,0x18(%rsp)
mov    %r15,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xd4a(%rip),%rdi
mov    %esi,0x1c(%rsp)
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    (%rsp),%rsi
mov    %ebp,%edx
call   1070 <fill_grid@plt>
xor    %r14d,%r14d
jmp    13e0 <main+0x240>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x30(%rsp),%rax
mov    %rax,%r14
mov    0x10(%rsp),%r15
cmp    %r15,%rax
je     1540 <main+0x3a0>
lea    0x1(%r14),%rsi
lea    -0x1(%r14),%eax
cltd
mov    (%rsp),%rcx
idiv   %ecx
mov    %edx,%eax
sar    $0x1f,%eax
and    %ecx,%eax
add    %edx,%eax
cmp    %r15,%rsi
mov    %rsi,0x30(%rsp)
mov    %esi,%ecx
mov    $0x0,%edx
cmovne %rcx,%rdx
mov    %rdx,0x40(%rsp)
cltq
mov    %rax,0x38(%rsp)
mov    $0x1,%r12d
jmp    1449 <main+0x2a9>
nop
mov    0x20(%rsp),%rcx
mov    (%rcx,%r14,8),%rcx
mov    %eax,-0x4(%rcx,%r12,4)
lea    (%r12,%r13,1),%rax
add    $0x1,%rax
add    $0x1,%r12
cmp    $0x1,%rax
mov    0x28(%rsp),%rbp
je     13c0 <main+0x220>
lea    -0x2(%r12),%eax
cltd
idiv   %ebp
mov    %edx,%ecx
sar    $0x1f,%ecx
and    %ebp,%ecx
add    %edx,%ecx
mov    %r13,%rax
add    %r12,%rax
mov    (%rbx,%r14,8),%rax
mov    %r12d,%esi
mov    $0x0,%edx
cmovne %rsi,%rdx
xor    %esi,%esi
cmpl   $0x1,(%rax,%rdx,4)
sete   %sil
movslq %ecx,%rcx
lea    0x1(%rsi),%edi
cmpl   $0x1,(%rax,%rcx,4)
cmovne %esi,%edi
mov    0x40(%rsp),%rsi
mov    (%rbx,%rsi,8),%rsi
xor    %ebp,%ebp
cmpl   $0x1,(%rsi,%rdx,4)
sete   %bpl
add    %edi,%ebp
xor    %edi,%edi
cmpl   $0x1,-0x4(%rsi,%r12,4)
sete   %dil
add    %ebp,%edi
xor    %ebp,%ebp
cmpl   $0x1,(%rsi,%rcx,4)
sete   %bpl
add    %edi,%ebp
mov    0x38(%rsp),%rsi
mov    (%rbx,%rsi,8),%rsi
xor    %edi,%edi
cmpl   $0x1,(%rsi,%rdx,4)
sete   %dil
add    %ebp,%edi
xor    %edx,%edx
cmpl   $0x1,-0x4(%rsi,%r12,4)
sete   %dl
add    %edi,%edx
xor    %r15d,%r15d
cmpl   $0x1,(%rsi,%rcx,4)
sete   %r15b
add    %edx,%r15d
cmpl   $0x0,-0x4(%rax,%r12,4)
je     1520 <main+0x380>
mov    $0x4f,%edi
call   1030 <putchar@plt>
lea    -0x4(%r15),%ecx
xor    %eax,%eax
cmp    $0xfffffffe,%ecx
jb     1420 <main+0x280>
and    $0xfffffffe,%r15d
mov    $0x1,%eax
cmp    $0x2,%r15d
je     1420 <main+0x280>
jmp    142e <main+0x28e>
nop
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    $0x1,%eax
cmp    $0x3,%r15d
jne    142e <main+0x28e>
jmp    1420 <main+0x280>
xchg   %ax,%ax
xor    %r15d,%r15d
mov    0x20(%rsp),%r14
mov    0x18(%rsp),%r12d
nopl   (%rax)
mov    (%rbx,%r15,8),%rdi
mov    (%r14,%r15,8),%rsi
mov    %r12d,%edx
call   1080 <memcpy@plt>
add    $0x1,%r15
cmp    %r15,0x10(%rsp)
jne    1550 <main+0x3b0>
mov    0x1c(%rsp),%r15d
add    $0x1,%r15d
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    %r15d,%esi
cmp    0xc(%rsp),%r15d
mov    0x10(%rsp),%r15
jne    1390 <main+0x1f0>
mov    %rbx,%rdi
mov    (%rsp),%rbx
mov    %ebx,%esi
call   10b0 <free2d@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   10b0 <free2d@plt>
xor    %eax,%eax
jmp    15d4 <main+0x434>
lea    0xa42(%rip),%rdi
call   1040 <puts@plt>
lea    0xabf(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%rax
movl   $0x1,(%rax)
movl   $0x1,0xc(%rax)
mov    0x8(%rbx),%rax
movl   $0x1,0x10(%rax)
mov    0x10(%rbx),%rax
movl   $0x1,(%rax)
movl   $0x1,0x10(%rax)
mov    0x18(%rbx),%rax
movl   $0x1,0x10(%rax)
movabs $0x100000001,%rcx
mov    %rcx,0x4(%rax)
add    $0xc,%rax
jmp    1355 <main+0x1b5>

LLVM IR (-O0):
@.str = [43 x i8] c"Usage: ./serial rows cols stages [pattern]\00"
@.str.1 = [26 x i8] c"Default pattern is glider\00"
@.str.2 = [21 x i8] c"Pattern options are:\00"
@.str.3 = [9 x i8] c"-glider\0A\00"
@.str.4 = [7 x i8] c"-lwss\0A\00"
@.str.5 = [47 x i8] c"Number of rows and columns must be at least 10\00"
@.str.6 = [36 x i8] c"Number of stages must be at least 1\00"
@.str.7 = [7 x i8] c"glider\00"
@.str.8 = [5 x i8] c"lwss\00"
@.str.9 = [16 x i8] c"Invalid pattern\00"
@.str.10 = [36 x i8] c"Usage: ./serial rows cols [pattern]\00"
@.str.11 = [9 x i8] c"Time %d\0A\00"
@.str.12 = [2 x i8] c"-\00"
@.str.13 = [2 x i8] c"O\00"
@.str.14 = [1 x i8] zeroinitializer
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 i32**
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 4
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %424
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %6
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %7
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %8
%41 = load i32, i32* %6
%42 = icmp slt i32 %41, 10
br i1 %42, label %46, label %43
43: ; preds = %28
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 10
br i1 %45, label %46, label %49
46: ; preds = %43, %28
%47 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%48 = call i32 @puts(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %424
49: ; preds = %43
%50 = load i32, i32* %8
%51 = icmp slt i32 %50, 1
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i32 @puts(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%54 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %424
55: ; preds = %49
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = mul i64 8, %57
%59 = trunc i64 %58 to i32
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to i32**
store i32** %61, i32*** %9
%62 = load i32**, i32*** %9
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = call i32 @fill_grid(i32** %62, i32 %63, i32 %64)
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = mul i64 8, %67
%69 = trunc i64 %68 to i32
%70 = call i64 @malloc(i32 %69)
%71 = inttoptr i64 %70 to i32**
store i32** %71, i32*** %10
%72 = load i32, i32* %4
%73 = icmp eq i32 %72, 4
br i1 %73, label %80, label %74
74: ; preds = %55
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 4
%77 = load i8*, i8** %76
%78 = call i64 @strcmp(i8* %77, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %101
80: ; preds = %74, %55
%81 = load i32**, i32*** %9
%82 = getelementptr inbounds i32*, i32** %81, i64 5
%83 = load i32*, i32** %82
%84 = getelementptr inbounds i32, i32* %83, i64 5
store i32 1, i32* %84
%85 = load i32**, i32*** %9
%86 = getelementptr inbounds i32*, i32** %85, i64 6
%87 = load i32*, i32** %86
%88 = getelementptr inbounds i32, i32* %87, i64 6
store i32 1, i32* %88
%89 = load i32**, i32*** %9
%90 = getelementptr inbounds i32*, i32** %89, i64 7
%91 = load i32*, i32** %90
%92 = getelementptr inbounds i32, i32* %91, i64 4
store i32 1, i32* %92
%93 = load i32**, i32*** %9
%94 = getelementptr inbounds i32*, i32** %93, i64 7
%95 = load i32*, i32** %94
%96 = getelementptr inbounds i32, i32* %95, i64 5
store i32 1, i32* %96
%97 = load i32**, i32*** %9
%98 = getelementptr inbounds i32*, i32** %97, i64 7
%99 = load i32*, i32** %98
%100 = getelementptr inbounds i32, i32* %99, i64 6
store i32 1, i32* %100
br label %158
101: ; preds = %74
%102 = load i8**, i8*** %5
%103 = getelementptr inbounds i8*, i8** %102, i64 4
%104 = load i8*, i8** %103
%105 = call i64 @strcmp(i8* %104, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %107, label %144
107: ; preds = %101
%108 = load i32**, i32*** %9
%109 = getelementptr inbounds i32*, i32** %108, i64 0
%110 = load i32*, i32** %109
%111 = getelementptr inbounds i32, i32* %110, i64 0
store i32 1, i32* %111
%112 = load i32**, i32*** %9
%113 = getelementptr inbounds i32*, i32** %112, i64 0
%114 = load i32*, i32** %113
%115 = getelementptr inbounds i32, i32* %114, i64 3
store i32 1, i32* %115
%116 = load i32**, i32*** %9
%117 = getelementptr inbounds i32*, i32** %116, i64 1
%118 = load i32*, i32** %117
%119 = getelementptr inbounds i32, i32* %118, i64 4
store i32 1, i32* %119
%120 = load i32**, i32*** %9
%121 = getelementptr inbounds i32*, i32** %120, i64 2
%122 = load i32*, i32** %121
%123 = getelementptr inbounds i32, i32* %122, i64 0
store i32 1, i32* %123
%124 = load i32**, i32*** %9
%125 = getelementptr inbounds i32*, i32** %124, i64 2
%126 = load i32*, i32** %125
%127 = getelementptr inbounds i32, i32* %126, i64 4
store i32 1, i32* %127
%128 = load i32**, i32*** %9
%129 = getelementptr inbounds i32*, i32** %128, i64 3
%130 = load i32*, i32** %129
%131 = getelementptr inbounds i32, i32* %130, i64 4
store i32 1, i32* %131
%132 = load i32**, i32*** %9
%133 = getelementptr inbounds i32*, i32** %132, i64 3
%134 = load i32*, i32** %133
%135 = getelementptr inbounds i32, i32* %134, i64 1
store i32 1, i32* %135
%136 = load i32**, i32*** %9
%137 = getelementptr inbounds i32*, i32** %136, i64 3
%138 = load i32*, i32** %137
%139 = getelementptr inbounds i32, i32* %138, i64 2
store i32 1, i32* %139
%140 = load i32**, i32*** %9
%141 = getelementptr inbounds i32*, i32** %140, i64 3
%142 = load i32*, i32** %141
%143 = getelementptr inbounds i32, i32* %142, i64 3
store i32 1, i32* %143
br label %157
144: ; preds = %101
%145 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%146 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0))
%147 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%148 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%150 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%151 = load i32**, i32*** %9
%152 = load i32, i32* %6
%153 = call i32 @free2d(i32** %151, i32 %152)
%154 = load i32**, i32*** %10
%155 = load i32, i32* %6
%156 = call i32 @free2d(i32** %154, i32 %155)
store i32 -1, i32* %3
br label %424
157: ; preds = %107
br label %158
158: ; preds = %157, %80
store i32 0, i32* %11
br label %159
159: ; preds = %412, %158
%160 = load i32, i32* %11
%161 = load i32, i32* %8
%162 = icmp slt i32 %160, %161
br i1 %162, label %163, label %417
163: ; preds = %159
%164 = load i32, i32* %11
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i32 %164)
%166 = load i32**, i32*** %10
%167 = load i32, i32* %6
%168 = load i32, i32* %7
%169 = call i32 @fill_grid(i32** %166, i32 %167, i32 %168)
store i32 0, i32* %12
br label %170
170: ; preds = %385, %163
%171 = load i32, i32* %12
%172 = load i32, i32* %6
%173 = icmp slt i32 %171, %172
br i1 %173, label %174, label %388
174: ; preds = %170
store i32 0, i32* %13
br label %175
175: ; preds = %380, %174
%176 = load i32, i32* %13
%177 = load i32, i32* %7
%178 = icmp slt i32 %176, %177
br i1 %178, label %179, label %383
179: ; preds = %175
store i32 0, i32* %14
%180 = load i32, i32* %13
%181 = add nsw i32 %180, 1
%182 = load i32, i32* %7
%183 = srem i32 %181, %182
store i32 %183, i32* %17
%184 = load i32, i32* %13
%185 = sub nsw i32 %184, 1
%186 = load i32, i32* %7
%187 = srem i32 %185, %186
store i32 %187, i32* %18
%188 = load i32, i32* %18
%189 = icmp slt i32 %188, 0
br i1 %189, label %190, label %194
190: ; preds = %179
%191 = load i32, i32* %18
%192 = load i32, i32* %7
%193 = add nsw i32 %191, %192
store i32 %193, i32* %18
br label %194
194: ; preds = %190, %179
%195 = load i32, i32* %12
%196 = add nsw i32 %195, 1
%197 = load i32, i32* %6
%198 = srem i32 %196, %197
store i32 %198, i32* %15
%199 = load i32, i32* %12
%200 = sub nsw i32 %199, 1
%201 = load i32, i32* %6
%202 = srem i32 %200, %201
store i32 %202, i32* %16
%203 = load i32, i32* %16
%204 = icmp slt i32 %203, 0
br i1 %204, label %205, label %209
205: ; preds = %194
%206 = load i32, i32* %16
%207 = load i32, i32* %6
%208 = add nsw i32 %206, %207
store i32 %208, i32* %16
br label %209
209: ; preds = %205, %194
%210 = load i32**, i32*** %9
%211 = load i32, i32* %12
%212 = sext i32 %211 to i64
%213 = getelementptr inbounds i32*, i32** %210, i64 %212
%214 = load i32*, i32** %213
%215 = load i32, i32* %17
%216 = sext i32 %215 to i64
%217 = getelementptr inbounds i32, i32* %214, i64 %216
%218 = load i32, i32* %217
%219 = icmp eq i32 %218, 1
br i1 %219, label %220, label %223
220: ; preds = %209
%221 = load i32, i32* %14
%222 = add nsw i32 %221, 1
store i32 %222, i32* %14
br label %223
223: ; preds = %220, %209
%224 = load i32**, i32*** %9
%225 = load i32, i32* %12
%226 = sext i32 %225 to i64
%227 = getelementptr inbounds i32*, i32** %224, i64 %226
%228 = load i32*, i32** %227
%229 = load i32, i32* %18
%230 = sext i32 %229 to i64
%231 = getelementptr inbounds i32, i32* %228, i64 %230
%232 = load i32, i32* %231
%233 = icmp eq i32 %232, 1
br i1 %233, label %234, label %237
234: ; preds = %223
%235 = load i32, i32* %14
%236 = add nsw i32 %235, 1
store i32 %236, i32* %14
br label %237
237: ; preds = %234, %223
%238 = load i32**, i32*** %9
%239 = load i32, i32* %15
%240 = sext i32 %239 to i64
%241 = getelementptr inbounds i32*, i32** %238, i64 %240
%242 = load i32*, i32** %241
%243 = load i32, i32* %17
%244 = sext i32 %243 to i64
%245 = getelementptr inbounds i32, i32* %242, i64 %244
%246 = load i32, i32* %245
%247 = icmp eq i32 %246, 1
br i1 %247, label %248, label %251
248: ; preds = %237
%249 = load i32, i32* %14
%250 = add nsw i32 %249, 1
store i32 %250, i32* %14
br label %251
251: ; preds = %248, %237
%252 = load i32**, i32*** %9
%253 = load i32, i32* %15
%254 = sext i32 %253 to i64
%255 = getelementptr inbounds i32*, i32** %252, i64 %254
%256 = load i32*, i32** %255
%257 = load i32, i32* %13
%258 = sext i32 %257 to i64
%259 = getelementptr inbounds i32, i32* %256, i64 %258
%260 = load i32, i32* %259
%261 = icmp eq i32 %260, 1
br i1 %261, label %262, label %265
262: ; preds = %251
%263 = load i32, i32* %14
%264 = add nsw i32 %263, 1
store i32 %264, i32* %14
br label %265
265: ; preds = %262, %251
%266 = load i32**, i32*** %9
%267 = load i32, i32* %15
%268 = sext i32 %267 to i64
%269 = getelementptr inbounds i32*, i32** %266, i64 %268
%270 = load i32*, i32** %269
%271 = load i32, i32* %18
%272 = sext i32 %271 to i64
%273 = getelementptr inbounds i32, i32* %270, i64 %272
%274 = load i32, i32* %273
%275 = icmp eq i32 %274, 1
br i1 %275, label %276, label %279
276: ; preds = %265
%277 = load i32, i32* %14
%278 = add nsw i32 %277, 1
store i32 %278, i32* %14
br label %279
279: ; preds = %276, %265
%280 = load i32**, i32*** %9
%281 = load i32, i32* %16
%282 = sext i32 %281 to i64
%283 = getelementptr inbounds i32*, i32** %280, i64 %282
%284 = load i32*, i32** %283
%285 = load i32, i32* %17
%286 = sext i32 %285 to i64
%287 = getelementptr inbounds i32, i32* %284, i64 %286
%288 = load i32, i32* %287
%289 = icmp eq i32 %288, 1
br i1 %289, label %290, label %293
290: ; preds = %279
%291 = load i32, i32* %14
%292 = add nsw i32 %291, 1
store i32 %292, i32* %14
br label %293
293: ; preds = %290, %279
%294 = load i32**, i32*** %9
%295 = load i32, i32* %16
%296 = sext i32 %295 to i64
%297 = getelementptr inbounds i32*, i32** %294, i64 %296
%298 = load i32*, i32** %297
%299 = load i32, i32* %13
%300 = sext i32 %299 to i64
%301 = getelementptr inbounds i32, i32* %298, i64 %300
%302 = load i32, i32* %301
%303 = icmp eq i32 %302, 1
br i1 %303, label %304, label %307
304: ; preds = %293
%305 = load i32, i32* %14
%306 = add nsw i32 %305, 1
store i32 %306, i32* %14
br label %307
307: ; preds = %304, %293
%308 = load i32**, i32*** %9
%309 = load i32, i32* %16
%310 = sext i32 %309 to i64
%311 = getelementptr inbounds i32*, i32** %308, i64 %310
%312 = load i32*, i32** %311
%313 = load i32, i32* %18
%314 = sext i32 %313 to i64
%315 = getelementptr inbounds i32, i32* %312, i64 %314
%316 = load i32, i32* %315
%317 = icmp eq i32 %316, 1
br i1 %317, label %318, label %321
318: ; preds = %307
%319 = load i32, i32* %14
%320 = add nsw i32 %319, 1
store i32 %320, i32* %14
br label %321
321: ; preds = %318, %307
%322 = load i32**, i32*** %9
%323 = load i32, i32* %12
%324 = sext i32 %323 to i64
%325 = getelementptr inbounds i32*, i32** %322, i64 %324
%326 = load i32*, i32** %325
%327 = load i32, i32* %13
%328 = sext i32 %327 to i64
%329 = getelementptr inbounds i32, i32* %326, i64 %328
%330 = load i32, i32* %329
%331 = icmp eq i32 %330, 0
br i1 %331, label %332, label %346
332: ; preds = %321
%333 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%334 = load i32, i32* %14
%335 = icmp eq i32 %334, 3
br i1 %335, label %336, label %345
336: ; preds = %332
%337 = load i32**, i32*** %10
%338 = load i32, i32* %12
%339 = sext i32 %338 to i64
%340 = getelementptr inbounds i32*, i32** %337, i64 %339
%341 = load i32*, i32** %340
%342 = load i32, i32* %13
%343 = sext i32 %342 to i64
%344 = getelementptr inbounds i32, i32* %341, i64 %343
store i32 1, i32* %344
br label %345
345: ; preds = %336, %332
br label %379
346: ; preds = %321
%347 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%348 = load i32, i32* %14
%349 = icmp slt i32 %348, 2
br i1 %349, label %353, label %350
350: ; preds = %346
%351 = load i32, i32* %14
%352 = icmp sgt i32 %351, 3
br i1 %352, label %353, label %362
353: ; preds = %350, %346
%354 = load i32**, i32*** %10
%355 = load i32, i32* %12
%356 = sext i32 %355 to i64
%357 = getelementptr inbounds i32*, i32** %354, i64 %356
%358 = load i32*, i32** %357
%359 = load i32, i32* %13
%360 = sext i32 %359 to i64
%361 = getelementptr inbounds i32, i32* %358, i64 %360
store i32 0, i32* %361
br label %378
362: ; preds = %350
%363 = load i32, i32* %14
%364 = icmp eq i32 %363, 2
br i1 %364, label %368, label %365
365: ; preds = %362
%366 = load i32, i32* %14
%367 = icmp eq i32 %366, 3
br i1 %367, label %368, label %377
368: ; preds = %365, %362
%369 = load i32**, i32*** %10
%370 = load i32, i32* %12
%371 = sext i32 %370 to i64
%372 = getelementptr inbounds i32*, i32** %369, i64 %371
%373 = load i32*, i32** %372
%374 = load i32, i32* %13
%375 = sext i32 %374 to i64
%376 = getelementptr inbounds i32, i32* %373, i64 %375
store i32 1, i32* %376
br label %377
377: ; preds = %368, %365
br label %378
378: ; preds = %377, %353
br label %379
379: ; preds = %378, %345
br label %380
380: ; preds = %379
%381 = load i32, i32* %13
%382 = add nsw i32 %381, 1
store i32 %382, i32* %13
br label %175
383: ; preds = %175
%384 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.14, i64 0, i64 0))
br label %385
385: ; preds = %383
%386 = load i32, i32* %12
%387 = add nsw i32 %386, 1
store i32 %387, i32* %12
br label %170
388: ; preds = %170
store i32 0, i32* %19
br label %389
389: ; preds = %409, %388
%390 = load i32, i32* %19
%391 = load i32, i32* %6
%392 = icmp slt i32 %390, %391
br i1 %392, label %393, label %412
393: ; preds = %389
%394 = load i32**, i32*** %9
%395 = load i32, i32* %19
%396 = sext i32 %395 to i64
%397 = getelementptr inbounds i32*, i32** %394, i64 %396
%398 = load i32*, i32** %397
%399 = load i32**, i32*** %10
%400 = load i32, i32* %19
%401 = sext i32 %400 to i64
%402 = getelementptr inbounds i32*, i32** %399, i64 %401
%403 = load i32*, i32** %402
%404 = load i32, i32* %7
%405 = sext i32 %404 to i64
%406 = mul i64 4, %405
%407 = trunc i64 %406 to i32
%408 = call i32 @memcpy(i32* %398, i32* %403, i32 %407)
br label %409
409: ; preds = %393
%410 = load i32, i32* %19
%411 = add nsw i32 %410, 1
store i32 %411, i32* %19
br label %389
412: ; preds = %389
%413 = load i32, i32* %11
%414 = add nsw i32 %413, 1
store i32 %414, i32* %11
%415 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.14, i64 0, i64 0))
%416 = call i32 @sleep(i32 1)
br label %159
417: ; preds = %159
%418 = load i32**, i32*** %9
%419 = load i32, i32* %6
%420 = call i32 @free2d(i32** %418, i32 %419)
%421 = load i32**, i32*** %10
%422 = load i32, i32* %6
%423 = call i32 @free2d(i32** %421, i32 %422)
store i32 0, i32* %3
br label %424
424: ; preds = %417, %144, %52, %46, %22
%425 = load i32, i32* %3
ret i32 %425
}

LLVM IR (-O2):
@.str = [43 x i8] c"Usage: ./serial rows cols stages [pattern]\00"
@.str.1 = [26 x i8] c"Default pattern is glider\00"
@.str.2 = [21 x i8] c"Pattern options are:\00"
@.str.5 = [47 x i8] c"Number of rows and columns must be at least 10\00"
@.str.6 = [36 x i8] c"Number of stages must be at least 1\00"
@.str.7 = [7 x i8] c"glider\00"
@.str.8 = [5 x i8] c"lwss\00"
@.str.9 = [16 x i8] c"Invalid pattern\00"
@.str.10 = [36 x i8] c"Usage: ./serial rows cols [pattern]\00"
@.str.11 = [9 x i8] c"Time %d\0A\00"
@str.16 = [8 x i8] c"-glider\00"
@str.17 = [6 x i8] c"-lwss\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.16, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.17, i64 0, i64 0))
br label %204
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = icmp slt i32 %13, 10
%21 = icmp slt i32 %16, 10
%22 = select i1 %20, i1 true, i1 %21
br i1 %22, label %23, label %26
23: ; preds = %10
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
br label %204
26: ; preds = %10
%27 = icmp slt i32 %19, 1
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
br label %204
31: ; preds = %26
%32 = shl i32 %13, 3
%33 = tail call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to i32**
%35 = tail call i32 @fill_grid(i32** %34, i32 %13, i32 %16)
%36 = tail call i64 @malloc(i32 %32)
%37 = inttoptr i64 %36 to i32**
%38 = icmp eq i32 %0, 4
br i1 %38, label %44, label %39
39: ; preds = %31
%40 = getelementptr inbounds i8*, i8** %1, i64 4
%41 = load i8*, i8** %40
%42 = tail call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %56
44: ; preds = %39, %31
%45 = getelementptr inbounds i32*, i32** %34, i64 5
%46 = load i32*, i32** %45
%47 = getelementptr inbounds i32, i32* %46, i64 5
store i32 1, i32* %47
%48 = getelementptr inbounds i32*, i32** %34, i64 6
%49 = load i32*, i32** %48
%50 = getelementptr inbounds i32, i32* %49, i64 6
store i32 1, i32* %50
%51 = getelementptr inbounds i32*, i32** %34, i64 7
%52 = load i32*, i32** %51
%53 = getelementptr inbounds i32, i32* %52, i64 4
store i32 1, i32* %53
%54 = getelementptr inbounds i32, i32* %52, i64 5
store i32 1, i32* %54
%55 = getelementptr inbounds i32, i32* %52, i64 6
br label %84
56: ; preds = %39
%57 = load i8*, i8** %40
%58 = tail call i64 @strcmp(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %75
60: ; preds = %56
%61 = load i32*, i32** %34
store i32 1, i32* %61
%62 = getelementptr inbounds i32, i32* %61, i64 3
store i32 1, i32* %62
%63 = getelementptr inbounds i32*, i32** %34, i64 1
%64 = load i32*, i32** %63
%65 = getelementptr inbounds i32, i32* %64, i64 4
store i32 1, i32* %65
%66 = getelementptr inbounds i32*, i32** %34, i64 2
%67 = load i32*, i32** %66
store i32 1, i32* %67
%68 = getelementptr inbounds i32, i32* %67, i64 4
store i32 1, i32* %68
%69 = getelementptr inbounds i32*, i32** %34, i64 3
%70 = load i32*, i32** %69
%71 = getelementptr inbounds i32, i32* %70, i64 4
store i32 1, i32* %71
%72 = getelementptr inbounds i32, i32* %70, i64 1
store i32 1, i32* %72
%73 = getelementptr inbounds i32, i32* %70, i64 2
store i32 1, i32* %73
%74 = getelementptr inbounds i32, i32* %70, i64 3
br label %84
75: ; preds = %56
%76 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
%77 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0))
%78 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%79 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%80 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.16, i64 0, i64 0))
%81 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.17, i64 0, i64 0))
%82 = tail call i32 @free2d(i32** %34, i32 %13)
%83 = tail call i32 @free2d(i32** %37, i32 %13)
br label %204
84: ; preds = %44, %60
%85 = phi i32* [ %55, %44 ], [ %74, %60 ]
store i32 1, i32* %85
%86 = shl i32 %16, 2
%87 = zext i32 %16 to i64
%88 = zext i32 %13 to i64
br label %89
89: ; preds = %84, %196
%90 = phi i32 [ 0, %84 ], [ %197, %196 ]
%91 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.11, i64 0, i64 0), i32 %90)
%92 = tail call i32 @fill_grid(i32** %37, i32 %13, i32 %16)
br label %93
93: ; preds = %89, %184
%94 = phi i64 [ 0, %89 ], [ %95, %184 ]
%95 = add nuw nsw i64 %94, 1
%96 = icmp eq i64 %95, %88
%97 = trunc i64 %94 to i32
%98 = add i32 %97, -1
%99 = srem i32 %98, %13
%100 = icmp slt i32 %99, 0
%101 = select i1 %100, i32 %13, i32 0
%102 = add nsw i32 %101, %99
%103 = getelementptr inbounds i32*, i32** %34, i64 %94
%104 = and i64 %95, 4294967295
%105 = select i1 %96, i64 0, i64 %104
%106 = getelementptr inbounds i32*, i32** %34, i64 %105
%107 = sext i32 %102 to i64
%108 = getelementptr inbounds i32*, i32** %34, i64 %107
%109 = getelementptr inbounds i32*, i32** %37, i64 %94
br label %110
110: ; preds = %93, %182
%111 = phi i64 [ 0, %93 ], [ %112, %182 ]
%112 = add nuw nsw i64 %111, 1
%113 = icmp eq i64 %112, %87
%114 = trunc i64 %111 to i32
%115 = add i32 %114, -1
%116 = srem i32 %115, %16
%117 = icmp slt i32 %116, 0
%118 = select i1 %117, i32 %16, i32 0
%119 = add nsw i32 %118, %116
%120 = load i32*, i32** %103
%121 = and i64 %112, 4294967295
%122 = select i1 %113, i64 0, i64 %121
%123 = getelementptr inbounds i32, i32* %120, i64 %122
%124 = load i32, i32* %123
%125 = icmp eq i32 %124, 1
%126 = zext i1 %125 to i32
%127 = sext i32 %119 to i64
%128 = getelementptr inbounds i32, i32* %120, i64 %127
%129 = load i32, i32* %128
%130 = icmp eq i32 %129, 1
%131 = select i1 %125, i32 2, i32 1
%132 = select i1 %130, i32 %131, i32 %126
%133 = load i32*, i32** %106
%134 = getelementptr inbounds i32, i32* %133, i64 %122
%135 = load i32, i32* %134
%136 = icmp eq i32 %135, 1
%137 = zext i1 %136 to i32
%138 = add nuw nsw i32 %132, %137
%139 = getelementptr inbounds i32, i32* %133, i64 %111
%140 = load i32, i32* %139
%141 = icmp eq i32 %140, 1
%142 = zext i1 %141 to i32
%143 = add nuw nsw i32 %138, %142
%144 = getelementptr inbounds i32, i32* %133, i64 %127
%145 = load i32, i32* %144
%146 = icmp eq i32 %145, 1
%147 = zext i1 %146 to i32
%148 = add nuw nsw i32 %143, %147
%149 = load i32*, i32** %108
%150 = getelementptr inbounds i32, i32* %149, i64 %122
%151 = load i32, i32* %150
%152 = icmp eq i32 %151, 1
%153 = zext i1 %152 to i32
%154 = add nuw nsw i32 %148, %153
%155 = getelementptr inbounds i32, i32* %149, i64 %111
%156 = load i32, i32* %155
%157 = icmp eq i32 %156, 1
%158 = zext i1 %157 to i32
%159 = add nuw nsw i32 %154, %158
%160 = getelementptr inbounds i32, i32* %149, i64 %127
%161 = load i32, i32* %160
%162 = icmp eq i32 %161, 1
%163 = zext i1 %162 to i32
%164 = add nuw nsw i32 %159, %163
%165 = getelementptr inbounds i32, i32* %120, i64 %111
%166 = load i32, i32* %165
%167 = icmp eq i32 %166, 0
br i1 %167, label %168, label %171
168: ; preds = %110
%169 = tail call i32 @putchar(i32 45)
%170 = icmp eq i32 %164, 3
br i1 %170, label %178, label %182
171: ; preds = %110
%172 = tail call i32 @putchar(i32 79)
%173 = add nsw i32 %164, -4
%174 = icmp ult i32 %173, -2
br i1 %174, label %178, label %175
175: ; preds = %171
%176 = and i32 %164, -2
%177 = icmp eq i32 %176, 2
br i1 %177, label %178, label %182
178: ; preds = %175, %171, %168
%179 = phi i32 [ 1, %168 ], [ 0, %171 ], [ 1, %175 ]
%180 = load i32*, i32** %109
%181 = getelementptr inbounds i32, i32* %180, i64 %111
store i32 %179, i32* %181
br label %182
182: ; preds = %178, %175, %168
%183 = icmp eq i64 %112, %87
br i1 %183, label %184, label %110
184: ; preds = %182
%185 = tail call i32 @putchar(i32 10)
%186 = icmp eq i64 %95, %88
br i1 %186, label %187, label %93
187: ; preds = %184, %187
%188 = phi i64 [ %194, %187 ], [ 0, %184 ]
%189 = getelementptr inbounds i32*, i32** %34, i64 %188
%190 = load i32*, i32** %189
%191 = getelementptr inbounds i32*, i32** %37, i64 %188
%192 = load i32*, i32** %191
%193 = tail call i32 @memcpy(i32* %190, i32* %192, i32 %86)
%194 = add nuw nsw i64 %188, 1
%195 = icmp eq i64 %194, %88
br i1 %195, label %196, label %187
196: ; preds = %187
%197 = add nuw nsw i32 %90, 1
%198 = tail call i32 @putchar(i32 10)
%199 = tail call i32 @sleep(i32 1)
%200 = icmp eq i32 %197, %19
br i1 %200, label %201, label %89
201: ; preds = %196
%202 = tail call i32 @free2d(i32** %34, i32 %13)
%203 = tail call i32 @free2d(i32** %37, i32 %13)
br label %204
204: ; preds = %23, %28, %201, %75, %4
%205 = phi i32 [ -1, %4 ], [ -1, %23 ], [ -1, %28 ], [ 0, %201 ], [ -1, %75 ]
ret i32 %205
}