#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 random();
void randomString(char *buf) {
  char *choices = "abcd efgh ijkl mnop qrst uvw xyz";
  int i, n;
  n = random() % 10;
  *buf++ = 'A' + random() % 26;
  for (i = 0; i < n; i++)
    *buf++ = choices[random() % 32];
  *buf = '\0';
}


x86 assembly (clang, -O0):
<randomString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xedd(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    %dl,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b1 <randomString+0xa1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    $0x20,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <randomString+0x55>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomString>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <random@plt>
movslq %eax,%r14
imul   $0x66666667,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r14d
xor    %eax,%eax
call   1030 <random@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,(%rbx)
add    $0x1,%rbx
test   %r14d,%r14d
jle    11a7 <randomString+0x97>
lea    0xe87(%rip),%r15
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <random@plt>
lea    0x1f(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffffffe0,%ecx
sub    %ecx,%eax
cltq
movzbl (%rax,%r15,1),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0xffffffff,%r14d
jne    1180 <randomString+0x70>
movb   $0x0,(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [33 x i8] c"abcd efgh ijkl mnop qrst uvw xyz\00"
define void @randomString(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = call i32 (...) @random()
%7 = srem i32 %6, 10
store i32 %7, i32* %5
%8 = call i32 (...) @random()
%9 = srem i32 %8, 26
%10 = add nsw i32 65, %9
%11 = trunc i32 %10 to i8
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %2
store i8 %11, i8* %12
store i32 0, i32* %4
br label %14
14: ; preds = %27, %1
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = call i32 (...) @random()
%21 = srem i32 %20, 32
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %2
store i8 %24, i8* %25
br label %27
27: ; preds = %18
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %14
30: ; preds = %14
%31 = load i8*, i8** %2
store i8 0, i8* %31
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"abcd efgh ijkl mnop qrst uvw xyz\00"
define void @randomString(i8* nocapture writeonly %0) {
%2 = tail call i32 (...) @random()
%3 = srem i32 %2, 10
%4 = tail call i32 (...) @random()
%5 = srem i32 %4, 26
%6 = trunc i32 %5 to i8
%7 = add nsw i8 %6, 65
store i8 %7, i8* %0
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %21
10: ; preds = %1, %10
%11 = phi i8* [ %19, %10 ], [ %8, %1 ]
%12 = phi i32 [ %18, %10 ], [ 0, %1 ]
%13 = tail call i32 (...) @random()
%14 = srem i32 %13, 32
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [33 x i8], [33 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %11
%18 = add nuw nsw i32 %12, 1
%19 = getelementptr inbounds i8, i8* %11, i64 1
%20 = icmp eq i32 %18, %3
br i1 %20, label %21, label %10
21: ; preds = %10, %1
%22 = phi i8* [ %8, %1 ], [ %19, %10 ]
store i8 0, i8* %22
ret void
}