#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, j, temp;
  do {
    printf("Enter length for the cell chain(you can only use a number between "
           "0 and 20):\n");
    scanf("%d", &n);
  } while (n < 0 || n > 20);
  for (i = 0; i < n; i++) {
    do {
      printf("Enter a number(you can only use 1 or 0):\n");
      scanf("%d", &currentGen[i]);
    } while (currentGen[i] != 0 && currentGen[i] != 1);
  }
  if (currentGen[0] != 0 || currentGen[n - 1] != 0) {
    printf("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 && temp != n; i++) {
    next_generation(currentGen, nextGen, n);
    for (j = 0, temp = 0; j < n; j++) {
      if (currentGen[j] == 0)
        temp++;
    }
  }
  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
call   1040 <printf@plt>
lea    0xef9(%rip),%rdi
lea    -0xb4(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x1,%al
cmpl   $0x0,-0xb4(%rbp)
mov    %al,-0xc1(%rbp)
jl     1186 <main+0x56>
cmpl   $0x14,-0xb4(%rbp)
setg   %al
mov    %al,-0xc1(%rbp)
mov    -0xc1(%rbp),%al
test   $0x1,%al
jne    1142 <main+0x12>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    1235 <main+0x105>
jmp    11b5 <main+0x85>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
movslq -0xb8(%rbp),%rax
lea    -0x60(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe74(%rip),%rdi
call   1050 <scanf@plt>
movslq -0xb8(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x0,-0x60(%rbp,%rcx,4)
mov    %al,-0xc2(%rbp)
je     120e <main+0xde>
movslq -0xb8(%rbp),%rax
cmpl   $0x1,-0x60(%rbp,%rax,4)
setne  %al
mov    %al,-0xc2(%rbp)
mov    -0xc2(%rbp),%al
test   $0x1,%al
jne    11b5 <main+0x85>
jmp    1221 <main+0xf1>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    119e <main+0x6e>
cmpl   $0x0,-0x60(%rbp)
jne    1255 <main+0x125>
mov    -0xb4(%rbp),%eax
sub    $0x1,%eax
cltq
cmpl   $0x0,-0x60(%rbp,%rax,4)
je     126d <main+0x13d>
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f4 <main+0x2c4>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    12e8 <main+0x1b8>
movslq -0xb8(%rbp),%rax
cmpl   $0x0,-0x60(%rbp,%rax,4)
jne    12ac <main+0x17c>
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
jmp    12cf <main+0x19f>
movslq -0xb8(%rbp),%rax
cmpl   $0x1,-0x60(%rbp,%rax,4)
jne    12ca <main+0x19a>
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
jmp    12cf <main+0x19f>
jmp    12d4 <main+0x1a4>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1277 <main+0x147>
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,-0xc3(%rbp)
jge    133f <main+0x20f>
mov    -0xc0(%rbp),%eax
cmp    -0xb4(%rbp),%eax
setne  %al
mov    %al,-0xc3(%rbp)
mov    -0xc3(%rbp),%al
test   $0x1,%al
jne    1352 <main+0x222>
jmp    13e1 <main+0x2b1>
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    13c8 <main+0x298>
movslq -0xbc(%rbp),%rax
cmpl   $0x0,-0x60(%rbp,%rax,4)
jne    13af <main+0x27f>
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
jmp    13b4 <main+0x284>
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    137c <main+0x24c>
jmp    13cd <main+0x29d>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1312 <main+0x1e2>
lea    0xcbf(%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   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xec1(%rip),%r14
lea    0xeb7(%rip),%r15
lea    0xc(%rsp),%rbx
xchg   %ax,%ax
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x14,%eax
ja     1150 <main+0x20>
test   %eax,%eax
je     11cf <main+0x9f>
xor    %r12d,%r12d
lea    0xf03(%rip),%r14
lea    0xe7f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%rsp,%r12,4),%rbx
add    $0x10,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmpl   $0x1,(%rbx)
ja     11a0 <main+0x70>
add    $0x1,%r12
movslq 0xc(%rsp),%rax
cmp    %rax,%r12
jl     1190 <main+0x60>
cmpl   $0x0,0x10(%rsp)
jne    11db <main+0xab>
jmp    11d1 <main+0xa1>
xor    %eax,%eax
movslq %eax,%rcx
cmpl   $0x0,0xc(%rsp,%rcx,4)
je     11e9 <main+0xb9>
lea    0xe6e(%rip),%rdi
call   1040 <puts@plt>
jmp    123c <main+0x10c>
test   %eax,%eax
jle    1232 <main+0x102>
xor    %eax,%eax
mov    $0x1,%ebx
test   %eax,%eax
je     1210 <main+0xe0>
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%eax
jne    121a <main+0xea>
mov    $0x2a,%edi
jmp    1215 <main+0xe5>
nopl   0x0(%rax)
mov    $0x2e,%edi
call   1030 <putchar@plt>
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jge    1232 <main+0x102>
mov    0x10(%rsp,%rbx,4),%eax
add    $0x1,%rbx
test   %eax,%eax
jne    1200 <main+0xd0>
jmp    1210 <main+0xe0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [77 x i8] c"Enter length for the cell chain(you can only use a number between 0 and 20):\00"
@str.7 = [45 x i8] c"Error! Cell chain must start and end with 0.\00"
@str.8 = [41 x i8] c"Enter a number(you can only use 1 or 0):\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*
br label %5
5: ; preds = %5, %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = icmp ugt i32 %8, 20
br i1 %9, label %5, label %10
10: ; preds = %5
%11 = icmp eq i32 %8, 0
br i1 %11, label %29, label %12
12: ; preds = %10, %20
%13 = phi i64 [ %21, %20 ], [ 0, %10 ]
%14 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %13
br label %15
15: ; preds = %12, %15
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.8, i64 0, i64 0))
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%18 = load i32, i32* %14
%19 = icmp ult i32 %18, 2
br i1 %19, label %20, label %15
20: ; preds = %15
%21 = add nuw nsw i64 %13, 1
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %12, label %25
25: ; preds = %20
%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 = %10, %25
%30 = phi i32 [ %22, %25 ], [ 0, %10 ]
%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 ([45 x i8], [45 x i8]* @str.7, 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
ret i32 0
}