#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_int(int const);
int /*<<< orphan*/ xasprintf(char **, char const *, char *);
int /*<<< orphan*/ xfree(char *);
char *xmalloc(int);
char *rand_str(const int maxlen, const char *fmt) {
  char *res;
  int i, len;
  len = rand_int(maxlen) + 1;
  res = xmalloc(len + 1);
  res[len] = '\0';
  for (i = 0; i < len; i++) {
    int c = rand_int(26 + 26 + 10);
    if (c < 26)
      c += 'a';
    else if (c < 52)
      c = (c - 26) + 'A';
    else
      c = (c - 52) + '0';
    res[i] = c;
  }
  if (fmt) {
    char *tmp;
    xasprintf(&tmp, fmt, res);
    xfree(res);
    return tmp;
  } else
    return res;
}


x86 assembly (clang, -O0):
<rand_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <rand_int@plt>
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
add    $0x1,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11fa <rand_str+0xba>
mov    $0x3e,%edi
call   1060 <rand_int@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1a,-0x2c(%rbp)
jge    11b0 <rand_str+0x70>
mov    -0x2c(%rbp),%eax
add    $0x61,%eax
mov    %eax,-0x2c(%rbp)
jmp    11dc <rand_str+0x9c>
cmpl   $0x34,-0x2c(%rbp)
jge    11cb <rand_str+0x8b>
mov    -0x2c(%rbp),%eax
sub    $0x1a,%eax
add    $0x41,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d7 <rand_str+0x97>
mov    -0x2c(%rbp),%eax
sub    $0x34,%eax
add    $0x30,%eax
mov    %eax,-0x2c(%rbp)
jmp    11dc <rand_str+0x9c>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117f <rand_str+0x3f>
cmpq   $0x0,-0x18(%rbp)
je     122c <rand_str+0xec>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x38(%rbp),%rdi
call   1050 <xasprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <xfree@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1234 <rand_str+0xf4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_str>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
call   1060 <rand_int@plt>
mov    %eax,%r15d
lea    0x1(%r15),%ebx
lea    0x2(%r15),%edi
call   1040 <xmalloc@plt>
mov    %rax,%r12
movslq %ebx,%rax
movb   $0x0,(%r12,%rax,1)
test   %r15d,%r15d
js     11b0 <rand_str+0x70>
mov    %ebx,%r15d
xor    %ebx,%ebx
mov    $0x61,%ebp
jmp    1195 <rand_str+0x55>
cmp    $0x1a,%eax
cmovl  %ebp,%ecx
add    %eax,%ecx
mov    %cl,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
je     11b0 <rand_str+0x70>
mov    $0x3e,%edi
call   1060 <rand_int@plt>
mov    $0x27,%ecx
cmp    $0x34,%eax
jb     1180 <rand_str+0x40>
mov    $0xfc,%ecx
jmp    1180 <rand_str+0x40>
test   %r14,%r14
je     11d2 <rand_str+0x92>
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <xasprintf@plt>
mov    %r12,%rdi
call   1030 <xfree@plt>
mov    0x8(%rsp),%r12
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @rand_str(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = tail call i32 @rand_int(i32 %0)
%5 = add i32 %4, 1
%6 = add nsw i32 %4, 2
%7 = tail call i8* @xmalloc(i32 %6)
%8 = sext i32 %5 to i64
%9 = getelementptr inbounds i8, i8* %7, i64 %8
store i8 0, i8* %9
%10 = icmp slt i32 %4, 0
br i1 %10, label %25, label %11
11: ; preds = %2
%12 = zext i32 %5 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %23, %13 ]
%15 = tail call i32 @rand_int(i32 62)
%16 = icmp slt i32 %15, 26
%17 = icmp ult i32 %15, 52
%18 = select i1 %17, i32 39, i32 252
%19 = select i1 %16, i32 97, i32 %18
%20 = add i32 %15, %19
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds i8, i8* %7, i64 %14
store i8 %21, i8* %22
%23 = add nuw nsw i64 %14, 1
%24 = icmp eq i64 %23, %12
br i1 %24, label %25, label %13
25: ; preds = %13, %2
%26 = icmp eq i8* %1, null
br i1 %26, label %32, label %27
27: ; preds = %25
%28 = bitcast i8** %3 to i8*
%29 = call i32 @xasprintf(i8** %3, i8* %1, i8* %7)
%30 = call i32 @xfree(i8* %7)
%31 = load i8*, i8** %3
br label %32
32: ; preds = %25, %27
%33 = phi i8* [ %31, %27 ], [ %7, %25 ]
ret i8* %33
}