#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 */
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
char *tmpnam(char *s) {
  static char name[] = "/tmp/tn000000000000";
  char *p;
  do {
    p = name + 7;
    while (*p == '9')
      *p++ = '0';
    if (*p == '\0')
      return NULL;
    ++*p;
  } while (access(name, 0) == 0);
  if (s) {
    strcpy(s, name);
    return s;
  }
  return name;
}


x86 assembly (clang, -O0):
<tmpnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0x2f0d(%rip),%rax
add    $0x7,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jne    1162 <tmpnam+0x42>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x30,(%rax)
jmp    113b <tmpnam+0x1b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117f <tmpnam+0x5f>
movq   $0x0,-0x8(%rbp)
jmp    11d5 <tmpnam+0xb5>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
add    $0x1,%cl
mov    %cl,(%rax)
lea    0x2eaf(%rip),%rdi
xor    %esi,%esi
call   1040 <access@plt>
cmp    $0x0,%rax
je     112c <tmpnam+0xc>
cmpq   $0x0,-0x10(%rbp)
je     11ca <tmpnam+0xaa>
mov    -0x10(%rbp),%rdi
lea    0x2e88(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d5 <tmpnam+0xb5>
lea    0x2e6f(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmpnam>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0x2f18(%rip),%r15
lea    0x2f0a(%rip),%rbx
mov    %r15,%rcx
jmp    1147 <tmpnam+0x27>
nopl   0x0(%rax,%rax,1)
movb   $0x30,(%rcx)
add    $0x1,%rcx
movzbl (%rcx),%eax
cmp    $0x39,%al
je     1140 <tmpnam+0x20>
test   %al,%al
je     1181 <tmpnam+0x61>
add    $0x1,%al
mov    %al,(%rcx)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <access@plt>
mov    %r15,%rcx
test   %rax,%rax
je     1147 <tmpnam+0x27>
test   %r14,%r14
je     1183 <tmpnam+0x63>
lea    0x2ecc(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rbx
jmp    1183 <tmpnam+0x63>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@tmpnam.name = internal global [20 x i8] c"/tmp/tn000000000000\00"
define i8* @tmpnam(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
br label %5
5: ; preds = %24, %1
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tmpnam.name, i64 0, i64 7), i8** %4
br label %6
6: ; preds = %11, %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 57
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %4
store i8 48, i8* %12
br label %6
14: ; preds = %6
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
store i8* null, i8** %2
br label %35
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = add i8 %22, 1
store i8 %23, i8* %21
br label %24
24: ; preds = %20
%25 = call i64 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tmpnam.name, i64 0, i64 0), i32 0)
%26 = icmp eq i64 %25, 0
br i1 %26, label %5, label %27
27: ; preds = %24
%28 = load i8*, i8** %3
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i8*, i8** %3
%32 = call i32 @strcpy(i8* %31, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tmpnam.name, i64 0, i64 0))
%33 = load i8*, i8** %3
store i8* %33, i8** %2
br label %35
34: ; preds = %27
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tmpnam.name, i64 0, i64 0), i8** %2
br label %35
35: ; preds = %34, %30, %19
%36 = load i8*, i8** %2
ret i8* %36
}

LLVM IR (-O2):
@tmpnam.name = internal global [20 x i8] c"/tmp/tn000000000000\00"
define i8* @tmpnam(i8* %0) {
br label %2
2: ; preds = %7, %1
%3 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @tmpnam.name, i64 0, i64 7), %1 ], [ %8, %7 ]
%4 = load i8, i8* %3
switch i8 %4, label %9 [
i8 57, label %5
i8 0, label %17
]
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
store i8 48, i8* %3
br label %7
7: ; preds = %5, %9
%8 = phi i8* [ %6, %5 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @tmpnam.name, i64 0, i64 7), %9 ]
br label %2
9: ; preds = %2
%10 = add i8 %4, 1
store i8 %10, i8* %3
%11 = tail call i64 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tmpnam.name, i64 0, i64 0), i32 0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %7, label %13
13: ; preds = %9
%14 = icmp eq i8* %0, null
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @tmpnam.name, i64 0, i64 0))
br label %17
17: ; preds = %2, %13, %15
%18 = phi i8* [ %0, %15 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @tmpnam.name, i64 0, i64 0), %13 ], [ null, %2 ]
ret i8* %18
}