#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 alive(int *, int);
int /*<<< orphan*/ copy_array(int *, int *, int);
int /*<<< orphan*/ next_generation(int *, int *, int);
int /*<<< orphan*/ print(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i, count = 0, is_alive;
  scanf("%d", &n);
  int current[n], next[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &current[i]);
  }
  do {
    print(current, n);
    next_generation(current, next, n);
    printf("\n");
    copy_array(next, current, n);
    count++;
    is_alive = alive(next, n);
  } while (count < 1000 && is_alive == 1);
  print(current, n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe83(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1209 <main+0xa9>
mov    -0x40(%rbp),%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe0a(%rip),%rdi
call   1070 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d4 <main+0x74>
jmp    120e <main+0xae>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <print@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <next_generation@plt>
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%edx
call   1060 <copy_array@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
call   1080 <alive@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x3e8,-0x10(%rbp)
mov    %al,-0x41(%rbp)
jge    127a <main+0x11a>
cmpl   $0x1,-0x14(%rbp)
sete   %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    120e <main+0xae>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <print@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe88(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1070 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%esi
mov    %rsp,%r12
lea    0xf(,%rsi,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
test   %esi,%esi
jle    11f0 <main+0x90>
mov    %r15,-0x38(%rbp)
xor    %r13d,%r13d
lea    0xe3a(%rip),%r15
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rsi
add    $0x4,%rbx
cmp    %rsi,%r13
jl     11d0 <main+0x70>
mov    -0x38(%rbp),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <print@plt>
mov    -0x2c(%rbp),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <next_generation@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    -0x2c(%rbp),%edx
mov    %r12,%rdi
mov    %r14,%rsi
call   1060 <copy_array@plt>
mov    -0x2c(%rbp),%esi
mov    %r12,%rdi
call   1080 <alive@plt>
cmp    $0x3e6,%ebx
ja     124e <main+0xee>
cmp    $0x1,%eax
jne    124e <main+0xee>
add    $0x1,%ebx
mov    -0x2c(%rbp),%esi
jmp    1200 <main+0xa0>
mov    -0x2c(%rbp),%esi
mov    %r14,%rdi
call   1050 <print@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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