#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*/ L_tmpnam;
scalar_t__ ___path_search(char *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *);
scalar_t__ __gen_tempname(char *, int, int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
char *tmpnam_r(char *s) {
  if (s == NULL)
    return NULL;
  if (___path_search(s, L_tmpnam, NULL, NULL))
    return NULL;
  if (__gen_tempname(s, 3, 0, 0, 0))
    return NULL;
  return s;
}


x86 assembly (clang, -O0):
<tmpnam_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <tmpnam_r+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11aa <tmpnam_r+0x8a>
mov    -0x10(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <___path_search@plt>
cmp    $0x0,%rax
je     1174 <tmpnam_r+0x54>
movq   $0x0,-0x8(%rbp)
jmp    11aa <tmpnam_r+0x8a>
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1040 <__gen_tempname@plt>
cmp    $0x0,%rax
je     11a2 <tmpnam_r+0x82>
movq   $0x0,-0x8(%rbp)
jmp    11aa <tmpnam_r+0x8a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmpnam_r>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1166 <tmpnam_r+0x46>
mov    %rdi,%rbx
mov    0x2ead(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <___path_search@plt>
test   %rax,%rax
jne    1169 <tmpnam_r+0x49>
xor    %r14d,%r14d
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <__gen_tempname@plt>
test   %rax,%rax
cmove  %rbx,%r14
jmp    1169 <tmpnam_r+0x49>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@L_tmpnam = global i32 0
define i8* @tmpnam_r(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
store i8* null, i8** %2
br label %20
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i32, i32* @L_tmpnam
%10 = call i64 @___path_search(i8* %8, i32 %9, i32* null, i32* null)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7
store i8* null, i8** %2
br label %20
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = call i64 @__gen_tempname(i8* %14, i32 3, i32 0, i32 0, i32 0)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* null, i8** %2
br label %20
18: ; preds = %13
%19 = load i8*, i8** %3
store i8* %19, i8** %2
br label %20
20: ; preds = %18, %17, %12, %6
%21 = load i8*, i8** %2
ret i8* %21
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
define i8* @tmpnam_r(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = load i32, i32* @L_tmpnam
%5 = tail call i64 @___path_search(i8* %0, i32 %4, i32* null, i32* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = tail call i64 @__gen_tempname(i8* %0, i32 3, i32 0, i32 0, i32 0)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i8* %0, i8* null
br label %11
11: ; preds = %7, %3, %1
%12 = phi i8* [ null, %1 ], [ null, %3 ], [ %10, %7 ]
ret i8* %12
}