#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*/ print_gen(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int Current[20], Next[20];
  int main_length, counter, n, main_counter;
  char check;
  do {
    scanf("%d", &main_length);
  } while (main_length >= 20 || main_length <= 0);
  for (counter = 0; counter < main_length; counter++) {
    scanf("%d", &n);
    if (n == 0 || n == 1) {
      Current[counter] = n;
    } else {
      printf("Only 0 or 1 !!!");
      return 1;
    }
  }
  if (Current[0] != 0 && Current[main_length - 1] != 0) {
    printf("\nFirst and final cell must be only 0 !!!\n");
    return 1;
  }
  for (counter = 0; counter < main_length; counter++) {
    if (Current[counter] == 0)
      printf(".");
    else if (Current[counter] == 1)
      printf("*");
  }
  printf("\n");
  for (counter = 0; counter < 20; counter++)
    Next[counter] = 0;
  for (main_counter = 1; main_counter <= 1000; main_counter++) {
    next_generation(Current, Next, main_length);
    print_gen(Next, main_length);
    for (counter = 0; counter < main_length; counter++) {
      if (Next[counter] == 1)
        check = 'a';
    }
    if (check != 'a')
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0xb4(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x1,%al
cmpl   $0x14,-0xb4(%rbp)
mov    %al,-0xc2(%rbp)
jge    118a <main+0x4a>
cmpl   $0x0,-0xb4(%rbp)
setle  %al
mov    %al,-0xc2(%rbp)
mov    -0xc2(%rbp),%al
test   $0x1,%al
jne    1152 <main+0x12>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    1228 <main+0xe8>
lea    0xe45(%rip),%rdi
lea    -0xbc(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xbc(%rbp)
je     11e1 <main+0xa1>
cmpl   $0x1,-0xbc(%rbp)
jne    11f7 <main+0xb7>
mov    -0xbc(%rbp),%ecx
movslq -0xb8(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
jmp    120f <main+0xcf>
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ec <main+0x2ac>
jmp    1214 <main+0xd4>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    11a2 <main+0x62>
cmpl   $0x0,-0x60(%rbp)
je     1260 <main+0x120>
mov    -0xb4(%rbp),%eax
sub    $0x1,%eax
cltq
cmpl   $0x0,-0x60(%rbp,%rax,4)
je     1260 <main+0x120>
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13ec <main+0x2ac>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    12db <main+0x19b>
movslq -0xb8(%rbp),%rax
cmpl   $0x0,-0x60(%rbp,%rax,4)
jne    129f <main+0x15f>
lea    0xda8(%rip),%rdi
call   1040 <printf@plt>
jmp    12c2 <main+0x182>
movslq -0xb8(%rbp),%rax
cmpl   $0x1,-0x60(%rbp,%rax,4)
jne    12bd <main+0x17d>
lea    0xd87(%rip),%rdi
call   1040 <printf@plt>
jmp    12c2 <main+0x182>
jmp    12c7 <main+0x187>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    126a <main+0x12a>
lea    0xd59(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0xb8(%rbp)
cmpl   $0x14,-0xb8(%rbp)
jge    1324 <main+0x1e4>
movslq -0xb8(%rbp),%rax
movl   $0x0,-0xb0(%rbp,%rax,4)
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    12f1 <main+0x1b1>
movl   $0x1,-0xc0(%rbp)
cmpl   $0x3e8,-0xc0(%rbp)
jg     13e5 <main+0x2a5>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0xb4(%rbp),%edx
call   1030 <next_generation@plt>
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
call   1060 <print_gen@plt>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    13b7 <main+0x277>
movslq -0xb8(%rbp),%rax
cmpl   $0x1,-0xb0(%rbp,%rax,4)
01
jne    139e <main+0x25e>
movb   $0x61,-0xc1(%rbp)
jmp    13a3 <main+0x263>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1370 <main+0x230>
movsbl -0xc1(%rbp),%eax
cmp    $0x61,%eax
je     13cc <main+0x28c>
jmp    13e5 <main+0x2a5>
jmp    13d1 <main+0x291>
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
jmp    132e <main+0x1ee>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xb8,%rsp
lea    0xe8c(%rip),%r14
lea    0x8(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%eax
add    $0xffffffec,%eax
cmp    $0xffffffed,%eax
jb     1180 <main+0x20>
xor    %ebx,%ebx
lea    0xe60(%rip),%r14
lea    0xc(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x1,%eax
ja     11fb <main+0x9b>
mov    %eax,0x60(%rsp,%rbx,4)
add    $0x1,%rbx
movslq 0x8(%rsp),%rcx
cmp    %rcx,%rbx
jl     11b0 <main+0x50>
mov    0x60(%rsp),%eax
test   %eax,%eax
je     1211 <main+0xb1>
cmpl   $0x0,0x5c(%rsp,%rcx,4)
je     1211 <main+0xb1>
lea    0xe27(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
jmp    12b2 <main+0x152>
lea    0xe01(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%eax
jmp    12b2 <main+0x152>
test   %ecx,%ecx
jle    1252 <main+0xf2>
mov    $0x1,%ebx
test   %eax,%eax
je     1230 <main+0xd0>
xchg   %ax,%ax
cmp    $0x1,%eax
jne    123a <main+0xda>
mov    $0x2a,%edi
jmp    1235 <main+0xd5>
nopl   0x0(%rax)
mov    $0x2e,%edi
call   1040 <putchar@plt>
movslq 0x8(%rsp),%rax
cmp    %rax,%rbx
jge    1252 <main+0xf2>
mov    0x60(%rsp,%rbx,4),%eax
add    $0x1,%rbx
test   %eax,%eax
jne    1220 <main+0xc0>
jmp    1230 <main+0xd0>
mov    $0xa,%edi
call   1040 <putchar@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
mov    $0x3e8,%ebp
lea    0x60(%rsp),%r14
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <next_generation@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1080 <print_gen@plt>
add    $0xffffffff,%ebp
jne    1290 <main+0x130>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [16 x i8] c"Only 0 or 1 !!!\00"
@str = [41 x i8] c"\0AFirst and final cell must be only 0 !!!\00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca [20 x i32]
%3 = bitcast [20 x i32]* %2 to i8*
%4 = alloca i32
%5 = alloca i32
%6 = bitcast [20 x i32]* %1 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
br label %9
9: ; preds = %9, %0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%11 = load i32, i32* %4
%12 = add i32 %11, -20
%13 = icmp ult i32 %12, -19
br i1 %13, label %9, label %14
14: ; preds = %9, %19
%15 = phi i64 [ %21, %19 ], [ 0, %9 ]
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%17 = load i32, i32* %5
%18 = icmp ult i32 %17, 2
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %15
store i32 %17, i32* %20
%21 = add nuw nsw i64 %15, 1
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %14, label %27
25: ; preds = %14
%26 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %68
27: ; preds = %19
%28 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%29 = load i32, i32* %28
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%31 = icmp eq i32 %29, 0
br i1 %31, label %40, label %32
32: ; preds = %27
%33 = add nsw i32 %22, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 0
br i1 %37, label %40, label %38
38: ; preds = %32
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %68
40: ; preds = %32, %27
%41 = icmp sgt i32 %22, 0
br i1 %41, label %42, label %57
42: ; preds = %40, %54
%43 = phi i32 [ %56, %54 ], [ %29, %40 ]
%44 = phi i64 [ %50, %54 ], [ 0, %40 ]
switch i32 %43, label %49 [
i32 0, label %46
i32 1, label %45
]
45: ; preds = %42
br label %46
46: ; preds = %42, %45
%47 = phi i32 [ 42, %45 ], [ 46, %42 ]
%48 = call i32 @putchar(i32 %47)
br label %49
49: ; preds = %46, %42
%50 = add nuw nsw i64 %44, 1
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = icmp slt i64 %50, %52
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %50
%56 = load i32, i32* %55
br label %42
57: ; preds = %49, %40
%58 = call i32 @putchar(i32 10)
%59 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
br label %60
60: ; preds = %57, %60
%61 = phi i32 [ 1, %57 ], [ %66, %60 ]
%62 = load i32, i32* %4
%63 = call i32 @next_generation(i32* %30, i32* %59, i32 %62)
%64 = load i32, i32* %4
%65 = call i32 @print_gen(i32* %59, i32 %64)
%66 = add nuw nsw i32 %61, 1
%67 = icmp eq i32 %66, 1001
br i1 %67, label %68, label %60
68: ; preds = %60, %38, %25
%69 = phi i32 [ 1, %25 ], [ 1, %38 ], [ 0, %60 ]
ret i32 %69
}