#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 */
char getchar();
int /*<<< orphan*/ next_generation(int *, int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  char ch;
  int entered[20], generated[20], n, i = 0, death_count = 0, loop = 0;
  do {
    printf("n=");
    scanf("%d", &n);
  } while (n <= 0 || n >= 20);
  while (1) {
    ch = getchar();
    if (ch == '1') {
      entered[i] = 1;
      i++;
    }
    if (ch == '0') {
      entered[i] = 0;
      i++;
    }
    if (i >= n) {
      break;
    }
  }
  printf("\n");
  for (i = 0; i < n; i++) {
    if (entered[i] == 0) {
      printf(".");
    } else {
      printf("*");
    }
  }
  printf("\n");
  do {
    next_generation(entered, generated, n);
    death_count = 0;
    for (i = 0; i < n; i++) {
      if (generated[i] == 0) {
        death_count++;
        printf(".");
      } else {
        printf("*");
      }
      entered[i] = generated[i];
    }
    printf("\n");
    loop++;
  } while (death_count != n && loop < 1000);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xb8(%rbp)
movl   $0x0,-0xbc(%rbp)
movl   $0x0,-0xc0(%rbp)
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
lea    0xe80(%rip),%rdi
lea    -0xb4(%rbp),%rsi
call   1060 <scanf@plt>
mov    $0x1,%al
cmpl   $0x0,-0xb4(%rbp)
mov    %al,-0xc1(%rbp)
jle    11b4 <main+0x74>
cmpl   $0x14,-0xb4(%rbp)
setge  %al
mov    %al,-0xc1(%rbp)
mov    -0xc1(%rbp),%al
test   $0x1,%al
jne    1170 <main+0x30>
jmp    11c7 <main+0x87>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x31,%eax
jne    11fc <main+0xbc>
movslq -0xb8(%rbp),%rax
movl   $0x1,-0x60(%rbp,%rax,4)
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jne    1227 <main+0xe7>
movslq -0xb8(%rbp),%rax
movl   $0x0,-0x60(%rbp,%rax,4)
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jl     123e <main+0xfe>
jmp    1243 <main+0x103>
jmp    11c7 <main+0x87>
lea    0xdbc(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    12b3 <main+0x173>
movslq -0xb8(%rbp),%rax
cmpl   $0x0,-0x60(%rbp,%rax,4)
jne    128e <main+0x14e>
lea    0xd84(%rip),%rdi
call   1040 <printf@plt>
jmp    129a <main+0x15a>
lea    0xd75(%rip),%rdi
call   1040 <printf@plt>
jmp    129f <main+0x15f>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1259 <main+0x119>
lea    0xd4c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0xb4(%rbp),%edx
call   1030 <next_generation@plt>
movl   $0x0,-0xbc(%rbp)
movl   $0x0,-0xb8(%rbp)
mov    -0xb8(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jge    1369 <main+0x229>
movslq -0xb8(%rbp),%rax
cmpl   $0x0,-0xb0(%rbp,%rax,4)
jne    1330 <main+0x1f0>
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
lea    0xce2(%rip),%rdi
call   1040 <printf@plt>
jmp    133c <main+0x1fc>
lea    0xcd3(%rip),%rdi
call   1040 <printf@plt>
movslq -0xb8(%rbp),%rax
mov    -0xb0(%rbp,%rax,4),%ecx
movslq -0xb8(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    12e9 <main+0x1a9>
lea    0xc96(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
mov    -0xbc(%rbp),%ecx
xor    %eax,%eax
cmp    -0xb4(%rbp),%ecx
mov    %al,-0xc2(%rbp)
je     13b1 <main+0x271>
cmpl   $0x3e8,-0xc0(%rbp)
setl   %al
mov    %al,-0xc2(%rbp)
mov    -0xc2(%rbp),%al
test   $0x1,%al
jne    12bf <main+0x17f>
lea    0xc40(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb0,%rsp
lea    0xe9a(%rip),%r14
lea    0xe96(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffffec,%eax
cmp    $0xffffffed,%eax
jb     1180 <main+0x30>
xor    %ebx,%ebx
jmp    11c5 <main+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%eax
movslq %ebx,%rbx
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jge    11d8 <main+0x88>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x31,%al
je     11b0 <main+0x60>
cmp    $0x30,%al
jne    11bf <main+0x6f>
xor    %eax,%eax
jmp    11b5 <main+0x65>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmpl   $0x0,0xc(%rsp)
jle    1214 <main+0xc4>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
cmpl   $0x0,0x10(%rsp,%rbx,4)
sete   %al
lea    0x2a(,%rax,4),%edi
call   1040 <putchar@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     11f0 <main+0xa0>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %r12d,%r12d
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%r14
lea    0x60(%rsp),%r15
nop
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <next_generation@plt>
cmpl   $0x0,0xc(%rsp)
mov    $0x0,%ebp
jle    127e <main+0x12e>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
cmpl   $0x0,0x60(%rsp,%rbx,4)
sete   %al
lea    0x2a(,%rax,4),%edi
add    %eax,%ebp
call   1040 <putchar@plt>
mov    0x60(%rsp,%rbx,4),%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1250 <main+0x100>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    0xc(%rsp),%edx
cmp    %edx,%ebp
je     12a1 <main+0x151>
lea    0x1(%r12),%eax
cmp    $0x3e7,%r12d
mov    %eax,%r12d
jb     1230 <main+0xe0>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"n=\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [2 x i8] c"*\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [20 x i32]
%4 = alloca [20 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %9
9: ; preds = %18, %0
%10 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
br label %12
12: ; preds = %9
%13 = load i32, i32* %5
%14 = icmp sle i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %5
%17 = icmp sge i32 %16, 20
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ true, %12 ], [ %17, %15 ]
br i1 %19, label %9, label %20
20: ; preds = %18
br label %21
21: ; preds = %20, %47
%22 = call signext i8 (...) @getchar()
store i8 %22, i8* %2
%23 = load i8, i8* %2
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 49
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %28
store i32 1, i32* %29
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %32
32: ; preds = %26, %21
%33 = load i8, i8* %2
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 48
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %38
store i32 0, i32* %39
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %42
42: ; preds = %36, %32
%43 = load i32, i32* %6
%44 = load i32, i32* %5
%45 = icmp sge i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42
br label %48
47: ; preds = %42
br label %21
48: ; preds = %46
%49 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %6
br label %50
50: ; preds = %65, %48
%51 = load i32, i32* %6
%52 = load i32, i32* %5
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %68
54: ; preds = %50
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %54
%61 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %64
62: ; preds = %54
%63 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %62, %60
br label %65
65: ; preds = %64
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %50
68: ; preds = %50
%69 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %70
70: ; preds = %113, %68
%71 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%72 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%73 = load i32, i32* %5
%74 = call i32 @next_generation(i32* %71, i32* %72, i32 %73)
store i32 0, i32* %7
store i32 0, i32* %6
br label %75
75: ; preds = %99, %70
%76 = load i32, i32* %6
%77 = load i32, i32* %5
%78 = icmp slt i32 %76, %77
br i1 %78, label %79, label %102
79: ; preds = %75
%80 = load i32, i32* %6
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %81
%83 = load i32, i32* %82
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %89
85: ; preds = %79
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 1
store i32 %87, i32* %7
%88 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %91
89: ; preds = %79
%90 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %91
91: ; preds = %89, %85
%92 = load i32, i32* %6
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %93
%95 = load i32, i32* %94
%96 = load i32, i32* %6
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %97
store i32 %95, i32* %98
br label %99
99: ; preds = %91
%100 = load i32, i32* %6
%101 = add nsw i32 %100, 1
store i32 %101, i32* %6
br label %75
102: ; preds = %75
%103 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%104 = load i32, i32* %8
%105 = add nsw i32 %104, 1
store i32 %105, i32* %8
br label %106
106: ; preds = %102
%107 = load i32, i32* %7
%108 = load i32, i32* %5
%109 = icmp ne i32 %107, %108
br i1 %109, label %110, label %113
110: ; preds = %106
%111 = load i32, i32* %8
%112 = icmp slt i32 %111, 1000
br label %113
113: ; preds = %110, %106
%114 = phi i1 [ false, %106 ], [ %112, %110 ]
br i1 %114, label %70, label %115
115: ; preds = %113
%116 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

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