#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 length, n, current[20], next[20], countforZeros, i, j;
  scanf("%d", &length);
  if (length > 20) {
    printf("Length should be max 20!");
    return 1;
  }
  if (length <= 0) {
    printf("Length should be 1 at least!");
    return 1;
  }
  for (i = 0; i < length; i++) {
    scanf("%d", &n);
    if (n == 0 || n == 1) {
      if ((i == 0 || i == (length - 1)) && n == 1) {
        printf("\nFirst and last cell should always be 0!");
        return 1;
      }
      current[i] = n;
    } else {
      printf("\nExpected 0 or 1!");
      return 1;
    }
  }
  for (i = 0; i < 1000; i++) {
    countforZeros = 0;
    for (j = 0; j < length; j++) {
      if (current[j] == 0) {
        countforZeros++;
        printf(".");
      } else
        printf("*");
    }
    printf("\n");
    if (countforZeros == length)
      break;
    next_generation(current, next, length);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x14,-0x8(%rbp)
jle    1174 <main+0x44>
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133c <main+0x20c>
cmpl   $0x0,-0x8(%rbp)
jg     1196 <main+0x66>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133c <main+0x20c>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    125a <main+0x12a>
lea    0xe4a(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
je     11d3 <main+0xa3>
cmpl   $0x1,-0xc(%rbp)
jne    1229 <main+0xf9>
cmpl   $0x0,-0xb8(%rbp)
je     11f4 <main+0xc4>
mov    -0xb8(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1216 <main+0xe6>
cmpl   $0x1,-0xc(%rbp)
jne    1216 <main+0xe6>
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133c <main+0x20c>
mov    -0xc(%rbp),%ecx
movslq -0xb8(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
jmp    1241 <main+0x111>
lea    0xe32(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133c <main+0x20c>
jmp    1246 <main+0x116>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    11a0 <main+0x70>
movl   $0x0,-0xb8(%rbp)
cmpl   $0x3e8,-0xb8(%rbp)
jge    1335 <main+0x205>
movl   $0x0,-0xb4(%rbp)
movl   $0x0,-0xbc(%rbp)
mov    -0xbc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ee <main+0x1be>
movslq -0xbc(%rbp),%rax
cmpl   $0x0,-0x60(%rbp,%rax,4)
jne    12c9 <main+0x199>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
lea    0xdb5(%rip),%rdi
call   1040 <printf@plt>
jmp    12d5 <main+0x1a5>
lea    0xda6(%rip),%rdi
call   1040 <printf@plt>
jmp    12da <main+0x1aa>
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    1288 <main+0x158>
lea    0xd83(%rip),%rdi
call   1040 <printf@plt>
mov    -0xb4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    130e <main+0x1de>
jmp    1335 <main+0x205>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <next_generation@plt>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1264 <main+0x134>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb0,%rsp
lea    0xeaa(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%eax
cmp    $0x14,%eax
jle    1175 <main+0x35>
lea    0xe93(%rip),%r14
jmp    11f7 <main+0xb7>
test   %eax,%eax
jle    11eb <main+0xab>
xor    %ebp,%ebp
lea    0xe7e(%rip),%r15
lea    0xc(%rsp),%rbx
lea    0xed4(%rip),%r14
lea    0xea4(%rip),%r12
jmp    11b0 <main+0x70>
nopw   0x0(%rax,%rax,1)
mov    %ecx,0x10(%rsp,%rbp,4)
add    $0x1,%rbp
movslq %eax,%rcx
cmp    %rcx,%rbp
jge    1216 <main+0xd6>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%ecx
cmp    $0x1,%ecx
ja     11f7 <main+0xb7>
test   %rbp,%rbp
je     11e0 <main+0xa0>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%edx
cmp    %rdx,%rbp
jne    11a0 <main+0x60>
cmp    $0x1,%ecx
jne    11a0 <main+0x60>
jmp    11f4 <main+0xb4>
nopl   0x0(%rax)
cmp    $0x1,%ecx
je     11f4 <main+0xb4>
mov    0x8(%rsp),%eax
jmp    11a0 <main+0x60>
lea    0xe2a(%rip),%r14
jmp    11f7 <main+0xb7>
mov    %r12,%r14
mov    %r14,%rdi
call   1050 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
lea    0x10(%rsp),%r14
lea    0x60(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x0,%ebx
test   %eax,%eax
jle    1266 <main+0x126>
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
cmpl   $0x0,0x10(%rsp,%rbp,4)
sete   %al
lea    0x2a(,%rax,4),%edi
add    %eax,%ebx
call   1040 <putchar@plt>
add    $0x1,%rbp
movslq 0x8(%rsp),%rax
cmp    %rax,%rbp
jl     1240 <main+0x100>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0x8(%rsp),%edx
xor    %ebp,%ebp
cmp    %edx,%ebx
je     1204 <main+0xc4>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <next_generation@plt>
add    $0x1,%r12d
cmp    $0x3e8,%r12d
je     1204 <main+0xc4>
mov    0x8(%rsp),%eax
jmp    1230 <main+0xf0>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [25 x i8] c"Length should be max 20!\00"
@.str.2 = [29 x i8] c"Length should be 1 at least!\00"
@.str.3 = [41 x i8] c"\0AFirst and last cell should always be 0!\00"
@.str.4 = [18 x i8] c"\0AExpected 0 or 1!\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [2 x i8] c"*\00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [20 x i32]
%5 = alloca [20 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%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 = icmp sgt i32 %10, 20
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %95
14: ; preds = %0
%15 = load i32, i32* %2
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %95
19: ; preds = %14
store i32 0, i32* %7
br label %20
20: ; preds = %52, %19
%21 = load i32, i32* %7
%22 = load i32, i32* %2
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %55
24: ; preds = %20
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %49
31: ; preds = %28, %24
%32 = load i32, i32* %7
%33 = icmp eq i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %31
%35 = load i32, i32* %7
%36 = load i32, i32* %2
%37 = sub nsw i32 %36, 1
%38 = icmp eq i32 %35, %37
br i1 %38, label %39, label %44
39: ; preds = %34, %31
%40 = load i32, i32* %3
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %95
44: ; preds = %39, %34
%45 = load i32, i32* %3
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %47
store i32 %45, i32* %48
br label %51
49: ; preds = %28
%50 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %95
51: ; preds = %44
br label %52
52: ; preds = %51
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %20
55: ; preds = %20
store i32 0, i32* %7
br label %56
56: ; preds = %91, %55
%57 = load i32, i32* %7
%58 = icmp slt i32 %57, 1000
br i1 %58, label %59, label %94
59: ; preds = %56
store i32 0, i32* %6
store i32 0, i32* %8
br label %60
60: ; preds = %77, %59
%61 = load i32, i32* %8
%62 = load i32, i32* %2
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %80
64: ; preds = %60
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %66
%68 = load i32, i32* %67
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %64
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
%73 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %76
74: ; preds = %64
%75 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %76
76: ; preds = %74, %70
br label %77
77: ; preds = %76
%78 = load i32, i32* %8
%79 = add nsw i32 %78, 1
store i32 %79, i32* %8
br label %60
80: ; preds = %60
%81 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%82 = load i32, i32* %6
%83 = load i32, i32* %2
%84 = icmp eq i32 %82, %83
br i1 %84, label %85, label %86
85: ; preds = %80
br label %94
86: ; preds = %80
%87 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%88 = getelementptr inbounds [20 x i32], [20 x i32]* %5, i64 0, i64 0
%89 = load i32, i32* %2
%90 = call i32 @next_generation(i32* %87, i32* %88, i32 %89)
br label %91
91: ; preds = %86
%92 = load i32, i32* %7
%93 = add nsw i32 %92, 1
store i32 %93, i32* %7
br label %56
94: ; preds = %85, %56
store i32 0, i32* %1
br label %95
95: ; preds = %94, %49, %42, %17, %12
%96 = load i32, i32* %1
ret i32 %96
}

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