#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*/ createFilePath(char *, int, char const *, char *,
                                  char const *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int monkey(char *, char *, int, int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int startMonkeying(const char *output_directory, int index,
                   const char *output_file_name, const char *source_file_name,
                   int read_max, bool verbose, bool silent) {
  char *prefix = malloc(5 * sizeof(char));
  if (index == 0) {
    prefix[0] = '\0';
  } else {
    snprintf(prefix, 5, "_%d", index);
  }
  char *output_file = malloc(255 * sizeof(char));
  if (!createFilePath(output_file, 255, output_directory, prefix,
                      output_file_name)) {
    return 1;
  }
  char *source_file = malloc(255 * sizeof(char));
  if (!createFilePath(source_file, 255, output_directory, prefix,
                      source_file_name)) {
    return 1;
  }
  free(prefix);
  int result = monkey(source_file, output_file, read_max, verbose, silent);
  free(output_file);
  free(source_file);
  return result;
}


x86 assembly (clang, -O0):
<startMonkeying>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9d,-0x30(%rbp)
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1196 <startMonkeying+0x46>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
jmp    11ae <startMonkeying+0x5e>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x5,%esi
lea    0xe57(%rip),%rdx
call   1050 <snprintf@plt>
mov    $0xff,%edi
call   1060 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0xff,%esi
call   1070 <createFilePath@plt>
cmp    $0x0,%eax
jne    11eb <startMonkeying+0x9b>
movl   $0x1,-0x4(%rbp)
jmp    1263 <startMonkeying+0x113>
mov    $0xff,%edi
call   1060 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    $0xff,%esi
call   1070 <createFilePath@plt>
cmp    $0x0,%eax
jne    1228 <startMonkeying+0xd8>
movl   $0x1,-0x4(%rbp)
jmp    1263 <startMonkeying+0x113>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    0x10(%rbp),%r8d
call   1040 <monkey@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startMonkeying>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r13
mov    $0x5,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
je     1197 <startMonkeying+0x47>
lea    0xe7a(%rip),%rdx
mov    %rbx,%rdi
mov    $0x5,%esi
mov    %ebp,%ecx
call   1050 <snprintf@plt>
jmp    119a <startMonkeying+0x4a>
movb   $0x0,(%rbx)
mov    $0xff,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0xff,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
call   1070 <createFilePath@plt>
test   %eax,%eax
je     1220 <startMonkeying+0xd0>
mov    $0xff,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0xff,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
call   1070 <createFilePath@plt>
test   %eax,%eax
je     1220 <startMonkeying+0xd0>
mov    0x40(%rsp),%r12d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    0x4(%rsp),%ecx
mov    %r12d,%r8d
call   1040 <monkey@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
jmp    1225 <startMonkeying+0xd5>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"_%d\00"
define i32 @startMonkeying(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i32
store i8* %0, i8** %9
store i32 %1, i32* %10
store i8* %2, i8** %11
store i8* %3, i8** %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i32 %6, i32* %15
%20 = call i8* @malloc(i32 5)
store i8* %20, i8** %16
%21 = load i32, i32* %10
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %7
%24 = load i8*, i8** %16
%25 = getelementptr inbounds i8, i8* %24, i64 0
store i8 0, i8* %25
br label %30
26: ; preds = %7
%27 = load i8*, i8** %16
%28 = load i32, i32* %10
%29 = call i32 @snprintf(i8* %27, i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26, %23
%31 = call i8* @malloc(i32 255)
store i8* %31, i8** %17
%32 = load i8*, i8** %17
%33 = load i8*, i8** %9
%34 = load i8*, i8** %16
%35 = load i8*, i8** %11
%36 = call i32 @createFilePath(i8* %32, i32 255, i8* %33, i8* %34, i8* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %30
store i32 1, i32* %8
br label %62
39: ; preds = %30
%40 = call i8* @malloc(i32 255)
store i8* %40, i8** %18
%41 = load i8*, i8** %18
%42 = load i8*, i8** %9
%43 = load i8*, i8** %16
%44 = load i8*, i8** %12
%45 = call i32 @createFilePath(i8* %41, i32 255, i8* %42, i8* %43, i8* %44)
%46 = icmp ne i32 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %39
store i32 1, i32* %8
br label %62
48: ; preds = %39
%49 = load i8*, i8** %16
%50 = call i32 @free(i8* %49)
%51 = load i8*, i8** %18
%52 = load i8*, i8** %17
%53 = load i32, i32* %13
%54 = load i32, i32* %14
%55 = load i32, i32* %15
%56 = call i32 @monkey(i8* %51, i8* %52, i32 %53, i32 %54, i32 %55)
store i32 %56, i32* %19
%57 = load i8*, i8** %17
%58 = call i32 @free(i8* %57)
%59 = load i8*, i8** %18
%60 = call i32 @free(i8* %59)
%61 = load i32, i32* %19
store i32 %61, i32* %8
br label %62
62: ; preds = %48, %47, %38
%63 = load i32, i32* %8
ret i32 %63
}

LLVM IR (-O2):
@.str = [4 x i8] c"_%d\00"
define i32 @startMonkeying(i8* %0, i32 %1, i8* %2, i8* %3, i32 %4, i32 %5, i32 %6) {
%8 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%9 = icmp eq i32 %1, 0
br i1 %9, label %10, label %11
10: ; preds = %7
store i8 0, i8* %8
br label %13
11: ; preds = %7
%12 = tail call i32 @snprintf(i8* %8, i32 5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %13
13: ; preds = %11, %10
%14 = tail call dereferenceable_or_null(255) i8* @malloc(i32 255)
%15 = tail call i32 @createFilePath(i8* %14, i32 255, i8* %0, i8* %8, i8* %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %13
%18 = tail call dereferenceable_or_null(255) i8* @malloc(i32 255)
%19 = tail call i32 @createFilePath(i8* %18, i32 255, i8* %0, i8* %8, i8* %3)
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = tail call i32 @free(i8* %8)
%23 = tail call i32 @monkey(i8* %18, i8* %14, i32 %4, i32 %5, i32 %6)
%24 = tail call i32 @free(i8* %14)
%25 = tail call i32 @free(i8* %18)
br label %26
26: ; preds = %21, %17, %13
%27 = phi i32 [ 1, %13 ], [ %23, %21 ], [ 1, %17 ]
ret i32 %27
}