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

/* Variables and functions */
char *getenv(char *);
scalar_t__ getpid();
int rand();
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
char *strdup(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *shared_file_name_create(char *file) {
  char *tmpdir;
  char buf[4096];
  if (file)
    return (strdup(file));
  if (!(tmpdir = getenv("TMPDIR")))
    tmpdir = "/tmp";
  srand(time(NULL));
  snprintf(buf, sizeof(buf), "%s/io-watchdog-%d-%04x", tmpdir, (int)getpid(),
           rand());
  return (strdup(buf));
}


x86 assembly (clang, -O0):
<shared_file_name_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     119c <shared_file_name_create+0x2c>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1237 <shared_file_name_create+0xc7>
lea    0xe5d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c1 <shared_file_name_create+0x51>
lea    0xe4a(%rip),%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1038(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x1030(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x1024(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x1038(%rbp),%rdi
mov    -0x1030(%rbp),%rcx
mov    -0x1024(%rbp),%r8d
mov    %eax,%r9d
mov    $0x1000,%esi
lea    0xdea(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shared_file_name_create>:
test   %rdi,%rdi
je     117a <shared_file_name_create+0xa>
jmp    1080 <strdup@plt>
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
lea    0xe73(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe6b(%rip),%rbx
cmovne %rax,%rbx
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1090 <rand@plt>
lea    0xe46(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %rbx,%rcx
mov    %r14d,%r8d
mov    %eax,%r9d
call   1050 <snprintf@plt>
mov    %r15,%rdi
call   1080 <strdup@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [23 x i8] c"%s/io-watchdog-%d-%04x\00"
define i8* @shared_file_name_create(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [4096 x i8]
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %2
br label %26
11: ; preds = %1
%12 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %11
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %15
15: ; preds = %14, %11
%16 = call i32 @time(i32* null)
%17 = call i32 @srand(i32 %16)
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %4
%20 = call i64 (...) @getpid()
%21 = trunc i64 %20 to i32
%22 = call i32 (...) @rand()
%23 = call i32 @snprintf(i8* %18, i32 4096, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32 %21, i32 %22)
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%25 = call i8* @strdup(i8* %24)
store i8* %25, i8** %2
br label %26
26: ; preds = %15, %8
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [23 x i8] c"%s/io-watchdog-%d-%04x\00"
define noalias i8* @shared_file_name_create(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i8* @strdup(i8* %0)
br label %18
7: ; preds = %1
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i8* %8, null
%10 = select i1 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %8
%11 = tail call i32 @time(i32* null)
%12 = tail call i32 @srand(i32 %11)
%13 = tail call i64 (...) @getpid()
%14 = trunc i64 %13 to i32
%15 = tail call i32 (...) @rand()
%16 = call i32 @snprintf(i8* %3, i32 4096, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32 %14, i32 %15)
%17 = call i8* @strdup(i8* %3)
br label %18
18: ; preds = %7, %5
%19 = phi i8* [ %6, %5 ], [ %17, %7 ]
ret i8* %19
}