#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__ ace_fs_does_file_exist(char *);
char *ace_str_join_2(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ rename(char *, char *);
char *choose_index_filepath(char *index_filepath) {
  char *singleton_filepath;
  if (ace_fs_does_file_exist(index_filepath)) {
    return index_filepath;
  }
  singleton_filepath = ace_str_join_2(index_filepath, ".0");
  if (ace_fs_does_file_exist(singleton_filepath)) {
    rename(singleton_filepath, index_filepath);
    free(singleton_filepath);
    return index_filepath;
  } else {
    free(index_filepath);
    return singleton_filepath;
  }
}


x86 assembly (clang, -O0):
<choose_index_filepath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <ace_fs_does_file_exist@plt>
cmp    $0x0,%rax
je     116c <choose_index_filepath+0x2c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c7 <choose_index_filepath+0x87>
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <ace_str_join_2@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ace_fs_does_file_exist@plt>
cmp    $0x0,%rax
je     11b6 <choose_index_filepath+0x76>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <rename@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c7 <choose_index_filepath+0x87>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<choose_index_filepath>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <ace_fs_does_file_exist@plt>
test   %rax,%rax
jne    118b <choose_index_filepath+0x4b>
lea    0xea8(%rip),%rsi
mov    %rbx,%rdi
call   1060 <ace_str_join_2@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <ace_fs_does_file_exist@plt>
test   %rax,%rax
je     1180 <choose_index_filepath+0x40>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <rename@plt>
mov    %r14,%rdi
jmp    1186 <choose_index_filepath+0x46>
mov    %rbx,%rdi
mov    %r14,%rbx
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c".0\00"
define i8* @choose_index_filepath(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @ace_fs_does_file_exist(i8* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i8*, i8** %3
store i8* %9, i8** %2
br label %27
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @ace_str_join_2(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = call i64 @ace_fs_does_file_exist(i8* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %10
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = call i32 @rename(i8* %17, i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
%22 = load i8*, i8** %3
store i8* %22, i8** %2
br label %27
23: ; preds = %10
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %4
store i8* %26, i8** %2
br label %27
27: ; preds = %23, %16, %8
%28 = load i8*, i8** %2
ret i8* %28
}

LLVM IR (-O2):
@.str = [3 x i8] c".0\00"
define i8* @choose_index_filepath(i8* %0) {
%2 = tail call i64 @ace_fs_does_file_exist(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = tail call i8* @ace_str_join_2(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @ace_fs_does_file_exist(i8* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @rename(i8* %5, i8* %0)
br label %10
10: ; preds = %4, %8
%11 = phi i8* [ %5, %8 ], [ %0, %4 ]
%12 = phi i8* [ %0, %8 ], [ %5, %4 ]
%13 = tail call i32 @free(i8* %11)
br label %14
14: ; preds = %10, %1
%15 = phi i8* [ %0, %1 ], [ %12, %10 ]
ret i8* %15
}