#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 current[20];
  int next[20];
  int lenght, lenght_helper, cell_current, i, error = 0;
  for (i = 0; i < 20; i++) {
    *(current + i) = 0;
    *(next + i) = 0;
  }
  do {
    scanf("%d", &lenght);
  } while (lenght > 20 || lenght < 0);
  for (lenght_helper = lenght, cell_current = 0; lenght_helper > 0;
       lenght_helper--, cell_current++) {
    scanf("%d", &current[cell_current]);
    if (cell_current == 0 || cell_current == lenght - 1) {
      if (current[cell_current] == 1) {
        printf(" Error : String must start and end with 0. ");
        error = 1;
        break;
      }
    }
  }
  if (error == 0)
    next_generation(current, next, lenght);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc4(%rbp)
movl   $0x0,-0xc0(%rbp)
cmpl   $0x14,-0xc0(%rbp)
jge    1198 <main+0x68>
movslq -0xc0(%rbp),%rax
movl   $0x0,-0x60(%rbp,%rax,4)
movslq -0xc0(%rbp),%rax
movl   $0x0,-0xb0(%rbp,%rax,4)
mov    -0xc0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc0(%rbp)
jmp    1156 <main+0x26>
jmp    119d <main+0x6d>
lea    0xe5c(%rip),%rdi
lea    -0xb4(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x1,%al
cmpl   $0x14,-0xb4(%rbp)
mov    %al,-0xc5(%rbp)
jg     11d5 <main+0xa5>
cmpl   $0x0,-0xb4(%rbp)
setl   %al
mov    %al,-0xc5(%rbp)
mov    -0xc5(%rbp),%al
test   $0x1,%al
jne    119d <main+0x6d>
mov    -0xb4(%rbp),%eax
mov    %eax,-0xb8(%rbp)
movl   $0x0,-0xbc(%rbp)
cmpl   $0x0,-0xb8(%rbp)
jle    12a2 <main+0x172>
movslq -0xbc(%rbp),%rax
lea    -0x60(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xde1(%rip),%rdi
call   1050 <scanf@plt>
cmpl   $0x0,-0xbc(%rbp)
je     1248 <main+0x118>
mov    -0xbc(%rbp),%eax
mov    -0xb4(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    127a <main+0x14a>
movslq -0xbc(%rbp),%rax
cmpl   $0x1,-0x60(%rbp,%rax,4)
jne    1275 <main+0x145>
lea    0xda2(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0xc4(%rbp)
jmp    12a2 <main+0x172>
jmp    127a <main+0x14a>
jmp    127f <main+0x14f>
mov    -0xb8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xb8(%rbp)
mov    -0xbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xbc(%rbp)
jmp    11f9 <main+0xc9>
cmpl   $0x0,-0xc4(%rbp)
jne    12c5 <main+0x195>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0xb4(%rbp),%edx
call   1030 <next_generation@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb8,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0xa0(%rsp)
lea    0xe7d(%rip),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%r12d
cmp    $0x14,%r12
ja     1190 <main+0x60>
test   %r12,%r12
je     1205 <main+0xd5>
test   %r12d,%r12d
mov    $0x1,%eax
cmovle %r12d,%eax
sub    %rax,%r12
add    $0x1,%r12
xor    %ebx,%ebx
lea    0xe39(%rip),%r14
jmp    11df <main+0xaf>
nopl   0x0(%rax)
cmpl   $0x1,(%r15)
je     121e <main+0xee>
add    $0x1,%rbx
cmp    %r12,%rbx
je     1209 <main+0xd9>
lea    (%rsp,%rbx,4),%r15
add    $0x10,%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
test   %rbx,%rbx
je     11d0 <main+0xa0>
mov    0xc(%rsp),%eax
add    $0xffffffff,%eax
cmp    %rax,%rbx
je     11d0 <main+0xa0>
jmp    11d6 <main+0xa6>
xor    %edx,%edx
jmp    120d <main+0xdd>
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rdi
lea    0x60(%rsp),%rsi
call   1030 <next_generation@plt>
jmp    122a <main+0xfa>
lea    0xdde(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [44 x i8] c" Error : String must start and end with 0. \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
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %8
store i32 0, i32* %7
br label %9
9: ; preds = %21, %0
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 20
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
store i32 0, i32* %16
%17 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32 0, i32* %20
br label %21
21: ; preds = %12
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %9
24: ; preds = %9
br label %25
25: ; preds = %33, %24
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
br label %27
27: ; preds = %25
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 20
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 0
br label %33
33: ; preds = %30, %27
%34 = phi i1 [ true, %27 ], [ %32, %30 ]
br i1 %34, label %25, label %35
35: ; preds = %33
%36 = load i32, i32* %4
store i32 %36, i32* %5
store i32 0, i32* %6
br label %37
37: ; preds = %62, %35
%38 = load i32, i32* %5
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %67
40: ; preds = %37
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %42
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %43)
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 0
br i1 %46, label %52, label %47
47: ; preds = %40
%48 = load i32, i32* %6
%49 = load i32, i32* %4
%50 = sub nsw i32 %49, 1
%51 = icmp eq i32 %48, %50
br i1 %51, label %52, label %61
52: ; preds = %47, %40
%53 = load i32, i32* %6
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %60
58: ; preds = %52
%59 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %8
br label %67
60: ; preds = %52
br label %61
61: ; preds = %60, %47
br label %62
62: ; preds = %61
%63 = load i32, i32* %5
%64 = add nsw i32 %63, -1
store i32 %64, i32* %5
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %37
67: ; preds = %58, %37
%68 = load i32, i32* %8
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %67
%71 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%72 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%73 = load i32, i32* %4
%74 = call i32 @next_generation(i32* %71, i32* %72, i32 %73)
br label %75
75: ; preds = %70, %67
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [44 x i8] c" Error : String must start and end with 0. \00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = bitcast [20 x i32]* %1 to i8*
%3 = alloca [20 x i32]
%4 = bitcast [20 x i32]* %3 to i8*
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
br label %7
7: ; preds = %0, %7
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%9 = load i32, i32* %5
%10 = icmp ugt i32 %9, 20
br i1 %10, label %7, label %11
11: ; preds = %7
%12 = icmp eq i32 %9, 0
br i1 %12, label %38, label %13
13: ; preds = %11
%14 = add nuw nsw i32 %9, 1
%15 = call i32 @llvm.smin.i32(i32 %9, i32 1)
%16 = sub nuw nsw i32 %14, %15
%17 = zext i32 %16 to i64
br label %18
18: ; preds = %13, %33
%19 = phi i64 [ 0, %13 ], [ %34, %33 ]
%20 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %20)
%22 = icmp eq i64 %19, 0
br i1 %22, label %28, label %23
23: ; preds = %18
%24 = load i32, i32* %5
%25 = add nsw i32 %24, -1
%26 = zext i32 %25 to i64
%27 = icmp eq i64 %19, %26
br i1 %27, label %28, label %33
28: ; preds = %23, %18
%29 = load i32, i32* %20
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %43
33: ; preds = %23, %28
%34 = add nuw nsw i64 %19, 1
%35 = icmp eq i64 %34, %17
br i1 %35, label %36, label %18
36: ; preds = %33
%37 = load i32, i32* %5
br label %38
38: ; preds = %36, %11
%39 = phi i32 [ %37, %36 ], [ 0, %11 ]
%40 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
%41 = getelementptr inbounds [20 x i32], [20 x i32]* %3, i64 0, i64 0
%42 = call i32 @next_generation(i32* %40, i32* %41, i32 %39)
br label %43
43: ; preds = %31, %38
ret i32 0
}