#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 */
size_t random_int(int /*<<< orphan*/, int);
int strlen(char *);
void random_string(char *str, int length, char *alphabet) {
  char *c;
  int max = strlen(alphabet) - 1;
  if (max < 0)
    max = 0;
  if (0 && length == 5) {
    for (c = str; c < str + 4; c++) {
      *c = '-';
    }
    *c++ = alphabet[random_int(0, max)];
  } else {
    for (c = str; c < str + length; c++) {
      *c = alphabet[random_int(0, max)];
    }
  }
  str[length] = '\0';
}


x86 assembly (clang, -O0):
<random_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1153 <random_string+0x33>
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    11a6 <random_string+0x86>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%esi
xor    %edi,%edi
call   1040 <random_int@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115b <random_string+0x3b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
mov    $0x1,%ebp
cmovg  %eax,%ebp
movslq %r15d,%rax
lea    (%rbx,%rax,1),%r15
test   %eax,%eax
jle    1169 <random_string+0x49>
add    $0xffffffff,%ebp
xor    %edi,%edi
mov    %ebp,%esi
call   1040 <random_int@plt>
movzbl (%r14,%rax,1),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
cmp    %r15,%rbx
jb     1150 <random_string+0x30>
movb   $0x0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @random_string(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = call i32 @strlen(i8* %9)
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %8
br label %15
15: ; preds = %14, %3
%16 = load i8*, i8** %4
store i8* %16, i8** %7
br label %17
17: ; preds = %31, %15
%18 = load i8*, i8** %7
%19 = load i8*, i8** %4
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = icmp ult i8* %18, %22
br i1 %23, label %24, label %34
24: ; preds = %17
%25 = load i8*, i8** %6
%26 = load i32, i32* %8
%27 = call i64 @random_int(i32 0, i32 %26)
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = load i8*, i8** %7
store i8 %29, i8* %30
br label %31
31: ; preds = %24
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %7
br label %17
34: ; preds = %17
%35 = load i8*, i8** %4
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
ret void
}

LLVM IR (-O2):
define void @random_string(i8* writeonly %0, i32 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = icmp sgt i32 %4, 1
%6 = select i1 %5, i32 %4, i32 1
%7 = add nsw i32 %6, -1
%8 = sext i32 %1 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %18
11: ; preds = %3, %11
%12 = phi i8* [ %16, %11 ], [ %0, %3 ]
%13 = tail call i64 @random_int(i32 0, i32 %7)
%14 = getelementptr inbounds i8, i8* %2, i64 %13
%15 = load i8, i8* %14
store i8 %15, i8* %12
%16 = getelementptr inbounds i8, i8* %12, i64 1
%17 = icmp ult i8* %16, %9
br i1 %17, label %11, label %18
18: ; preds = %11, %3
store i8 0, i8* %9
ret void
}