#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*/ *mktemp(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *tempnam(const char *dir, const char *pfx) {
  static char nam[32];
  strcpy(nam, dir ? dir : "/var/tmp");
  strcat(nam, "/");
  strcat(nam, pfx ? pfx : "XXXXXX");
  if (mktemp(nam) == NULL)
    return (NULL);
  return (nam);
}


x86 assembly (clang, -O0):
<tempnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1158 <tempnam+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1168 <tempnam+0x38>
lea    0xea1(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1168 <tempnam+0x38>
mov    -0x20(%rbp),%rsi
lea    0x2edd(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2ed1(%rip),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strcat@plt>
cmpq   $0x0,-0x18(%rbp)
je     11a3 <tempnam+0x73>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11b3 <tempnam+0x83>
lea    0xe61(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11b3 <tempnam+0x83>
mov    -0x28(%rbp),%rsi
lea    0x2e92(%rip),%rdi
call   1040 <strcat@plt>
lea    0x2e86(%rip),%rdi
call   1050 <mktemp@plt>
cmp    $0x0,%rax
jne    11e6 <tempnam+0xb6>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <tempnam+0xc1>
lea    0x2e63(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tempnam>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %rdi,%rdi
lea    0xebf(%rip),%rsi
cmovne %rdi,%rsi
lea    0x2f04(%rip),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
lea    0xeae(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
test   %rbx,%rbx
lea    0xe9e(%rip),%rsi
cmovne %rbx,%rsi
mov    %r14,%rdi
call   1040 <strcat@plt>
mov    %r14,%rdi
call   1050 <mktemp@plt>
test   %rax,%rax
cmovne %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@tempnam.nam = internal global [32 x i8] zeroinitializer
@.str = [9 x i8] c"/var/tmp\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [7 x i8] c"XXXXXX\00"
define i8* @tempnam(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i8*, i8** %4
br label %11
10: ; preds = %2
br label %11
11: ; preds = %10, %8
%12 = phi i8* [ %9, %8 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %10 ]
%13 = call i32 @strcpy(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0), i8* %12)
%14 = call i32 @strcat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i8*, i8** %5
br label %20
19: ; preds = %11
br label %20
20: ; preds = %19, %17
%21 = phi i8* [ %18, %17 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %19 ]
%22 = call i32 @strcat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0), i8* %21)
%23 = call i32* @mktemp(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %26
25: ; preds = %20
store i8* null, i8** %3
br label %27
26: ; preds = %20
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0), i8** %3
br label %27
27: ; preds = %26, %25
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
@tempnam.nam = internal global [32 x i8] zeroinitializer
@.str = [9 x i8] c"/var/tmp\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [7 x i8] c"XXXXXX\00"
define i8* @tempnam(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = select i1 %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0
%5 = tail call i32 @strcpy(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0), i8* %4)
%6 = tail call i32 @strcat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %1, null
%8 = select i1 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %1
%9 = tail call i32 @strcat(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0), i8* %8)
%10 = tail call i32* @mktemp(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0))
%11 = icmp eq i32* %10, null
%12 = select i1 %11, i8* null, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @tempnam.nam, i64 0, i64 0)
ret i8* %12
}