#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__ is_alive(int *, int);
int /*<<< orphan*/ next_generation(int *, int *, int);
int /*<<< orphan*/ print_generation(int *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int current[20], next[20], n, length;
  scanf("%d", &n);
  if (n <= 0) {
    return 0;
  } else if (n > 20) {
    n = 20;
  }
  length = n;
  while (n > 0) {
    scanf("%d", &current[length - n]);
    n--;
  }
  print_generation(current, length);
  if (is_alive(current, length)) {
    do {
      n++;
      next_generation(current, next, length);
      print_generation(next, length);
    } while (n < 999 && is_alive(next, length));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0xb4(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0xb4(%rbp)
jg     117e <main+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    12a1 <main+0x161>
cmpl   $0x14,-0xb4(%rbp)
jle    1195 <main+0x55>
movl   $0x14,-0xb4(%rbp)
jmp    119a <main+0x5a>
mov    -0xb4(%rbp),%eax
mov    %eax,-0xb8(%rbp)
cmpl   $0x0,-0xb4(%rbp)
jle    11ec <main+0xac>
mov    -0xb8(%rbp),%eax
sub    -0xb4(%rbp),%eax
cltq
lea    -0x60(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe2d(%rip),%rdi
call   1060 <scanf@plt>
mov    -0xb4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xb4(%rbp)
jmp    11a6 <main+0x66>
lea    -0x60(%rbp),%rdi
mov    -0xb8(%rbp),%esi
call   1050 <print_generation@plt>
lea    -0x60(%rbp),%rdi
mov    -0xb8(%rbp),%esi
call   1040 <is_alive@plt>
cmp    $0x0,%rax
je     129a <main+0x15a>
jmp    1219 <main+0xd9>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0xb8(%rbp),%edx
call   1030 <next_generation@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb8(%rbp),%esi
call   1050 <print_generation@plt>
xor    %eax,%eax
cmpl   $0x3e7,-0xb4(%rbp)
mov    %al,-0xb9(%rbp)
jge    1287 <main+0x147>
lea    -0xb0(%rbp),%rdi
mov    -0xb8(%rbp),%esi
call   1040 <is_alive@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xb9(%rbp)
mov    -0xb9(%rbp),%al
test   $0x1,%al
jne    1219 <main+0xd9>
jmp    129a <main+0x15a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xb0,%rsp
lea    0xead(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
jle    1215 <main+0xd5>
cmp    $0x15,%ebx
jb     117b <main+0x3b>
movl   $0x14,0xc(%rsp)
mov    $0x14,%ebx
lea    0xe7e(%rip),%r14
mov    %ebx,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%ecx
sub    %eax,%ecx
movslq %ecx,%rax
lea    (%rsp,%rax,4),%rsi
add    $0x10,%rsi
mov    %r14,%rdi
call   1060 <scanf@plt>
mov    0xc(%rsp),%ecx
lea    -0x1(%rcx),%eax
mov    %eax,0xc(%rsp)
cmp    $0x1,%ecx
jg     1190 <main+0x50>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <print_generation@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <is_alive@plt>
test   %rax,%rax
je     1215 <main+0xd5>
lea    0x10(%rsp),%r14
lea    0x60(%rsp),%r15
nop
addl   $0x1,0xc(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <next_generation@plt>
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <print_generation@plt>
cmpl   $0x3e6,0xc(%rsp)
jg     1215 <main+0xd5>
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <is_alive@plt>
test   %rax,%rax
jne    11e0 <main+0xa0>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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