#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ hasTrailingSlash(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ removeTrailingNewLine(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stdin;
int system(char *);
int runTest(char *binPath) {
  char *fileName = (char *)calloc(1024, sizeof(char));
  if (fileName == NULL) {
    perror("malloc");
    exit(1);
  }
  if (fgets(fileName, 1024, stdin) == NULL) {
    goto exitTerminated;
  }
  removeTrailingNewLine(fileName);
  char *command = (char *)calloc(1024, sizeof(char));
  if (command == NULL) {
    perror("malloc");
    exit(1);
  }
  sprintf(command, "rm -rf gvki-0");
  printf("Running command %s\n", command);
  if (hasTrailingSlash(binPath)) {
    sprintf(command, "%s%s", binPath, fileName);
  } else {
    sprintf(command, "%s/%s", binPath, fileName);
  }
  printf("Running command %s\n", command);
  int systemResult = system(command);
  if (systemResult == 0) {
    sprintf(command, "mv gvki-0 gvki-%s", fileName);
    printf("Running command %s\n", command);
    system(command);
  } else {
    printf("Program error\n");
  }
exitSuccess:
  sprintf(command, "rm -rf gvki-0");
  printf("Running command %s\n", command);
  system(command);
  free(fileName);
  free(command);
  return 0;
exitTerminated:
  sprintf(command, "rm -rf gvki-0");
  printf("Running command %s\n", command);
  system(command);
  free(fileName);
  free(command);
  return 1;
}


