#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*/ F_OK;
scalar_t__ XtMalloc(int);
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *_tmpFileName(char *fileName) {
  int fileNameLen = strlen(fileName);
  char *newFileName = (char *)XtMalloc((fileNameLen + 20) * sizeof(char));
  if (newFileName != (char *)NULL) {
    int i;
    char *ptr = &(newFileName[fileNameLen]);
    strcpy(newFileName, fileName);
    for (i = 0;; i++) {
      sprintf(ptr, "%d", i);
      if (access(newFileName, F_OK) != 0)
        break;
    }
  }
  return newFileName;
}


x86 assembly (clang, -O0):
<_tmpFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x14,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <XtMalloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f9 <_tmpFileName+0xa9>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe45(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     11e1 <_tmpFileName+0x91>
jmp    11f4 <_tmpFileName+0xa4>
jmp    11e6 <_tmpFileName+0x96>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ad <_tmpFileName+0x5d>
jmp    11f9 <_tmpFileName+0xa9>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_tmpFileName>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbp
call   1050 <strlen@plt>
mov    %eax,%ebx
lea    0x14(%rbx),%edi
call   1040 <XtMalloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     11c1 <_tmpFileName+0x71>
movslq %ebx,%rax
mov    %r14,%rbx
add    %rax,%rbx
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
xor    %ebp,%ebp
lea    0xe71(%rip),%r15
mov    0x2e42(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1070 <sprintf@plt>
mov    (%r12),%esi
mov    %r14,%rdi
call   1060 <access@plt>
add    $0x1,%ebp
test   %rax,%rax
je     11a0 <_tmpFileName+0x50>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@F_OK = global i32 0
define i8* @_tmpFileName(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 20
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @XtMalloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %40
18: ; preds = %1
%19 = load i8*, i8** %4
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8* %22, i8** %6
%23 = load i8*, i8** %4
%24 = load i8*, i8** %2
%25 = call i32 @strcpy(i8* %23, i8* %24)
store i32 0, i32* %5
br label %26
26: ; preds = %36, %18
%27 = load i8*, i8** %6
%28 = load i32, i32* %5
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i8*, i8** %4
%31 = load i32, i32* @F_OK
%32 = call i64 @access(i8* %30, i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %26
br label %39
35: ; preds = %26
br label %36
36: ; preds = %35
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %26
39: ; preds = %34
br label %40
40: ; preds = %39, %1
%41 = load i8*, i8** %4
ret i8* %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@F_OK = global i32 0
define i8* @_tmpFileName(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 20
%4 = tail call i64 @XtMalloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %18, label %7
7: ; preds = %1
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
%10 = tail call i32 @strcpy(i8* %5, i8* %0)
br label %11
11: ; preds = %11, %7
%12 = phi i32 [ 0, %7 ], [ %17, %11 ]
%13 = tail call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @F_OK
%15 = tail call i64 @access(i8* %5, i32 %14)
%16 = icmp eq i64 %15, 0
%17 = add nuw nsw i32 %12, 1
br i1 %16, label %11, label %18
18: ; preds = %11, %1
ret i8* %5
}