#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ computeNextGen(char *, char *, int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printAutomata(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  FILE *ifp;
  ifp = fopen("automata.in", "r");
  int i, numcases;
  fscanf(ifp, "%d", &numcases);
  for (i = 1; i <= numcases; i++) {
    int gen, width;
    fscanf(ifp, "%d%d", &gen, &width);
    char curstate[100 + 1];
    char nextstate[100 + 1];
    char rules[8 + 1];
    fscanf(ifp, "%s%s", curstate, rules);
    printf("Automata #%d:\n", i);
    int day;
    for (day = 0; day <= gen; day++) {
      printAutomata(curstate, width);
      computeNextGen(curstate, nextstate, width, rules);
      strcpy(curstate, nextstate);
    }
    printf("\n");
  }
  fclose(ifp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6c(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1070 <fscanf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1295 <main+0x125>
mov    -0x10(%rbp),%rdi
lea    0xe41(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    -0x109(%rbp),%rcx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1070 <fscanf@plt>
mov    -0x14(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x110(%rbp)
mov    -0x110(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     1279 <main+0x109>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1060 <printAutomata@plt>
lea    -0x90(%rbp),%rdi
lea    -0x100(%rbp),%rsi
mov    -0x20(%rbp),%edx
lea    -0x109(%rbp),%rcx
call   1080 <computeNextGen@plt>
lea    -0x90(%rbp),%rdi
lea    -0x100(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x110(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x110(%rbp)
jmp    1217 <main+0xa7>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b6 <main+0x46>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
lea    0xe68(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
lea    0xe62(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1080 <fscanf@plt>
cmpl   $0x0,0x10(%rsp)
jle    1299 <main+0x119>
mov    $0x1,%ebx
lea    0x90(%rsp),%r14
lea    0x17(%rsp),%r12
lea    0x20(%rsp),%rbp
jmp    1209 <main+0x89>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0x1(%rbx),%eax
cmp    0x10(%rsp),%ebx
mov    %eax,%ebx
jge    1299 <main+0x119>
mov    %r15,%rdi
lea    0xdfb(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
xor    %eax,%eax
call   1080 <fscanf@plt>
mov    %r15,%rdi
lea    0xde5(%rip),%rsi
mov    %r14,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <fscanf@plt>
lea    0xdd6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0xc(%rsp)
js     11f0 <main+0x70>
mov    $0xffffffff,%r13d
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%esi
mov    %r14,%rdi
call   1070 <printAutomata@plt>
mov    0x8(%rsp),%edx
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12,%rcx
call   1090 <computeNextGen@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
add    $0x1,%r13d
cmp    0xc(%rsp),%r13d
jl     1260 <main+0xe0>
jmp    11f0 <main+0x70>
mov    %r15,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"automata.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"%d%d\00"
@.str.4 = [5 x i8] c"%s%s\00"
@.str.5 = [15 x i8] c"Automata #%d:\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [101 x i8]
%8 = alloca [101 x i8]
%9 = alloca [9 x i8]
%10 = alloca i32
store i32 0, i32* %1
%11 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = call i32 (i32*, i8*, ...) @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
store i32 1, i32* %3
br label %14
14: ; preds = %48, %0
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %51
18: ; preds = %14
%19 = load i32*, i32** %2
%20 = call i32 (i32*, i8*, ...) @fscanf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %5, i32* %6)
%21 = load i32*, i32** %2
%22 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 0
%23 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%24 = call i32 (i32*, i8*, ...) @fscanf(i32* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %22, i8* %23)
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %25)
store i32 0, i32* %10
br label %27
27: ; preds = %43, %18
%28 = load i32, i32* %10
%29 = load i32, i32* %5
%30 = icmp sle i32 %28, %29
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 0
%33 = load i32, i32* %6
%34 = call i32 @printAutomata(i8* %32, i32 %33)
%35 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 0
%36 = getelementptr inbounds [101 x i8], [101 x i8]* %8, i64 0, i64 0
%37 = load i32, i32* %6
%38 = getelementptr inbounds [9 x i8], [9 x i8]* %9, i64 0, i64 0
%39 = call i32 @computeNextGen(i8* %35, i8* %36, i32 %37, i8* %38)
%40 = getelementptr inbounds [101 x i8], [101 x i8]* %7, i64 0, i64 0
%41 = getelementptr inbounds [101 x i8], [101 x i8]* %8, i64 0, i64 0
%42 = call i32 @strcpy(i8* %40, i8* %41)
br label %43
43: ; preds = %31
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %27
46: ; preds = %27
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %46
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %14
51: ; preds = %14
%52 = load i32*, i32** %2
%53 = call i32 @fclose(i32* %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"automata.in\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [5 x i8] c"%d%d\00"
@.str.4 = [5 x i8] c"%s%s\00"
@.str.5 = [15 x i8] c"Automata #%d:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [101 x i8]
%5 = alloca [101 x i8]
%6 = alloca [9 x i8]
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = bitcast i32* %1 to i8*
%9 = call i32 (i32*, i8*, ...) @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 1
br i1 %11, label %40, label %12
12: ; preds = %0
%13 = bitcast i32* %2 to i8*
%14 = bitcast i32* %3 to i8*
%15 = getelementptr inbounds [101 x i8], [101 x i8]* %4, i64 0, i64 0
%16 = getelementptr inbounds [101 x i8], [101 x i8]* %5, i64 0, i64 0
%17 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
br label %18
18: ; preds = %12, %35
%19 = phi i32 [ 1, %12 ], [ %37, %35 ]
%20 = call i32 (i32*, i8*, ...) @fscanf(i32* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32* %3)
%21 = call i32 (i32*, i8*, ...) @fscanf(i32* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %15, i8* %17)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%23 = load i32, i32* %2
%24 = icmp slt i32 %23, 0
br i1 %24, label %35, label %25
25: ; preds = %18, %25
%26 = phi i32 [ %32, %25 ], [ 0, %18 ]
%27 = load i32, i32* %3
%28 = call i32 @printAutomata(i8* %15, i32 %27)
%29 = load i32, i32* %3
%30 = call i32 @computeNextGen(i8* %15, i8* %16, i32 %29, i8* %17)
%31 = call i32 @strcpy(i8* %15, i8* %16)
%32 = add nuw nsw i32 %26, 1
%33 = load i32, i32* %2
%34 = icmp slt i32 %26, %33
br i1 %34, label %25, label %35
35: ; preds = %25, %18
%36 = call i32 @putchar(i32 10)
%37 = add nuw nsw i32 %19, 1
%38 = load i32, i32* %1
%39 = icmp slt i32 %19, %38
br i1 %39, label %18, label %40
40: ; preds = %35, %0
%41 = call i32 @fclose(i32* %7)
ret i32 0
}