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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xb8(%rbp)
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
lea    -0xb4(%rbp),%rsi
call   1060 <scanf@plt>
mov    $0x1,%al
cmpl   $0x0,-0xb4(%rbp)
mov    %al,-0xc1(%rbp)
jle    11a0 <main+0x60>
cmpl   $0x14,-0xb4(%rbp)
setg   %al
mov    %al,-0xc1(%rbp)
mov    -0xc1(%rbp),%al
test   $0x1,%al
jne    115c <main+0x1c>
jmp    11b3 <main+0x73>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x31,%eax
jne    11f4 <main+0xb4>
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
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    122b <main+0xeb>
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
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     1242 <main+0x102>
jmp    1247 <main+0x107>
jmp    11b3 <main+0x73>
lea    0xdbc(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0xc0(%rbp)
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    1307 <main+0x1c7>
movslq -0xb8(%rbp),%rax
cmpl   $0x1,-0xb0(%rbp,%rax,4)
01
jne    12bf <main+0x17f>
lea    0xd51(%rip),%rdi
call   1040 <printf@plt>
jmp    12da <main+0x19a>
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
lea    0xd33(%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    1287 <main+0x147>
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
lea    0xced(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
cmpl   $0x3e8,-0xc0(%rbp)
mov    %al,-0xc2(%rbp)
jge    134f <main+0x20f>
mov    -0xbc(%rbp),%eax
cmp    -0xb4(%rbp),%eax
setne  %al
mov    %al,-0xc2(%rbp)
mov    -0xc2(%rbp),%al
test   $0x1,%al
jne    125d <main+0x11d>
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    $0xffffffeb,%eax
cmp    $0xffffffec,%eax
jb     1180 <main+0x30>
xor    %ebx,%ebx
jmp    11cf <main+0x7f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x1,%ebp
mov    $0x2a,%edi
call   1040 <putchar@plt>
movslq %ebx,%rbx
mov    %ebp,0x60(%rsp,%rbx,4)
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jge    11e7 <main+0x97>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x31,%al
je     11b0 <main+0x60>
cmp    $0x30,%al
jne    11c9 <main+0x79>
xor    %ebp,%ebp
mov    $0x2e,%edi
jmp    11ba <main+0x6a>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %r12d,%r12d
mov    0xc(%rsp),%edx
lea    0x60(%rsp),%r14
lea    0x10(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <next_generation@plt>
cmpl   $0x0,0xc(%rsp)
mov    $0x0,%ebx
jle    125e <main+0x10e>
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
cmpl   $0x1,0x10(%rsp,%rbp,4)
setne  %al
lea    0x2a(,%rax,4),%edi
add    %eax,%ebx
call   1040 <putchar@plt>
mov    0x10(%rsp,%rbp,4),%eax
mov    %eax,0x60(%rsp,%rbp,4)
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     1230 <main+0xe0>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmp    $0x3e6,%r12d
ja     127d <main+0x12d>
add    $0x1,%r12d
mov    0xc(%rsp),%edx
cmp    %edx,%ebx
jne    1210 <main+0xc0>
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"*\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [2 x i8] c"\0A\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
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 sgt 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, %49
%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 %33
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %29
store i32 1, i32* %30
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %33
33: ; preds = %26, %21
%34 = load i8, i8* %2
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 48
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %40
store i32 0, i32* %41
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %44
44: ; preds = %37, %33
%45 = load i32, i32* %6
%46 = load i32, i32* %5
%47 = icmp sge i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %44
br label %50
49: ; preds = %44
br label %21
50: ; preds = %48
%51 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %8
br label %52
52: ; preds = %95, %50
%53 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%54 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%55 = load i32, i32* %5
%56 = call i32 @next_generation(i32* %53, i32* %54, i32 %55)
store i32 0, i32* %7
store i32 0, i32* %6
br label %57
57: ; preds = %81, %52
%58 = load i32, i32* %6
%59 = load i32, i32* %5
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %84
61: ; preds = %57
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = icmp eq i32 %65, 1
br i1 %66, label %67, label %69
67: ; preds = %61
%68 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %73
69: ; preds = %61
%70 = load i32, i32* %7
%71 = add nsw i32 %70, 1
store i32 %71, i32* %7
%72 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %73
73: ; preds = %69, %67
%74 = load i32, i32* %6
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 %75
%77 = load i32, i32* %76
%78 = load i32, i32* %6
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 %79
store i32 %77, i32* %80
br label %81
81: ; preds = %73
%82 = load i32, i32* %6
%83 = add nsw i32 %82, 1
store i32 %83, i32* %6
br label %57
84: ; preds = %57
%85 = load i32, i32* %8
%86 = add nsw i32 %85, 1
store i32 %86, i32* %8
%87 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %88
88: ; preds = %84
%89 = load i32, i32* %8
%90 = icmp slt i32 %89, 1000
br i1 %90, label %91, label %95
91: ; preds = %88
%92 = load i32, i32* %7
%93 = load i32, i32* %5
%94 = icmp ne i32 %92, %93
br label %95
95: ; preds = %91, %88
%96 = phi i1 [ false, %88 ], [ %94, %91 ]
br i1 %96, label %52, label %97
97: ; preds = %95
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, -21
%12 = icmp ult i32 %11, -20
br i1 %12, label %7, label %13
13: ; preds = %7, %24
%14 = phi i32 [ %25, %24 ], [ 0, %7 ]
%15 = call signext i8 (...) @getchar()
switch i8 %15, label %24 [
i8 49, label %17
i8 48, label %16
]
16: ; preds = %13
br label %17
17: ; preds = %13, %16
%18 = phi i32 [ 46, %16 ], [ 42, %13 ]
%19 = phi i32 [ 0, %16 ], [ 1, %13 ]
%20 = call i32 @putchar(i32 %18)
%21 = sext i32 %14 to i64
%22 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %21
store i32 %19, i32* %22
%23 = add nsw i32 %14, 1
br label %24
24: ; preds = %17, %13
%25 = phi i32 [ %14, %13 ], [ %23, %17 ]
%26 = load i32, i32* %3
%27 = icmp slt i32 %25, %26
br i1 %27, label %13, label %28
28: ; preds = %24
%29 = call i32 @putchar(i32 10)
%30 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%31 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %3
br label %33
33: ; preds = %56, %28
%34 = phi i32 [ %32, %28 ], [ %61, %56 ]
%35 = phi i32 [ 0, %28 ], [ %58, %56 ]
%36 = call i32 @next_generation(i32* %30, i32* %31, i32 %34)
%37 = load i32, i32* %3
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %56
39: ; preds = %33, %39
%40 = phi i64 [ %52, %39 ], [ 0, %33 ]
%41 = phi i32 [ %48, %39 ], [ 0, %33 ]
%42 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %40
%43 = load i32, i32* %42
%44 = icmp eq i32 %43, 1
%45 = select i1 %44, i32 42, i32 46
%46 = xor i1 %44, true
%47 = zext i1 %46 to i32
%48 = add nuw nsw i32 %41, %47
%49 = call i32 @putchar(i32 %45)
%50 = load i32, i32* %42
%51 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %40
store i32 %50, i32* %51
%52 = add nuw nsw i64 %40, 1
%53 = load i32, i32* %3
%54 = sext i32 %53 to i64
%55 = icmp slt i64 %52, %54
br i1 %55, label %39, label %56
56: ; preds = %39, %33
%57 = phi i32 [ 0, %33 ], [ %48, %39 ]
%58 = add nuw nsw i32 %35, 1
%59 = call i32 @putchar(i32 10)
%60 = icmp ult i32 %35, 999
%61 = load i32, i32* %3
%62 = icmp ne i32 %57, %61
%63 = select i1 %60, i1 %62, i1 false
br i1 %63, label %33, label %64
64: ; preds = %56
ret i32 0
}