#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 rand();
void dict_rand_string(char *buf, int len) {
  int p;
  while (len--)
    *buf++ = ((p = rand() % 52) >= 26) ? (p - 26 + 'A') : (p + 'a');
  *buf = '\0';
}


x86 assembly (clang, -O0):
<dict_rand_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     1183 <dict_rand_string+0x73>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x34,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
cmp    $0x1a,%edx
jl     115f <dict_rand_string+0x4f>
mov    -0x10(%rbp),%eax
sub    $0x1a,%eax
add    $0x41,%eax
mov    %eax,-0x14(%rbp)
jmp    1168 <dict_rand_string+0x58>
mov    -0x10(%rbp),%eax
add    $0x61,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    111f <dict_rand_string+0xf>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dict_rand_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %esi,%esi
je     1164 <dict_rand_string+0x54>
mov    %esi,%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
mov    %eax,%edx
sub    %ecx,%edx
lea    0x27(%rdx),%esi
neg    %ecx
cmp    $0x1a,%edx
lea    0x61(%rax,%rcx,1),%ecx
cmovge %esi,%ecx
lea    0x1(%r14),%rax
mov    %cl,(%r14)
mov    %rax,%r14
add    $0xffffffff,%ebx
jne    1120 <dict_rand_string+0x10>
jmp    1167 <dict_rand_string+0x57>
mov    %r14,%rax
movb   $0x0,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @dict_rand_string(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %6
6: ; preds = %21, %2
%7 = load i32, i32* %4
%8 = add nsw i32 %7, -1
store i32 %8, i32* %4
%9 = icmp ne i32 %7, 0
br i1 %9, label %10, label %26
10: ; preds = %6
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 52
store i32 %12, i32* %5
%13 = icmp sge i32 %12, 26
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 26
%17 = add nsw i32 %16, 65
br label %21
18: ; preds = %10
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 97
br label %21
21: ; preds = %18, %14
%22 = phi i32 [ %17, %14 ], [ %20, %18 ]
%23 = trunc i32 %22 to i8
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %3
store i8 %23, i8* %24
br label %6
26: ; preds = %6
%27 = load i8*, i8** %3
store i8 0, i8* %27
ret void
}

LLVM IR (-O2):
define void @dict_rand_string(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %16, label %4
4: ; preds = %2, %4
%5 = phi i8* [ %14, %4 ], [ %0, %2 ]
%6 = phi i32 [ %7, %4 ], [ %1, %2 ]
%7 = add nsw i32 %6, -1
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 52
%10 = icmp sgt i32 %9, 25
%11 = select i1 %10, i32 39, i32 97
%12 = add nsw i32 %11, %9
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %13, i8* %5
%15 = icmp eq i32 %7, 0
br i1 %15, label %16, label %4
16: ; preds = %4, %2
%17 = phi i8* [ %0, %2 ], [ %14, %4 ]
store i8 0, i8* %17
ret void
}