#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*/ fprintf(int /*<<< orphan*/, char *);
char *gettext(char *);
scalar_t__ malloc(unsigned int);
scalar_t__ rand();
int /*<<< orphan*/ stderr;
char *random_name(unsigned int len) {
  char *str = (char *)malloc(len + 1);
  if (!str) {
    fprintf(stderr,
            gettext("random_name(): malloc() failed: insufficient memory.\n"));
    return NULL;
  }
  str[len] = '\0';
  unsigned int rand_char;
  for (int i = 0; i < len; i++) {
    do {
      rand_char = (unsigned int)rand() % 123;
    } while (rand_char < 48 || (rand_char > 57 && rand_char < 65) ||
             (rand_char > 90 && rand_char < 97));
    str[i] = (char)rand_char;
  }
  return (str);
}


x86 assembly (clang, -O0):
<random_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1195 <random_name+0x55>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    0xe88(%rip),%rdi
call   1030 <gettext@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1243 <random_name+0x103>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    123b <random_name+0xfb>
jmp    11b8 <random_name+0x78>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x7b,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x1c(%rbp)
mov    $0x1,%al
cmpl   $0x30,-0x1c(%rbp)
mov    %al,-0x25(%rbp)
jb     1212 <random_name+0xd2>
cmpl   $0x39,-0x1c(%rbp)
jbe    11f3 <random_name+0xb3>
mov    $0x1,%al
cmpl   $0x41,-0x1c(%rbp)
mov    %al,-0x25(%rbp)
jb     1212 <random_name+0xd2>
xor    %eax,%eax
cmpl   $0x5a,-0x1c(%rbp)
mov    %al,-0x26(%rbp)
jbe    120c <random_name+0xcc>
cmpl   $0x61,-0x1c(%rbp)
setb   %al
mov    %al,-0x26(%rbp)
mov    -0x26(%rbp),%al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    11b8 <random_name+0x78>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a7 <random_name+0x67>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x1(%r14),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11c9 <random_name+0x89>
mov    %rax,%r15
mov    %r14d,%r12d
movb   $0x0,(%rax,%r12,1)
test   %r14d,%r14d
je     11eb <random_name+0xab>
movabs $0x7e0000007f,%rbx
xor    %r14d,%r14d
jmp    1190 <random_name+0x50>
mov    %al,(%r15,%r14,1)
add    $0x1,%r14
cmp    %r12,%r14
je     11eb <random_name+0xab>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ecx
imul   $0xa6810a7,%rcx,%rcx
shr    $0x20,%rcx
mov    %eax,%edx
sub    %ecx,%edx
shr    %edx
add    %ecx,%edx
shr    $0x6,%edx
imul   $0x7b,%edx,%ecx
sub    %ecx,%eax
cmp    $0x30,%eax
jb     1190 <random_name+0x50>
lea    -0x3a(%rax),%ecx
cmp    $0x26,%ecx
ja     117c <random_name+0x3c>
bt     %rcx,%rbx
jb     1190 <random_name+0x50>
jmp    117c <random_name+0x3c>
mov    0x2e10(%rip),%rax
mov    (%rax),%ebx
lea    0xe27(%rip),%rdi
call   1030 <gettext@plt>
mov    %ebx,%edi
mov    %rax,%rsi
call   1040 <fprintf@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [54 x i8] c"random_name(): malloc() failed: insufficient memory.\0A\00"
define i8* @random_name(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = add i32 %7, 1
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = call i8* @gettext(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @fprintf(i32 %14, i8* %15)
store i8* null, i8** %2
br label %62
17: ; preds = %1
%18 = load i8*, i8** %4
%19 = load i32, i32* %3
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %21
store i32 0, i32* %6
br label %22
22: ; preds = %57, %17
%23 = load i32, i32* %6
%24 = load i32, i32* %3
%25 = icmp ult i32 %23, %24
br i1 %25, label %26, label %60
26: ; preds = %22
br label %27
27: ; preds = %48, %26
%28 = call i64 (...) @rand()
%29 = trunc i64 %28 to i32
%30 = urem i32 %29, 123
store i32 %30, i32* %5
br label %31
31: ; preds = %27
%32 = load i32, i32* %5
%33 = icmp ult i32 %32, 48
br i1 %33, label %48, label %34
34: ; preds = %31
%35 = load i32, i32* %5
%36 = icmp ugt i32 %35, 57
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %5
%39 = icmp ult i32 %38, 65
br i1 %39, label %48, label %40
40: ; preds = %37, %34
%41 = load i32, i32* %5
%42 = icmp ugt i32 %41, 90
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i32, i32* %5
%45 = icmp ult i32 %44, 97
br label %46
46: ; preds = %43, %40
%47 = phi i1 [ false, %40 ], [ %45, %43 ]
br label %48
48: ; preds = %46, %37, %31
%49 = phi i1 [ true, %37 ], [ true, %31 ], [ %47, %46 ]
br i1 %49, label %27, label %50
50: ; preds = %48
%51 = load i32, i32* %5
%52 = trunc i32 %51 to i8
%53 = load i8*, i8** %4
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 %52, i8* %56
br label %57
57: ; preds = %50
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
br label %22
60: ; preds = %22
%61 = load i8*, i8** %4
store i8* %61, i8** %2
br label %62
62: ; preds = %60, %13
%63 = load i8*, i8** %2
ret i8* %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [54 x i8] c"random_name(): malloc() failed: insufficient memory.\0A\00"
define i8* @random_name(i32 %0) {
%2 = add i32 %0, 1
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i8* @gettext(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @fprintf(i32 %7, i8* %8)
br label %29
10: ; preds = %1
%11 = zext i32 %0 to i64
%12 = getelementptr inbounds i8, i8* %4, i64 %11
store i8 0, i8* %12
%13 = icmp eq i32 %0, 0
br i1 %13, label %29, label %14
14: ; preds = %10, %24
%15 = phi i64 [ %27, %24 ], [ 0, %10 ]
br label %16
16: ; preds = %22, %14
%17 = tail call i64 (...) @rand()
%18 = freeze i64 %17
%19 = trunc i64 %18 to i32
%20 = urem i32 %19, 123
%21 = icmp ult i32 %20, 48
br i1 %21, label %22, label %23
22: ; preds = %16, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23, %23
br label %16
23: ; preds = %16
switch i32 %20, label %24 [
i32 96, label %22
i32 95, label %22
i32 94, label %22
i32 93, label %22
i32 92, label %22
i32 91, label %22
i32 64, label %22
i32 63, label %22
i32 62, label %22
i32 61, label %22
i32 60, label %22
i32 59, label %22
i32 58, label %22
]
24: ; preds = %23
%25 = trunc i32 %20 to i8
%26 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 %25, i8* %26
%27 = add nuw nsw i64 %15, 1
%28 = icmp eq i64 %27, %11
br i1 %28, label %29, label %14
29: ; preds = %24, %10, %6
%30 = phi i8* [ null, %6 ], [ %4, %10 ], [ %4, %24 ]
ret i8* %30
}