#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__ access(char *, int /*<<< orphan*/);
int random();
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *gen_file_name(char *template, char *buf, int maxlen) {
  int r;
  int lim = 100;
  do {
    r = random();
    snprintf(buf, maxlen, template, r);
    lim--;
  } while (lim > 0 && access(buf, F_OK) == 0);
  return lim > 0 ? buf : NULL;
}


x86 assembly (clang, -O0):
<gen_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x64,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%ecx
call   1030 <snprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jle    119b <gen_file_name+0x6b>
mov    -0x10(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1050 <access@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    114a <gen_file_name+0x1a>
cmpl   $0x0,-0x1c(%rbp)
jle    11bd <gen_file_name+0x8d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11c8 <gen_file_name+0x98>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    11c8 <gen_file_name+0x98>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_file_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x65,%ebp
mov    0x2e8b(%rip),%r12
nopl   (%rax)
xor    %eax,%eax
call   1040 <random@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
mov    %eax,%ecx
call   1030 <snprintf@plt>
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
jb     1182 <gen_file_name+0x52>
mov    (%r12),%esi
mov    %rbx,%rdi
call   1050 <access@plt>
test   %rax,%rax
je     1150 <gen_file_name+0x20>
jmp    1184 <gen_file_name+0x54>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_OK = global i32 0
define i8* @gen_file_name(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 100, i32* %8
br label %9
9: ; preds = %26, %3
%10 = call i32 (...) @random()
store i32 %10, i32* %7
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = load i8*, i8** %4
%14 = load i32, i32* %7
%15 = call i32 @snprintf(i8* %11, i32 %12, i8* %13, i32 %14)
%16 = load i32, i32* %8
%17 = add nsw i32 %16, -1
store i32 %17, i32* %8
br label %18
18: ; preds = %9
%19 = load i32, i32* %8
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8*, i8** %5
%23 = load i32, i32* @F_OK
%24 = call i64 @access(i8* %22, i32 %23)
%25 = icmp eq i64 %24, 0
br label %26
26: ; preds = %21, %18
%27 = phi i1 [ false, %18 ], [ %25, %21 ]
br i1 %27, label %9, label %28
28: ; preds = %26
%29 = load i32, i32* %8
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = load i8*, i8** %5
br label %34
33: ; preds = %28
br label %34
34: ; preds = %33, %31
%35 = phi i8* [ %32, %31 ], [ null, %33 ]
ret i8* %35
}

LLVM IR (-O2):
@F_OK = global i32 0
define i8* @gen_file_name(i8* %0, i8* %1, i32 %2) {
br label %4
4: ; preds = %9, %3
%5 = phi i32 [ 100, %3 ], [ %10, %9 ]
%6 = tail call i32 (...) @random()
%7 = tail call i32 @snprintf(i8* %1, i32 %2, i8* %0, i32 %6)
%8 = icmp ugt i32 %5, 1
br i1 %8, label %9, label %14
9: ; preds = %4
%10 = add nsw i32 %5, -1
%11 = load i32, i32* @F_OK
%12 = tail call i64 @access(i8* %1, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %4, label %14
14: ; preds = %4, %9
%15 = phi i8* [ null, %4 ], [ %1, %9 ]
ret i8* %15
}