#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ gen_random(char *, int);
char *mm_alloc_char(int);
int /*<<< orphan*/ mm_free_char(char **);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *get_unique_filename(void) {
  char *filename = mm_alloc_char(44);
  struct stat sts;
  while (1) {
    char headname[40];
    gen_random(headname, 40);
    strncpy(filename, headname, 40);
    strcat(filename, ".out");
    if (stat(filename, &sts) == -1)
      break;
    else {
      mm_free_char(&filename);
      filename = mm_alloc_char(44);
    }
  }
  return filename;
}


x86 assembly (clang, -O0):
<get_unique_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x2c,%edi
call   1030 <mm_alloc_char@plt>
mov    %rax,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x28,%esi
call   1070 <gen_random@plt>
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x28,%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    11c1 <get_unique_filename+0x61>
jmp    11dd <get_unique_filename+0x7d>
lea    -0x8(%rbp),%rdi
call   1050 <mm_free_char@plt>
mov    $0x2c,%edi
call   1030 <mm_alloc_char@plt>
mov    %rax,-0x8(%rbp)
jmp    1176 <get_unique_filename+0x16>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_unique_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    $0x2c,%edi
call   1030 <mm_alloc_char@plt>
mov    %rax,(%rsp)
lea    0x10(%rsp),%rbx
lea    0xe7b(%rip),%r14
lea    0x8(%rsp),%r15
mov    %rsp,%r12
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x28,%esi
call   1070 <gen_random@plt>
mov    (%rsp),%rdi
mov    %rbx,%rsi
mov    $0x28,%edx
call   1040 <strncpy@plt>
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    (%rsp),%rdi
mov    %r15,%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     11e3 <get_unique_filename+0x83>
mov    %r12,%rdi
call   1050 <mm_free_char@plt>
mov    $0x2c,%edi
call   1030 <mm_alloc_char@plt>
mov    %rax,(%rsp)
jmp    1190 <get_unique_filename+0x30>
mov    (%rsp),%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c".out\00"
define i8* @get_unique_filename() {
%1 = alloca i8*
%2 = alloca %struct.stat
%3 = alloca [40 x i8]
%4 = call i8* @mm_alloc_char(i32 44)
store i8* %4, i8** %1
br label %5
5: ; preds = %0, %20
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%7 = call i32 @gen_random(i8* %6, i32 40)
%8 = load i8*, i8** %1
%9 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%10 = call i32 @strncpy(i8* %8, i8* %9, i32 40)
%11 = load i8*, i8** %1
%12 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %1
%14 = call i32 @stat(i8* %13, %struct.stat* %2)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %5
br label %21
17: ; preds = %5
%18 = call i32 @mm_free_char(i8** %1)
%19 = call i8* @mm_alloc_char(i32 44)
store i8* %19, i8** %1
br label %20
20: ; preds = %17
br label %5
21: ; preds = %16
%22 = load i8*, i8** %1
ret i8* %22
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c".out\00"
define i8* @get_unique_filename() {
%1 = alloca i8*
%2 = alloca %struct.stat
%3 = alloca [40 x i8]
%4 = bitcast i8** %1 to i8*
%5 = tail call i8* @mm_alloc_char(i32 44)
store i8* %5, i8** %1
%6 = bitcast %struct.stat* %2 to i8*
%7 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
br label %8
8: ; preds = %17, %0
%9 = call i32 @gen_random(i8* %7, i32 40)
%10 = load i8*, i8** %1
%11 = call i32 @strncpy(i8* %10, i8* %7, i32 40)
%12 = load i8*, i8** %1
%13 = call i32 @strcat(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %1
%15 = call i32 @stat(i8* %14, %struct.stat* %2)
%16 = icmp eq i32 %15, -1
br i1 %16, label %20, label %17
17: ; preds = %8
%18 = call i32 @mm_free_char(i8** %1)
%19 = call i8* @mm_alloc_char(i32 44)
store i8* %19, i8** %1
br label %8
20: ; preds = %8
%21 = load i8*, i8** %1
ret i8* %21
}