#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 L_tmpnam;
int rand();
char *tmpnam(char s[L_tmpnam]) {
  char m[L_tmpnam];
  char *buf;
  int i;
  if (s != NULL)
    buf = s;
  else
    buf = m;
  for (i = 0; i < L_tmpnam - 1; i++) {
    char c = rand() % 52;
    if (c < 26)
      buf[i] = 'a' + c;
    else
      buf[i] = 'A' + (c - 26);
  }
  buf[L_tmpnam - 1] = 0;
  return buf;
}


x86 assembly (clang, -O0):
<tmpnam>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ebd(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1160 <tmpnam+0x50>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1168 <tmpnam+0x58>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e67(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ea <tmpnam+0xda>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x34,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%eax
cmp    $0x1a,%eax
jge    11c0 <tmpnam+0xb0>
movsbl -0x25(%rbp),%eax
add    $0x61,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11d7 <tmpnam+0xc7>
movsbl -0x25(%rbp),%eax
sub    $0x1a,%eax
add    $0x41,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11dc <tmpnam+0xcc>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    116f <tmpnam+0x5f>
mov    -0x20(%rbp),%rax
mov    0x2deb(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmpnam>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2ebe(%rip),%r14
movslq (%r14),%rax
mov    %eax,%ecx
mov    %rsp,%r12
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r12
mov    %r12,%rsp
test   %rdi,%rdi
cmovne %rdi,%r12
cmp    $0x2,%rax
jl     1196 <tmpnam+0x86>
mov    $0x61,%r15d
xor    %ebx,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x24,%rcx
add    %edx,%ecx
imul   $0x34,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x1a,%eax
mov    $0x27,%ecx
cmovl  %r15d,%ecx
add    %al,%cl
mov    %cl,(%r12,%rbx,1)
add    $0x1,%rbx
movslq (%r14),%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%rbx
jl     1150 <tmpnam+0x40>
jmp    119a <tmpnam+0x8a>
add    $0xffffffffffffffff,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@L_tmpnam = global i32 0
define i8* @tmpnam(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
store i8* %0, i8** %2
%8 = load i32, i32* @L_tmpnam
%9 = zext i32 %8 to i64
%10 = load i32, i32* @L_tmpnam
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i8, i64 %11
store i64 %11, i64* %4
%14 = load i8*, i8** %2
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = load i8*, i8** %2
store i8* %17, i8** %5
br label %19
18: ; preds = %1
store i8* %13, i8** %5
br label %19
19: ; preds = %18, %16
store i32 0, i32* %6
br label %20
20: ; preds = %52, %19
%21 = load i32, i32* %6
%22 = load i32, i32* @L_tmpnam
%23 = sub nsw i32 %22, 1
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %55
25: ; preds = %20
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 52
%28 = trunc i32 %27 to i8
store i8 %28, i8* %7
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
%31 = icmp slt i32 %30, 26
br i1 %31, label %32, label %41
32: ; preds = %25
%33 = load i8, i8* %7
%34 = sext i8 %33 to i32
%35 = add nsw i32 97, %34
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %5
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 %36, i8* %40
br label %51
41: ; preds = %25
%42 = load i8, i8* %7
%43 = sext i8 %42 to i32
%44 = sub nsw i32 %43, 26
%45 = add nsw i32 65, %44
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %5
%48 = load i32, i32* %6
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 %46, i8* %50
br label %51
51: ; preds = %41, %32
br label %52
52: ; preds = %51
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %20
55: ; preds = %20
%56 = load i8*, i8** %5
%57 = load i32, i32* @L_tmpnam
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
store i8 0, i8* %60
%61 = load i8*, i8** %5
%62 = load i8*, i8** %3
ret i8* %61
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
define i8* @tmpnam(i8* writeonly %0) {
%2 = load i32, i32* @L_tmpnam
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = icmp eq i8* %0, null
%6 = select i1 %5, i8* %4, i8* %0
%7 = icmp sgt i32 %2, 1
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = add nsw i32 %2, -1
%10 = sext i32 %9 to i64
br label %25
11: ; preds = %1, %11
%12 = phi i64 [ %20, %11 ], [ 0, %1 ]
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 52
%15 = icmp slt i32 %14, 26
%16 = trunc i32 %14 to i8
%17 = select i1 %15, i8 97, i8 39
%18 = add nsw i8 %17, %16
%19 = getelementptr inbounds i8, i8* %6, i64 %12
store i8 %18, i8* %19
%20 = add nuw nsw i64 %12, 1
%21 = load i32, i32* @L_tmpnam
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %20, %23
br i1 %24, label %11, label %25
25: ; preds = %11, %8
%26 = phi i64 [ %10, %8 ], [ %23, %11 ]
%27 = getelementptr inbounds i8, i8* %6, i64 %26
store i8 0, i8* %27
ret i8* %6
}