#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*/ next_generation(int *, int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int currentGen[20], nextGen[20], n, i, c, ok;
  scanf("%d", &n);
  if (n < 0 || n > 20) {
    printf("Input error. The length of the cell chain must be a number between "
           "0 and 20.\n");
    return 0;
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &currentGen[i]);
    if (currentGen[i] != 0 && currentGen[i] != 1) {
      printf("Input error. Numbers in the cell chain must be only 1 or 0.\n");
      return 0;
    }
  }
  if (currentGen[0] != 0 || currentGen[n - 1] != 0) {
    printf("Input error. Cell chain must start and end with 0.\n");
    return 0;
  }
  for (i = 0; i < n; i++) {
    if (currentGen[i] == 0)
      printf(".");
    else if (currentGen[i] == 1)
      printf("*");
  }
  nextGen[0] = 0;
  nextGen[n - 1] = 0;
  for (i = 0; i < 999 && ok != n; i++) {
    next_generation(currentGen, nextGen, n);
    for (c = 0, ok = 0; c < n; c++) {
      if (currentGen[c] == 0)
        ok++;
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0xb4(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xb4(%rbp)
jl     116f <main+0x3f>
cmpl   $0x14,-0xb4(%rbp)
jle    1187 <main+0x57>
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13d5 <main+0x2a5>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    1216 <main+0xe6>
movslq -0xb8(%rbp),%rax
lea    -0x60(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe44(%rip),%rdi
call   1050 <scanf@plt>
movslq -0xb8(%rbp),%rax
cmpl   $0x0,-0x60(%rbp,%rax,4)
je     11fd <main+0xcd>
movslq -0xb8(%rbp),%rax
cmpl   $0x1,-0x60(%rbp,%rax,4)
je     11fd <main+0xcd>
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13d5 <main+0x2a5>
jmp    1202 <main+0xd2>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1191 <main+0x61>
cmpl   $0x0,-0x60(%rbp)
jne    1236 <main+0x106>
mov    -0xb4(%rbp),%eax
sub    $0x1,%eax
cltq
cmpl   $0x0,-0x60(%rbp,%rax,4)
je     124e <main+0x11e>
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13d5 <main+0x2a5>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    12c9 <main+0x199>
movslq -0xb8(%rbp),%rax
cmpl   $0x0,-0x60(%rbp,%rax,4)
jne    128d <main+0x15d>
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
jmp    12b0 <main+0x180>
movslq -0xb8(%rbp),%rax
cmpl   $0x1,-0x60(%rbp,%rax,4)
jne    12ab <main+0x17b>
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
jmp    12b0 <main+0x180>
jmp    12b5 <main+0x185>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1258 <main+0x128>
movl   $0x0,-0xb0(%rbp)
mov    -0xb4(%rbp),%eax
sub    $0x1,%eax
cltq
movl   $0x0,-0xb0(%rbp,%rax,4)
movl   $0x0,-0xb8(%rbp)
xor    %eax,%eax
cmpl   $0x3e7,-0xb8(%rbp)
mov    %al,-0xc1(%rbp)
jge    1320 <main+0x1f0>
mov    -0xc0(%rbp),%eax
cmp    -0xb4(%rbp),%eax
setne  %al
mov    %al,-0xc1(%rbp)
mov    -0xc1(%rbp),%al
test   $0x1,%al
jne    1333 <main+0x203>
jmp    13c2 <main+0x292>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0xb4(%rbp),%edx
call   1030 <next_generation@plt>
movl   $0x0,-0xbc(%rbp)
movl   $0x0,-0xc0(%rbp)
mov    -0xbc(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    13a9 <main+0x279>
movslq -0xbc(%rbp),%rax
cmpl   $0x0,-0x60(%rbp,%rax,4)
jne    1390 <main+0x260>
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
jmp    1395 <main+0x265>
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    135d <main+0x22d>
jmp    13ae <main+0x27e>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    12f3 <main+0x1c3>
lea    0xcf7(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xec0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x14,%eax
jbe    1164 <main+0x34>
lea    0xf18(%rip),%rdi
call   1040 <puts@plt>
jmp    122c <main+0xfc>
test   %eax,%eax
je     11ab <main+0x7b>
lea    0x10(%rsp),%rbx
xor    %r15d,%r15d
lea    0xe89(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmpl   $0x2,(%rbx)
jae    11c5 <main+0x95>
add    $0x1,%r15
movslq 0xc(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%r15
jl     1180 <main+0x50>
cmpl   $0x0,0x10(%rsp)
jne    11b7 <main+0x87>
jmp    11ad <main+0x7d>
xor    %eax,%eax
movslq %eax,%rcx
cmpl   $0x0,0xc(%rsp,%rcx,4)
je     11d3 <main+0xa3>
lea    0xe45(%rip),%rdi
call   1040 <puts@plt>
jmp    122c <main+0xfc>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
jmp    122c <main+0xfc>
test   %eax,%eax
jle    1222 <main+0xf2>
xor    %eax,%eax
mov    $0x1,%ebx
test   %eax,%eax
je     1200 <main+0xd0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x1,%eax
jne    120a <main+0xda>
mov    $0x2a,%edi
jmp    1205 <main+0xd5>
nopl   0x0(%rax)
mov    $0x2e,%edi
call   1030 <putchar@plt>
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jge    1222 <main+0xf2>
mov    0x10(%rsp,%rbx,4),%eax
add    $0x1,%rbx
test   %eax,%eax
jne    11f0 <main+0xc0>
jmp    1200 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [78 x i8] c"Input error. The length of the cell chain must be a number between 0 and 20.\0A\00"
@.str.2 = [61 x i8] c"Input error. Numbers in the cell chain must be only 1 or 0.\0A\00"
@.str.3 = [52 x i8] c"Input error. Cell chain must start and end with 0.\0A\00"
@.str.4 = [2 x i8] c".\00"
@.str.5 = [2 x i8] c"*\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca [20 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 20
br i1 %13, label %14, label %16
14: ; preds = %11, %0
%15 = call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %125
16: ; preds = %11
store i32 0, i32* %5
br label %17
17: ; preds = %40, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [20 x i32], [20 x i32]* %2, 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]* %2, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %21
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = icmp ne i32 %35, 1
br i1 %36, label %37, label %39
37: ; preds = %31
%38 = call i32 @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %125
39: ; preds = %31, %21
br label %40
40: ; preds = %39
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %17
43: ; preds = %17
%44 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%45 = load i32, i32* %44
%46 = icmp ne i32 %45, 0
br i1 %46, label %54, label %47
47: ; preds = %43
%48 = load i32, i32* %4
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %47, %43
%55 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %125
56: ; preds = %47
store i32 0, i32* %5
br label %57
57: ; preds = %79, %56
%58 = load i32, i32* %5
%59 = load i32, i32* %4
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %82
61: ; preds = %57
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = icmp eq i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %78
69: ; preds = %61
%70 = load i32, i32* %5
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %71
%73 = load i32, i32* %72
%74 = icmp eq i32 %73, 1
br i1 %74, label %75, label %77
75: ; preds = %69
%76 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %77
77: ; preds = %75, %69
br label %78
78: ; preds = %77, %67
br label %79
79: ; preds = %78
%80 = load i32, i32* %5
%81 = add nsw i32 %80, 1
store i32 %81, i32* %5
br label %57
82: ; preds = %57
%83 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
store i32 0, i32* %83
%84 = load i32, i32* %4
%85 = sub nsw i32 %84, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %86
store i32 0, i32* %87
store i32 0, i32* %5
br label %88
88: ; preds = %120, %82
%89 = load i32, i32* %5
%90 = icmp slt i32 %89, 999
br i1 %90, label %91, label %95
91: ; preds = %88
%92 = load i32, i32* %7
%93 = load i32, i32* %4
%94 = icmp ne i32 %92, %93
br label %95
95: ; preds = %91, %88
%96 = phi i1 [ false, %88 ], [ %94, %91 ]
br i1 %96, label %97, label %123
97: ; preds = %95
%98 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%99 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%100 = load i32, i32* %4
%101 = call i32 @next_generation(i32* %98, i32* %99, i32 %100)
store i32 0, i32* %6
store i32 0, i32* %7
br label %102
102: ; preds = %116, %97
%103 = load i32, i32* %6
%104 = load i32, i32* %4
%105 = icmp slt i32 %103, %104
br i1 %105, label %106, label %119
106: ; preds = %102
%107 = load i32, i32* %6
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %108
%110 = load i32, i32* %109
%111 = icmp eq i32 %110, 0
br i1 %111, label %112, label %115
112: ; preds = %106
%113 = load i32, i32* %7
%114 = add nsw i32 %113, 1
store i32 %114, i32* %7
br label %115
115: ; preds = %112, %106
br label %116
116: ; preds = %115
%117 = load i32, i32* %6
%118 = add nsw i32 %117, 1
store i32 %118, i32* %6
br label %102
119: ; preds = %102
br label %120
120: ; preds = %119
%121 = load i32, i32* %5
%122 = add nsw i32 %121, 1
store i32 %122, i32* %5
br label %88
123: ; preds = %95
%124 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %1
br label %125
125: ; preds = %123, %54, %37, %14
%126 = load i32, i32* %1
ret i32 %126
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [51 x i8] c"Input error. Cell chain must start and end with 0.\00"
@str.7 = [60 x i8] c"Input error. Numbers in the cell chain must be only 1 or 0.\00"
@str.8 = [77 x i8] c"Input error. The length of the cell chain must be a number between 0 and 20.\00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca i32
%3 = bitcast [20 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = load i32, i32* %2
%7 = icmp ugt i32 %6, 20
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = icmp eq i32 %6, 0
br i1 %9, label %29, label %16
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str.8, i64 0, i64 0))
br label %57
12: ; preds = %16
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = icmp slt i64 %22, %14
br i1 %15, label %16, label %25
16: ; preds = %8, %12
%17 = phi i64 [ %22, %12 ], [ 0, %8 ]
%18 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %17
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %18)
%20 = load i32, i32* %18
%21 = icmp ult i32 %20, 2
%22 = add nuw nsw i64 %17, 1
br i1 %21, label %12, label %23
23: ; preds = %16
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @str.7, i64 0, i64 0))
br label %57
25: ; preds = %12
%26 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %8, %25
%30 = phi i32 [ %13, %25 ], [ 0, %8 ]
%31 = add nsw i32 %30, -1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = icmp sgt i32 %30, 0
br i1 %37, label %40, label %55
38: ; preds = %29, %25
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %57
40: ; preds = %36, %52
%41 = phi i32 [ %54, %52 ], [ 0, %36 ]
%42 = phi i64 [ %48, %52 ], [ 0, %36 ]
switch i32 %41, label %47 [
i32 0, label %44
i32 1, label %43
]
43: ; preds = %40
br label %44
44: ; preds = %40, %43
%45 = phi i32 [ 42, %43 ], [ 46, %40 ]
%46 = call i32 @putchar(i32 %45)
br label %47
47: ; preds = %44, %40
%48 = add nuw nsw i64 %42, 1
%49 = load i32, i32* %2
%50 = sext i32 %49 to i64
%51 = icmp slt i64 %48, %50
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %48
%54 = load i32, i32* %53
br label %40
55: ; preds = %47, %36
%56 = call i32 @putchar(i32 10)
br label %57
57: ; preds = %55, %38, %23, %10
ret i32 0
}