#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*/ checked_free(char *);
scalar_t__ fileExists(char *);
char *getPath2(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getSolutionTapeDir();
int /*<<< orphan*/ sprintf(char *, char *, int, ...);
char *getSolutionTapeFilename(int nr) {
  static char *filename = NULL;
  char basename[256];
  checked_free(filename);
  sprintf(basename, "%03d.%s", nr, "tape");
  filename = getPath2(getSolutionTapeDir(), basename);
  if (!fileExists(filename)) {
    static char *filename_sln = NULL;
    checked_free(filename_sln);
    sprintf(basename, "%03d.sln", nr);
    filename_sln = getPath2(getSolutionTapeDir(), basename);
    if (fileExists(filename_sln))
      return filename_sln;
  }
  return filename;
}


x86 assembly (clang, -O0):
<getSolutionTapeFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0xc(%rbp)
mov    0x2eeb(%rip),%rdi
call   1060 <checked_free@plt>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe85(%rip),%rsi
lea    0xe86(%rip),%rcx
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    $0x0,%al
call   1030 <getSolutionTapeDir@plt>
mov    %eax,%edi
lea    -0x110(%rbp),%rsi
call   1050 <getPath2@plt>
mov    %rax,0x2eab(%rip)
mov    0x2ea4(%rip),%rdi
call   1040 <fileExists@plt>
cmp    $0x0,%rax
jne    1226 <getSolutionTapeFilename+0xd6>
mov    0x2e96(%rip),%rdi
call   1060 <checked_free@plt>
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    $0x0,%al
call   1030 <getSolutionTapeDir@plt>
mov    %eax,%edi
lea    -0x110(%rbp),%rsi
call   1050 <getPath2@plt>
mov    %rax,0x2e5d(%rip)
mov    0x2e56(%rip),%rdi
call   1040 <fileExists@plt>
cmp    $0x0,%rax
je     1221 <getSolutionTapeFilename+0xd1>
mov    0x2e40(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1231 <getSolutionTapeFilename+0xe1>
jmp    1226 <getSolutionTapeFilename+0xd6>
mov    0x2e23(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSolutionTapeFilename>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %edi,%ebp
mov    0x2eee(%rip),%rdi
call   1060 <checked_free@plt>
lea    0xe92(%rip),%rsi
lea    0xe93(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
xor    %eax,%eax
call   1030 <getSolutionTapeDir@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <getPath2@plt>
mov    %rax,0x2eb4(%rip)
mov    %rax,%rdi
call   1040 <fileExists@plt>
test   %rax,%rax
je     11b2 <getSolutionTapeFilename+0x62>
lea    0x2ea0(%rip),%rax
jmp    1200 <getSolutionTapeFilename+0xb0>
mov    0x2e9f(%rip),%rdi
call   1060 <checked_free@plt>
lea    0xe48(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
xor    %eax,%eax
call   1030 <getSolutionTapeDir@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <getPath2@plt>
mov    %rax,0x2e6c(%rip)
mov    %rax,%rdi
call   1040 <fileExists@plt>
test   %rax,%rax
je     11a9 <getSolutionTapeFilename+0x59>
lea    0x2e58(%rip),%rax
mov    (%rax),%rax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@getSolutionTapeFilename.filename = internal global i8* null
@.str = [8 x i8] c"%03d.%s\00"
@.str.1 = [5 x i8] c"tape\00"
@getSolutionTapeFilename.filename_sln = internal global i8* null
@.str.2 = [9 x i8] c"%03d.sln\00"
define i8* @getSolutionTapeFilename(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [256 x i8]
store i32 %0, i32* %3
%5 = load i8*, i8** @getSolutionTapeFilename.filename
%6 = call i32 @checked_free(i8* %5)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (...) @getSolutionTapeDir()
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%12 = call i8* @getPath2(i32 %10, i8* %11)
store i8* %12, i8** @getSolutionTapeFilename.filename
%13 = load i8*, i8** @getSolutionTapeFilename.filename
%14 = call i64 @fileExists(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %31, label %16
16: ; preds = %1
%17 = load i8*, i8** @getSolutionTapeFilename.filename_sln
%18 = call i32 @checked_free(i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%20 = load i32, i32* %3
%21 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 (...) @getSolutionTapeDir()
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = call i8* @getPath2(i32 %22, i8* %23)
store i8* %24, i8** @getSolutionTapeFilename.filename_sln
%25 = load i8*, i8** @getSolutionTapeFilename.filename_sln
%26 = call i64 @fileExists(i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = load i8*, i8** @getSolutionTapeFilename.filename_sln
store i8* %29, i8** %2
br label %33
30: ; preds = %16
br label %31
31: ; preds = %30, %1
%32 = load i8*, i8** @getSolutionTapeFilename.filename
store i8* %32, i8** %2
br label %33
33: ; preds = %31, %28
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@getSolutionTapeFilename.filename = internal unnamed_addr global i8* null
@.str = [8 x i8] c"%03d.%s\00"
@.str.1 = [5 x i8] c"tape\00"
@getSolutionTapeFilename.filename_sln = internal unnamed_addr global i8* null
@.str.2 = [9 x i8] c"%03d.sln\00"
define i8* @getSolutionTapeFilename(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = load i8*, i8** @getSolutionTapeFilename.filename
%5 = tail call i32 @checked_free(i8* %4)
%6 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 (...) @getSolutionTapeDir()
%8 = call i8* @getPath2(i32 %7, i8* %3)
store i8* %8, i8** @getSolutionTapeFilename.filename
%9 = call i64 @fileExists(i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %1
%12 = load i8*, i8** @getSolutionTapeFilename.filename_sln
%13 = call i32 @checked_free(i8* %12)
%14 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%15 = call i32 (...) @getSolutionTapeDir()
%16 = call i8* @getPath2(i32 %15, i8* %3)
store i8* %16, i8** @getSolutionTapeFilename.filename_sln
%17 = call i64 @fileExists(i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %11, %1
br label %20
20: ; preds = %11, %19
%21 = phi i8** [ @getSolutionTapeFilename.filename, %19 ], [ @getSolutionTapeFilename.filename_sln, %11 ]
%22 = load i8*, i8** %21
ret i8* %22
}