#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int main() {
  puts("Exploring...");
  FILE *data0 = fopen("curr.txt", "w");
  fputs("-1\n", data0);
  fclose(data0);
  if (1 == 1)
    system("./run.sh ./sample1");
  else if (1 == 2)
    system("./run.sh ./sample2");
  else
    exit(-1);
  int max = 0;
  FILE *data1 = fopen("max.txt", "r");
  char line[1024];
  fgets(line, 1024, data1);
  fclose(data1);
  max = atoi(line);
  FILE *data2 = fopen("curr.txt", "w");
  fputs("1\n", data2);
  fclose(data2);
  int i = 1;
  while (i <= max) {
    fprintf(stderr, "Executing step %d of %d\n", i, max);
    if (1 == 1)
      system("./run.sh ./sample1");
    else if (1 == 2)
      system("./run.sh ./sample2");
    else
      exit(-1);
    FILE *data3 = fopen("curr.txt", "w");
    fprintf(data3, "%d\n", i + 1);
    fclose(data3);
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
lea    0xe68(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1060 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe47(%rip),%rdi
call   1050 <system@plt>
movl   $0x0,-0x14(%rbp)
lea    0xe47(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x420(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
lea    0xde1(%rip),%rdi
lea    0xde3(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rsi
lea    0xdcc(%rip),%rdi
call   1060 <fputs@plt>
mov    -0x428(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     12fc <main+0x17c>
mov    0x2d62(%rip),%rax
movslq (%rax),%rdi
mov    -0x42c(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xda8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xd7d(%rip),%rdi
call   1050 <system@plt>
lea    0xd62(%rip),%rdi
lea    0xd64(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x438(%rbp)
mov    -0x438(%rbp),%rdi
mov    -0x42c(%rbp),%edx
add    $0x1,%edx
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x438(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    1268 <main+0xe8>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
lea    0xe69(%rip),%r14
lea    0xe6b(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xe58(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe3b(%rip),%rdi
call   1050 <system@plt>
lea    0xe42(%rip),%rdi
lea    0xe43(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
lea    0xde3(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %ebp,%ebp
jle    12cd <main+0x14d>
mov    $0x1,%ebx
lea    0xdb6(%rip),%r13
lea    0xde7(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    0x2d69(%rip),%rax
movslq (%rax),%rdi
lea    0xdb8(%rip),%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0xd89(%rip),%rdi
call   1050 <system@plt>
lea    0xd6e(%rip),%rdi
mov    %r13,%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0x1(%rbx),%r12d
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
cmp    %ebp,%ebx
mov    %r12d,%ebx
jne    1270 <main+0xf0>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Exploring...\00"
@.str.1 = [9 x i8] c"curr.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"-1\0A\00"
@.str.4 = [19 x i8] c"./run.sh ./sample1\00"
@.str.5 = [8 x i8] c"max.txt\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [3 x i8] c"1\0A\00"
@stderr = global i32 0
@.str.8 = [25 x i8] c"Executing step %d of %d\0A\00"
@.str.9 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %1
%9 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
%15 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
%16 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %16, i32** %4
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = load i32*, i32** %4
%19 = call i32 @fgets(i8* %17, i32 1024, i32* %18)
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %3
%24 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32* %25)
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
store i32 1, i32* %7
br label %29
29: ; preds = %33, %0
%30 = load i32, i32* %7
%31 = load i32, i32* %3
%32 = icmp sle i32 %30, %31
br i1 %32, label %33, label %50
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i32*
%37 = load i32, i32* %7
%38 = load i32, i32* %3
%39 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %37, i32 %38)
%40 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %41, i32** %8
%42 = load i32*, i32** %8
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
%45 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %44)
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %29
50: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Exploring...\00"
@.str.1 = [9 x i8] c"curr.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"-1\0A\00"
@.str.4 = [19 x i8] c"./run.sh ./sample1\00"
@.str.5 = [8 x i8] c"max.txt\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [3 x i8] c"1\0A\00"
@stderr = global i32 0
@.str.8 = [25 x i8] c"Executing step %d of %d\0A\00"
@.str.9 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3, i64 1, i32* %3)
%5 = tail call i32 @fclose(i32* %3)
%6 = tail call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%9 = call i32 @fgets(i8* %8, i32 1024, i32* %7)
%10 = call i32 @fclose(i32* %7)
%11 = call i32 @atoi(i8* %8)
%12 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %12)
%14 = call i32 @fclose(i32* %12)
%15 = icmp slt i32 %11, 1
br i1 %15, label %28, label %16
16: ; preds = %0, %16
%17 = phi i32 [ %24, %16 ], [ 1, %0 ]
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %17, i32 %11)
%22 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = add nuw i32 %17, 1
%25 = call i32 (i32*, i8*, i32, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %24)
%26 = call i32 @fclose(i32* %23)
%27 = icmp eq i32 %17, %11
br i1 %27, label %28, label %16
28: ; preds = %16, %0
ret i32 0
}