#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*/ strcpy(char *, char *);
char *tmpnam(char *s) {
  static char nam[32];
  strcpy(nam, "/var/tmp/XXXXXX");
  if (mktemp(nam) == NULL)
    return (NULL);
  if (s) {
    strcpy(s, nam);
    return (s);
  }
  return (nam);
}


x86 assembly (clang, -O0):
<tmpnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
lea    0x2f0d(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1030 <strcpy@plt>
lea    0x2efa(%rip),%rdi
call   1040 <mktemp@plt>
cmp    $0x0,%rax
jne    1162 <tmpnam+0x42>
movq   $0x0,-0x8(%rbp)
jmp    1195 <tmpnam+0x75>
cmpq   $0x0,-0x10(%rbp)
je     118a <tmpnam+0x6a>
mov    -0x10(%rbp),%rdi
lea    0x2ec8(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1195 <tmpnam+0x75>
lea    0x2eaf(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmpnam>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x2f12(%rip),%rbx
lea    0xecb(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <mktemp@plt>
test   %rax,%rax
je     1163 <tmpnam+0x43>
test   %r14,%r14
je     1165 <tmpnam+0x45>
lea    0x2eea(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rbx
jmp    1165 <tmpnam+0x45>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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