#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 ranf();
void MakeRandomString(char *string, int length) {
  int i;
  length = (((0) < (length) ? (length) : (0)));
  for (i = 0; i < length; i++)
    string[i] = 65 + (int)(ranf() * 26);
  string[i] = 0;
}


x86 assembly (clang, -O0):
<MakeRandomString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jge    1135 <MakeRandomString+0x25>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    113f <MakeRandomString+0x2f>
xor    %eax,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <MakeRandomString+0x2f>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1180 <MakeRandomString+0x70>
mov    $0x0,%al
call   1030 <ranf@plt>
imul   $0x1a,%eax,%eax
add    $0x41,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114c <MakeRandomString+0x3c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MakeRandomString>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %r15d,%r15d
test   %esi,%esi
cmovs  %r15d,%esi
jle    114f <MakeRandomString+0x3f>
mov    %esi,%r15d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <ranf@plt>
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
add    $0x41,%cl
mov    %cl,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <MakeRandomString+0x20>
movb   $0x0,(%r14,%r15,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @MakeRandomString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp slt i32 0, %6
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = load i32, i32* %4
br label %11
10: ; preds = %2
br label %11
11: ; preds = %10, %8
%12 = phi i32 [ %9, %8 ], [ 0, %10 ]
store i32 %12, i32* %4
store i32 0, i32* %5
br label %13
13: ; preds = %26, %11
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %29
17: ; preds = %13
%18 = call i32 (...) @ranf()
%19 = mul nsw i32 %18, 26
%20 = add nsw i32 65, %19
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
br label %26
26: ; preds = %17
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %13
29: ; preds = %13
%30 = load i8*, i8** %3
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
ret void
}

LLVM IR (-O2):
define void @MakeRandomString(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
%4 = select i1 %3, i32 %1, i32 0
br i1 %3, label %5, label %18
5: ; preds = %2
%6 = zext i32 %4 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %14, %7 ]
%9 = tail call i32 (...) @ranf()
%10 = trunc i32 %9 to i8
%11 = mul i8 %10, 26
%12 = add i8 %11, 65
%13 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %12, i8* %13
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = zext i32 %4 to i64
br label %18
18: ; preds = %2, %16
%19 = phi i64 [ %17, %16 ], [ 0, %2 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 0, i8* %20
ret void
}