#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(char *, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ *strchr(char *, char);
int main() {
  int len, i = 0, j;
  char str[20], nextStr[20], temp;
  scanf("%d", &len);
  if (len >= 0 && len <= 20) {
    while (i < len) {
      scanf("%c", &temp);
      if (temp != ' ') {
        printf("error: Input error! Space expected.");
        return 1;
      }
      scanf("%c", &temp);
      if (temp == '0' || temp == '1') {
        if ((i == 0 || i == (len - 1)) && temp == '1') {
          printf("error: Input error! cell chain must start and end with 0.");
          return 1;
        }
        str[i] = temp;
      } else {
        printf("error: Input error! 0/1 expected.");
        return 1;
      }
      i++;
    }
    str[i] = '\0';
    for (i = 0; i < 1000; i++) {
      for (j = 0; j < len; j++) {
        if (str[j] == '0')
          printf(".");
        else
          printf("*");
      }
      printf("\n");
      if (strchr(str, '1') == NULL)
        break;
      next_generation(str, nextStr, len);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xea3(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jl     1324 <main+0x1e4>
cmpl   $0x14,-0x8(%rbp)
jg     1324 <main+0x1e4>
jmp    1181 <main+0x41>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1266 <main+0x126>
lea    0xe6f(%rip),%rdi
lea    -0x51(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0x51(%rbp),%eax
cmp    $0x20,%eax
je     11c4 <main+0x84>
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    132b <main+0x1eb>
lea    0xe38(%rip),%rdi
lea    -0x51(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movsbl -0x51(%rbp),%eax
cmp    $0x30,%eax
je     11f0 <main+0xb0>
movsbl -0x51(%rbp),%eax
cmp    $0x31,%eax
jne    1240 <main+0x100>
cmpl   $0x0,-0xc(%rbp)
je     120b <main+0xcb>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1230 <main+0xf0>
movsbl -0x51(%rbp),%eax
cmp    $0x31,%eax
jne    1230 <main+0xf0>
lea    0xe0b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    132b <main+0x1eb>
mov    -0x51(%rbp),%cl
movslq -0xc(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
jmp    1258 <main+0x118>
lea    0xe1d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    132b <main+0x1eb>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1181 <main+0x41>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    131f <main+0x1df>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12d8 <main+0x198>
movslq -0x10(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jne    12b9 <main+0x179>
lea    0xdb3(%rip),%rdi
call   1050 <printf@plt>
jmp    12c5 <main+0x185>
lea    0xdc6(%rip),%rdi
call   1050 <printf@plt>
jmp    12ca <main+0x18a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    128a <main+0x14a>
lea    0xda9(%rip),%rdi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x31,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1301 <main+0x1c1>
jmp    131f <main+0x1df>
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <next_generation@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1276 <main+0x136>
jmp    1324 <main+0x1e4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
lea    0xe9b(%rip),%rdi
xor    %ebp,%ebp
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
cmp    $0x14,%eax
ja     12df <main+0x18f>
xor    %ebx,%ebx
test   %eax,%eax
je     122f <main+0xdf>
lea    0xe72(%rip),%r15
lea    0xb(%rsp),%r12
lea    0xe69(%rip),%r14
lea    0xec0(%rip),%r13
xor    %ebp,%ebp
jmp    11c0 <main+0x70>
nopl   0x0(%rax,%rax,1)
mov    %cl,0x10(%rsp,%rbp,1)
add    $0x1,%rbp
movslq %eax,%rcx
cmp    %rcx,%rbp
jge    1233 <main+0xe3>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmpb   $0x20,0xb(%rsp)
jne    12d2 <main+0x182>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
movzbl 0xb(%rsp),%ecx
mov    %ecx,%eax
and    $0xfe,%al
cmp    $0x30,%al
jne    12c6 <main+0x176>
test   %rbp,%rbp
je     1220 <main+0xd0>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%edx
cmp    %rdx,%rbp
jne    11b0 <main+0x60>
cmp    $0x31,%cl
jne    11b0 <main+0x60>
jmp    12cb <main+0x17b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x31,%cl
je     12cb <main+0x17b>
mov    0xc(%rsp),%eax
jmp    11b0 <main+0x60>
xor    %eax,%eax
xor    %ebp,%ebp
movb   $0x0,0x10(%rsp,%rbp,1)
lea    0x10(%rsp),%r15
lea    0x30(%rsp),%r14
test   %eax,%eax
jle    1284 <main+0x134>
cs nopw 0x0(%rax,%rax,1)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
cmpb   $0x30,0x10(%rsp,%rbp,1)
sete   %al
lea    0x2a(,%rax,4),%edi
call   1040 <putchar@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     1260 <main+0x110>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r15,%rdi
mov    $0x31,%esi
call   1050 <strchr@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     12df <main+0x18f>
mov    0xc(%rsp),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <next_generation@plt>
add    $0x1,%ebx
cmp    $0x3e8,%ebx
je     12df <main+0x18f>
mov    0xc(%rsp),%eax
test   %eax,%eax
jg     1250 <main+0x100>
jmp    1284 <main+0x134>
mov    %r13,%r14
jmp    12d2 <main+0x182>
lea    0xd58(%rip),%r14
mov    %r14,%rdi
call   1060 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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