#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*/ fileName;

/* Variables and functions */
int /*<<< orphan*/ fileExists(char *);
char lastChar(char *);
int /*<<< orphan*/ safef(char *, int, char *, char *, char *, char *, int,
                         char *);
char *semiUniqName(char *);
char *rTempName(char *dir, char *base, char *suffix) {
  char *x;
  static char fileName[512];
  int i;
  char *lastSlash = (lastChar(dir) == '/' ? "" : "/");
  for (i = 0;; ++i) {
    x = semiUniqName(base);
    safef(fileName, sizeof(fileName), "%s%s%s%d%s", dir, lastSlash, x, i,
          suffix);
    if (!fileExists(fileName))
      break;
  }
  return fileName;
}


x86 assembly (clang, -O0):
<rTempName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <lastChar@plt>
movsbl %al,%edx
lea    0xe99(%rip),%rax
lea    0xe93(%rip),%rcx
cmp    $0x2f,%edx
cmove  %rcx,%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <semiUniqName@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x20(%rbp),%r9
mov    -0x24(%rbp),%r10d
mov    -0x18(%rbp),%rax
lea    0x2ea8(%rip),%rdi
mov    $0x200,%esi
lea    0xe4e(%rip),%rdx
mov    %r10d,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <safef@plt>
lea    0x2e87(%rip),%rdi
call   1040 <fileExists@plt>
cmp    $0x0,%eax
jne    11dc <rTempName+0x9c>
jmp    11ef <rTempName+0xaf>
jmp    11e1 <rTempName+0xa1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1180 <rTempName+0x40>
lea    0x2e5a(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rTempName>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1050 <lastChar@plt>
cmp    $0x2f,%al
lea    0xe9f(%rip),%rax
lea    0xe97(%rip),%rbx
cmove  %rax,%rbx
xor    %ebp,%ebp
lea    0x2eda(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <semiUniqName@plt>
mov    %r13,%rdi
mov    $0x200,%esi
lea    0xe6b(%rip),%rdx
mov    %r12,%rcx
mov    %rbx,%r8
mov    %rax,%r9
push   %r14
push   %rbp
call   1060 <safef@plt>
add    $0x10,%rsp
mov    %r13,%rdi
call   1040 <fileExists@plt>
add    $0x1,%ebp
test   %eax,%eax
jne    1180 <rTempName+0x40>
lea    0x2e8e(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@rTempName.fileName = internal global [512 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [11 x i8] c"%s%s%s%d%s\00"
define i8* @rTempName(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call signext i8 @lastChar(i8* %10)
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 47
%14 = zext i1 %13 to i64
%15 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
store i8* %15, i8** %9
store i32 0, i32* %8
br label %16
16: ; preds = %29, %3
%17 = load i8*, i8** %5
%18 = call i8* @semiUniqName(i8* %17)
store i8* %18, i8** %7
%19 = load i8*, i8** %4
%20 = load i8*, i8** %9
%21 = load i8*, i8** %7
%22 = load i32, i32* %8
%23 = load i8*, i8** %6
%24 = call i32 @safef(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @rTempName.fileName, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %20, i8* %21, i32 %22, i8* %23)
%25 = call i32 @fileExists(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @rTempName.fileName, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %16
br label %32
28: ; preds = %16
br label %29
29: ; preds = %28
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %16
32: ; preds = %27
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @rTempName.fileName, i64 0, i64 0)
}

LLVM IR (-O2):
@rTempName.fileName = internal global [512 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [11 x i8] c"%s%s%s%d%s\00"
define i8* @rTempName(i8* %0, i8* %1, i8* %2) {
%4 = tail call signext i8 @lastChar(i8* %0)
%5 = icmp eq i8 %4, 47
%6 = select i1 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
br label %7
7: ; preds = %7, %3
%8 = phi i32 [ 0, %3 ], [ %13, %7 ]
%9 = tail call i8* @semiUniqName(i8* %1)
%10 = tail call i32 @safef(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @rTempName.fileName, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %6, i8* %9, i32 %8, i8* %2)
%11 = tail call i32 @fileExists(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @rTempName.fileName, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
%13 = add nuw nsw i32 %8, 1
br i1 %12, label %14, label %7
14: ; preds = %7
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @rTempName.fileName, i64 0, i64 0)
}