#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 */
scalar_t__ checkForLiving(int *, int);
int /*<<< orphan*/ next_generation(int *, int *, int);
int /*<<< orphan*/ printGeneration(int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, curGen[20], nextGen[20], i;
  do {
    scanf("%d", &n);
  } while (n < 0 && n > 20);
  i = 0;
  while (i < n) {
    scanf("%d", &curGen[i]);
    if (curGen[i] != 0 && curGen[i] != 1) {
      continue;
    }
    i++;
  }
  i = 0;
  printGeneration(curGen, n);
  do {
    next_generation(curGen, nextGen, n);
    printGeneration(curGen, n);
  } while (i < 1000 && checkForLiving(nextGen, n));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0xb5(%rbp)
jge    1181 <main+0x41>
cmpl   $0x14,-0x8(%rbp)
setg   %al
mov    %al,-0xb5(%rbp)
mov    -0xb5(%rbp),%al
test   $0x1,%al
jne    1152 <main+0x12>
movl   $0x0,-0xb4(%rbp)
mov    -0xb4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1203 <main+0xc3>
movslq -0xb4(%rbp),%rax
lea    -0x60(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe3f(%rip),%rdi
call   1060 <scanf@plt>
movslq -0xb4(%rbp),%rax
cmpl   $0x0,-0x60(%rbp,%rax,4)
je     11ef <main+0xaf>
movslq -0xb4(%rbp),%rax
cmpl   $0x1,-0x60(%rbp,%rax,4)
je     11ef <main+0xaf>
jmp    1199 <main+0x59>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    1199 <main+0x59>
movl   $0x0,-0xb4(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <printGeneration@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <next_generation@plt>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <printGeneration@plt>
xor    %eax,%eax
cmpl   $0x3e8,-0xb4(%rbp)
mov    %al,-0xb6(%rbp)
jge    126c <main+0x12c>
lea    -0xb0(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <checkForLiving@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xb6(%rbp)
mov    -0xb6(%rbp),%al
test   $0x1,%al
jne    1219 <main+0xd9>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xb0,%rsp
lea    0xeae(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    1192 <main+0x52>
xor    %ebp,%ebp
lea    0xe93(%rip),%r14
nopl   (%rax)
mov    %ebp,%ebx
lea    (%rsp,%rbx,4),%rsi
add    $0x10,%rsi
mov    %r14,%rdi
call   1060 <scanf@plt>
cmpl   $0x2,0x10(%rsp,%rbx,4)
adc    $0x0,%ebp
mov    0xc(%rsp),%esi
cmp    %esi,%ebp
jl     1170 <main+0x30>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <printGeneration@plt>
lea    0x60(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xc(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <next_generation@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
call   1040 <printGeneration@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1050 <checkForLiving@plt>
test   %rax,%rax
jne    11b0 <main+0x70>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i32]
%4 = alloca [20 x i32]
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %14, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %6
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 20
br label %14
14: ; preds = %11, %8
%15 = phi i1 [ false, %8 ], [ %13, %11 ]
br i1 %15, label %6, label %16
16: ; preds = %14
store i32 0, i32* %5
br label %17
17: ; preds = %38, %37, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %41
21: ; preds = %17
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %23
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %24)
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %21
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %38
37: ; preds = %31
br label %17
38: ; preds = %31, %21
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %17
41: ; preds = %17
store i32 0, i32* %5
%42 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%43 = load i32, i32* %2
%44 = call i32 @printGeneration(i32* %42, i32 %43)
br label %45
45: ; preds = %61, %41
%46 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%47 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%48 = load i32, i32* %2
%49 = call i32 @next_generation(i32* %46, i32* %47, i32 %48)
%50 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%51 = load i32, i32* %2
%52 = call i32 @printGeneration(i32* %50, i32 %51)
br label %53
53: ; preds = %45
%54 = load i32, i32* %5
%55 = icmp slt i32 %54, 1000
br i1 %55, label %56, label %61
56: ; preds = %53
%57 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%58 = load i32, i32* %2
%59 = call i64 @checkForLiving(i32* %57, i32 %58)
%60 = icmp ne i64 %59, 0
br label %61
61: ; preds = %56, %53
%62 = phi i1 [ false, %53 ], [ %60, %56 ]
br i1 %62, label %45, label %63
63: ; preds = %61
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca [20 x i32]
%4 = bitcast i32* %1 to i8*
%5 = bitcast [20 x i32]* %2 to i8*
%6 = bitcast [20 x i32]* %3 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %0, %10
%11 = phi i32 [ %18, %10 ], [ 0, %0 ]
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %12
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %13)
%15 = load i32, i32* %13
%16 = icmp ult i32 %15, 2
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %11, %17
%19 = load i32, i32* %1
%20 = icmp slt i32 %18, %19
br i1 %20, label %10, label %21
21: ; preds = %10, %0
%22 = phi i32 [ %8, %0 ], [ %19, %10 ]
%23 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%24 = call i32 @printGeneration(i32* %23, i32 %22)
%25 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
br label %26
26: ; preds = %26, %21
%27 = load i32, i32* %1
%28 = call i32 @next_generation(i32* %23, i32* %25, i32 %27)
%29 = load i32, i32* %1
%30 = call i32 @printGeneration(i32* %23, i32 %29)
%31 = load i32, i32* %1
%32 = call i64 @checkForLiving(i32* %25, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %26
34: ; preds = %26
ret i32 0
}