#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 FILENAME_MAX;
scalar_t__ __gen_tempname(char *, int);
scalar_t__ __path_search(char *, int, char const *, char const *, int);
char *strdup(char *);
char *tempnam(const char *dir, const char *pfx) {
  char buf[FILENAME_MAX];
  if (__path_search(buf, FILENAME_MAX, dir, pfx, 1))
    return NULL;
  if (__gen_tempname(buf, 3))
    return NULL;
  return strdup(buf);
}


x86 assembly (clang, -O0):
<tempnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%r8d
call   1030 <__path_search@plt>
cmp    $0x0,%rax
je     11a6 <tempnam+0x76>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11e6 <tempnam+0xb6>
mov    -0x38(%rbp),%rdi
mov    $0x3,%esi
call   1040 <__gen_tempname@plt>
cmp    $0x0,%rax
je     11d2 <tempnam+0xa2>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11e6 <tempnam+0xb6>
mov    -0x38(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tempnam>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %rsi,%rcx
mov    %rdi,%rdx
mov    0x2ea5(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    $0x1,%r8d
call   1030 <__path_search@plt>
test   %rax,%rax
jne    117e <tempnam+0x4e>
mov    %rbx,%rdi
mov    $0x3,%esi
call   1040 <__gen_tempname@plt>
test   %rax,%rax
je     1187 <tempnam+0x57>
xor    %eax,%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
call   1050 <strdup@plt>
jmp    1180 <tempnam+0x50>

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
define i8* @tempnam(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i32, i32* @FILENAME_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32, i32* @FILENAME_MAX
%14 = load i8*, i8** %4
%15 = load i8*, i8** %5
%16 = call i64 @__path_search(i8* %12, i32 %13, i8* %14, i8* %15, i32 1)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %2
store i8* null, i8** %3
store i32 1, i32* %8
br label %25
19: ; preds = %2
%20 = call i64 @__gen_tempname(i8* %12, i32 3)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19
store i8* null, i8** %3
store i32 1, i32* %8
br label %25
23: ; preds = %19
%24 = call i8* @strdup(i8* %12)
store i8* %24, i8** %3
store i32 1, i32* %8
br label %25
25: ; preds = %23, %22, %18
%26 = load i8*, i8** %6
%27 = load i8*, i8** %3
ret i8* %27
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
define noalias i8* @tempnam(i8* %0, i8* %1) {
%3 = load i32, i32* @FILENAME_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i64 @__path_search(i8* %5, i32 %3, i8* %0, i8* %1, i32 1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = call i64 @__gen_tempname(i8* %5, i32 3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i8* @strdup(i8* %5)
br label %13
13: ; preds = %8, %2, %11
%14 = phi i8* [ %12, %11 ], [ null, %2 ], [ null, %8 ]
ret i8* %14
}