#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__ malloc(int);
int rand();
char *getname(void) {
  char *name = NULL;
  int len = (rand() % 30) + 1;
  int i;
  name = (char *)malloc(len + 1);
  if (name) {
    for (i = 0; i < len; i++) {
      if ((rand() % 10) == 0) {
        name[i] = (char)(65 + ((rand() + 1) % 10) + (i % 10));
      } else if ((rand() % 10) == 1) {
        name[i] = (char)(48 + ((rand() + 1) % 10));
      } else {
        name[i] = (char)(97 + ((rand() + 1) % 10) + (i % 10));
      }
    }
    name[len] = '\0';
  }
  return name;
}


x86 assembly (clang, -O0):
<getname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x1e,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1030 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     125a <getname+0x13a>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124e <getname+0x12e>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11c4 <getname+0xa4>
mov    $0x0,%al
call   1040 <rand@plt>
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x14(%rbp),%eax
add    %edx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    123b <getname+0x11b>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1201 <getname+0xe1>
mov    $0x0,%al
call   1040 <rand@plt>
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1236 <getname+0x116>
mov    $0x0,%al
call   1040 <rand@plt>
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%eax
add    %edx,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    123b <getname+0x11b>
jmp    1240 <getname+0x120>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1166 <getname+0x46>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getname>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%ebp
cltq
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x4,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x5,%edx
mov    %ecx,%ebx
sub    %edx,%ebx
add    %ecx,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x2,%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     12b1 <getname+0x191>
mov    %rax,0x10(%rsp)
add    %ebx,%ebp
movslq %ebp,%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
test   %eax,%eax
js     12a3 <getname+0x183>
mov    0x8(%rsp),%ebp
mov    $0x61,%r12b
xor    %r13d,%r13d
mov    0x10(%rsp),%r15
xor    %r14d,%r14d
jmp    11fc <getname+0xdc>
xchg   %ax,%ax
add    $0x1,%eax
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ecx
mov    %r14d,%eax
mov    $0xcccccccd,%edx
imul   %rdx,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%edx
mov    %r14d,%eax
sub    %edx,%eax
add    %ecx,%eax
add    $0x41,%al
mov    %al,(%r15)
add    $0x1,%r14
add    $0x1,%r15
add    $0x1,%r12b
add    $0x1,%r13d
add    $0xffffffffffffffff,%rbp
je     12a3 <getname+0x183>
xor    %eax,%eax
call   1040 <rand@plt>
imul   $0xcccccccd,%eax,%ebx
add    $0x19999998,%ebx
ror    %ebx
xor    %eax,%eax
call   1040 <rand@plt>
cmp    $0x19999998,%ebx
jbe    11a0 <getname+0x80>
mov    %r12d,%ebx
movslq %eax,%r12
imul   $0x66666667,%r12,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r12d
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x1(%rax),%ecx
movslq %ecx,%rcx
imul   $0x66666667,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
cmp    $0x1,%r12d
jne    1280 <getname+0x160>
add    $0x30,%al
mov    %ebx,%r12d
jmp    11df <getname+0xbf>
nop
mov    %r13d,%ecx
mov    $0xcccccccd,%edx
imul   %rdx,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %ebx,%r12d
mov    %ebx,%edx
sub    %cl,%dl
add    %dl,%al
jmp    11df <getname+0xbf>
mov    0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @getname() {
%1 = tail call i32 (...) @rand()
%2 = srem i32 %1, 30
%3 = add nsw i32 %2, 1
%4 = add nsw i32 %2, 2
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %49, label %8
8: ; preds = %0
%9 = icmp slt i32 %2, 0
br i1 %9, label %46, label %10
10: ; preds = %8
%11 = zext i32 %3 to i64
br label %12
12: ; preds = %10, %41
%13 = phi i64 [ 0, %10 ], [ %44, %41 ]
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 10
%16 = icmp eq i32 %15, 0
%17 = tail call i32 (...) @rand()
br i1 %16, label %18, label %26
18: ; preds = %12
%19 = add nsw i32 %17, 1
%20 = srem i32 %19, 10
%21 = trunc i64 %13 to i32
%22 = urem i32 %21, 10
%23 = add nuw nsw i32 %22, 65
%24 = add nsw i32 %23, %20
%25 = trunc i32 %24 to i8
br label %41
26: ; preds = %12
%27 = srem i32 %17, 10
%28 = icmp eq i32 %27, 1
%29 = tail call i32 (...) @rand()
%30 = add nsw i32 %29, 1
%31 = srem i32 %30, 10
br i1 %28, label %32, label %35
32: ; preds = %26
%33 = trunc i32 %31 to i8
%34 = add nsw i8 %33, 48
br label %41
35: ; preds = %26
%36 = trunc i64 %13 to i32
%37 = urem i32 %36, 10
%38 = add nuw nsw i32 %37, 97
%39 = add nsw i32 %38, %31
%40 = trunc i32 %39 to i8
br label %41
41: ; preds = %18, %35, %32
%42 = phi i8 [ %25, %18 ], [ %40, %35 ], [ %34, %32 ]
%43 = getelementptr inbounds i8, i8* %6, i64 %13
store i8 %42, i8* %43
%44 = add nuw nsw i64 %13, 1
%45 = icmp eq i64 %44, %11
br i1 %45, label %46, label %12
46: ; preds = %41, %8
%47 = sext i32 %3 to i64
%48 = getelementptr inbounds i8, i8* %6, i64 %47
store i8 0, i8* %48
br label %49
49: ; preds = %46, %0
ret i8* %6
}