x86 assembly (clang, -O0):
<runTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x400,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <runTest+0x40>
lea    0xe2f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1206 <runTest+0x66>
jmp    136f <runTest+0x1cf>
mov    -0x18(%rbp),%rdi
call   1080 <removeTrailingNewLine@plt>
mov    $0x400,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1243 <runTest+0xa3>
lea    0xdcc(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rsi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <hasTrailingSlash@plt>
cmp    $0x0,%rax
je     1299 <runTest+0xf9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    12b3 <runTest+0x113>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rsi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1311 <runTest+0x171>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd4a(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rsi
lea    0xd19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
jmp    131f <runTest+0x17f>
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1324 <runTest+0x184>
mov    -0x20(%rbp),%rdi
lea    0xcd8(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rsi
lea    0xcd4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b5 <runTest+0x215>
mov    -0x20(%rbp),%rdi
lea    0xc8d(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x20(%rbp),%rsi
lea    0xc89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <system@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runTest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x400,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
test   %rax,%rax
je     134f <runTest+0x19f>
mov    %rax,%r14
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     129e <runTest+0xee>
mov    %r14,%rdi
call   1090 <removeTrailingNewLine@plt>
mov    $0x400,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
test   %rax,%rax
je     134f <runTest+0x19f>
mov    %rax,%rbx
movabs $0x302d696b766720,%r12
mov    %r12,0x6(%rax)
movabs $0x672066722d206d72,%r13
66 20 67
mov    %r13,(%rax)
lea    0xdd8(%rip),%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   10d0 <hasTrailingSlash@plt>
test   %rax,%rax
lea    0xdd2(%rip),%rax
lea    0xdc6(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10b0 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
test   %eax,%eax
je     12df <runTest+0x12f>
lea    0xdaf(%rip),%rdi
call   1040 <puts@plt>
jmp    130c <runTest+0x15c>
movabs $0x302d696b766720,%rax
mov    %rax,(%rax)
movabs $0x672066722d206d72,%rax
66 20 67
mov    %rax,(%rax)
lea    0xd56(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
call   1050 <system@plt>
mov    %r14,%rdi
call   1030 <free@plt>
call   1030 <free@plt>
mov    $0x1,%ebp
jmp    133e <runTest+0x18e>
lea    0xd4e(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <sprintf@plt>
lea    0xd1b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
mov    %r12,0x6(%rbx)
mov    %r13,(%rbx)
lea    0xcfb(%rip),%rdi
xor    %ebp,%ebp
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcaa(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@stdin = global i32 0
@.str.1 = [14 x i8] c"rm -rf gvki-0\00"
@.str.2 = [20 x i8] c"Running command %s\0A\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [18 x i8] c"mv gvki-0 gvki-%s\00"
@.str.6 = [15 x i8] c"Program error\0A\00"
define i32 @runTest(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i64 @calloc(i32 1024, i32 1)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i8*, i8** %4
%16 = load i32, i32* @stdin
%17 = call i32* @fgets(i8* %15, i32 1024, i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %14
br label %77
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = call i32 @removeTrailingNewLine(i8* %21)
%23 = call i64 @calloc(i32 1024, i32 1)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %20
%31 = load i8*, i8** %5
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%33 = load i8*, i8** %5
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %3
%36 = call i64 @hasTrailingSlash(i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %30
%39 = load i8*, i8** %5
%40 = load i8*, i8** %3
%41 = load i8*, i8** %4
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %41)
br label %48
43: ; preds = %30
%44 = load i8*, i8** %5
%45 = load i8*, i8** %3
%46 = load i8*, i8** %4
%47 = call i32 (i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %45, i8* %46)
br label %48
48: ; preds = %43, %38
%49 = load i8*, i8** %5
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = load i8*, i8** %5
%52 = call i32 @system(i8* %51)
store i32 %52, i32* %6
%53 = load i32, i32* %6
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %48
%56 = load i8*, i8** %5
%57 = load i8*, i8** %4
%58 = call i32 (i8*, i8*, ...) @sprintf(i8* %56, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %57)
%59 = load i8*, i8** %5
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %59)
%61 = load i8*, i8** %5
%62 = call i32 @system(i8* %61)
br label %65
63: ; preds = %48
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %65
65: ; preds = %63, %55
br label %66
66: ; preds = %65
%67 = load i8*, i8** %5
%68 = call i32 (i8*, i8*, ...) @sprintf(i8* %67, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%69 = load i8*, i8** %5
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %69)
%71 = load i8*, i8** %5
%72 = call i32 @system(i8* %71)
%73 = load i8*, i8** %4
%74 = call i32 @free(i8* %73)
%75 = load i8*, i8** %5
%76 = call i32 @free(i8* %75)
store i32 0, i32* %2
br label %88
77: ; preds = %19
%78 = load i8*, i8** %5
%79 = call i32 (i8*, i8*, ...) @sprintf(i8* %78, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%80 = load i8*, i8** %5
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %80)
%82 = load i8*, i8** %5
%83 = call i32 @system(i8* %82)
%84 = load i8*, i8** %4
%85 = call i32 @free(i8* %84)
%86 = load i8*, i8** %5
%87 = call i32 @free(i8* %86)
store i32 1, i32* %2
br label %88
88: ; preds = %77, %66
%89 = load i32, i32* %2
ret i32 %89
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@stdin = global i32 0
@.str.1 = [14 x i8] c"rm -rf gvki-0\00"
@.str.2 = [20 x i8] c"Running command %s\0A\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [18 x i8] c"mv gvki-0 gvki-%s\00"
@str = [14 x i8] c"Program error\00"
define i32 @runTest(i8* %0) {
%2 = tail call i64 @calloc(i32 1024, i32 1)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = load i32, i32* @stdin
%10 = tail call i32* @fgets(i8* %3, i32 1024, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %40, label %12
12: ; preds = %8
%13 = tail call i32 @removeTrailingNewLine(i8* %3)
%14 = tail call i64 @calloc(i32 1024, i32 1)
%15 = inttoptr i64 %14 to i8*
%16 = icmp eq i64 %14, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %12
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(14) %15, i8* align 1 dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 14, i1 false)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%22 = tail call i64 @hasTrailingSlash(i8* %0)
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%25 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* dereferenceable(1) %24, i8* %0, i8* %3)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%27 = tail call i32 @system(i8* %15)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %20
%30 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%32 = tail call i32 @system(i8* %15)
br label %35
33: ; preds = %20
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %35
35: ; preds = %29, %33
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(14) %15, i8* align 1 dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 14, i1 false)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%37 = tail call i32 @system(i8* %15)
%38 = tail call i32 @free(i8* %3)
%39 = tail call i32 @free(i8* %15)
br label %45
40: ; preds = %8
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(14) undef, i8* align 1 dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 14, i1 false)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* undef)
%42 = tail call i32 @system(i8* undef)
%43 = tail call i32 @free(i8* %3)
%44 = tail call i32 @free(i8* undef)
br label %45
45: ; preds = %40, %35
%46 = phi i32 [ 1, %40 ], [ 0, %35 ]
ret i32 %46
}