#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 /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ _error(char *, int);
int /*<<< orphan*/ errno;
char *malloc(size_t);
size_t rand();
size_t strlen(char const *);
char *_makepasswd_password(char const *characters, size_t min, size_t max) {
  char *ret;
  size_t len = min;
  size_t clen;
  size_t i;
  if (characters == NULL)
    return NULL;
  if ((clen = strlen(characters)) == 0) {
    errno = EINVAL;
    _error("password", 1);
    return NULL;
  }
  if (max > min)
    len += rand() % (max - min + 1);
  if ((ret = malloc(len + 1)) == NULL) {
    _error("malloc", 1);
    return NULL;
  }
  for (i = 0; i < len; i++)
    ret[i] = characters[rand() % clen];
  ret[len] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<_makepasswd_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <_makepasswd_password+0x34>
movq   $0x0,-0x8(%rbp)
jmp    1286 <_makepasswd_password+0x146>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11bb <_makepasswd_password+0x7b>
mov    0x2e46(%rip),%rax
mov    (%rax),%ecx
mov    0x2e45(%rip),%rax
mov    %ecx,(%rax)
lea    0xe5c(%rip),%rdi
mov    $0x1,%esi
call   1050 <_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1286 <_makepasswd_password+0x146>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11e9 <_makepasswd_password+0xa9>
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x20(%rbp),%rcx
sub    -0x18(%rbp),%rcx
add    $0x1,%rcx
xor    %edx,%edx
div    %rcx
add    -0x30(%rbp),%rdx
mov    %rdx,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1222 <_makepasswd_password+0xe2>
lea    0xdfe(%rip),%rdi
mov    $0x1,%esi
call   1050 <_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    1286 <_makepasswd_password+0x146>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1272 <_makepasswd_password+0x132>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x38(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax,%rdx,1),%dl
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    122a <_makepasswd_password+0xea>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_makepasswd_password>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     1219 <_makepasswd_password+0xd9>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %rax,%rax
je     118b <_makepasswd_password+0x4b>
mov    %rax,%r13
sub    %r14,%r12
jbe    11ae <_makepasswd_password+0x6e>
xor    %eax,%eax
call   1060 <rand@plt>
add    $0x1,%r12
mov    %rax,%rcx
or     %r12,%rcx
shr    $0x20,%rcx
je     11a6 <_makepasswd_password+0x66>
xor    %edx,%edx
div    %r12
jmp    11ab <_makepasswd_password+0x6b>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    0x2e45(%rip),%rcx
mov    %eax,(%rcx)
lea    0xe5c(%rip),%rdi
jmp    120f <_makepasswd_password+0xcf>
xor    %edx,%edx
div    %r12d
add    %rdx,%r14
lea    0x1(%r14),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1208 <_makepasswd_password+0xc8>
mov    %rax,%r12
test   %r14,%r14
je     1201 <_makepasswd_password+0xc1>
xor    %ebx,%ebx
jmp    11e7 <_makepasswd_password+0xa7>
nopl   0x0(%rax,%rax,1)
xor    %edx,%edx
div    %r13
movzbl (%r15,%rdx,1),%eax
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1201 <_makepasswd_password+0xc1>
xor    %eax,%eax
call   1060 <rand@plt>
mov    %rax,%rcx
or     %r13,%rcx
shr    $0x20,%rcx
jne    11d0 <_makepasswd_password+0x90>
xor    %edx,%edx
div    %r13d
jmp    11d5 <_makepasswd_password+0x95>
movb   $0x0,(%r12,%r14,1)
jmp    121c <_makepasswd_password+0xdc>
lea    0xdfa(%rip),%rdi
mov    $0x1,%esi
call   1050 <_error@plt>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"password\00"
@.str.1 = [7 x i8] c"malloc\00"
define i8* @_makepasswd_password(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%12 = load i64, i64* %6
store i64 %12, i64* %9
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i8* null, i8** %4
br label %66
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i64 @strlen(i8* %17)
store i64 %18, i64* %10
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @EINVAL
store i32 %21, i32* @errno
%22 = call i32 @_error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1)
store i8* null, i8** %4
br label %66
23: ; preds = %16
%24 = load i64, i64* %7
%25 = load i64, i64* %6
%26 = icmp ugt i64 %24, %25
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = call i64 (...) @rand()
%29 = load i64, i64* %7
%30 = load i64, i64* %6
%31 = sub i64 %29, %30
%32 = add i64 %31, 1
%33 = urem i64 %28, %32
%34 = load i64, i64* %9
%35 = add i64 %34, %33
store i64 %35, i64* %9
br label %36
36: ; preds = %27, %23
%37 = load i64, i64* %9
%38 = add i64 %37, 1
%39 = call i8* @malloc(i64 %38)
store i8* %39, i8** %8
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @_error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
store i8* null, i8** %4
br label %66
43: ; preds = %36
store i64 0, i64* %11
br label %44
44: ; preds = %58, %43
%45 = load i64, i64* %11
%46 = load i64, i64* %9
%47 = icmp ult i64 %45, %46
br i1 %47, label %48, label %61
48: ; preds = %44
%49 = load i8*, i8** %5
%50 = call i64 (...) @rand()
%51 = load i64, i64* %10
%52 = urem i64 %50, %51
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = load i8, i8* %53
%55 = load i8*, i8** %8
%56 = load i64, i64* %11
%57 = getelementptr inbounds i8, i8* %55, i64 %56
store i8 %54, i8* %57
br label %58
58: ; preds = %48
%59 = load i64, i64* %11
%60 = add i64 %59, 1
store i64 %60, i64* %11
br label %44
61: ; preds = %44
%62 = load i8*, i8** %8
%63 = load i64, i64* %9
%64 = getelementptr inbounds i8, i8* %62, i64 %63
store i8 0, i8* %64
%65 = load i8*, i8** %8
store i8* %65, i8** %4
br label %66
66: ; preds = %61, %41, %20, %15
%67 = load i8*, i8** %4
ret i8* %67
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@.str = [9 x i8] c"password\00"
@.str.1 = [7 x i8] c"malloc\00"
define noalias i8* @_makepasswd_password(i8* %0, i64 %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %39, label %5
5: ; preds = %3
%6 = tail call i64 @strlen(i8* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
%10 = tail call i32 @_error(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 1)
br label %39
11: ; preds = %5
%12 = icmp ugt i64 %2, %1
br i1 %12, label %13, label %19
13: ; preds = %11
%14 = tail call i64 (...) @rand()
%15 = sub i64 1, %1
%16 = add i64 %15, %2
%17 = urem i64 %14, %16
%18 = add i64 %17, %1
br label %19
19: ; preds = %13, %11
%20 = phi i64 [ %18, %13 ], [ %1, %11 ]
%21 = add i64 %20, 1
%22 = tail call i8* @malloc(i64 %21)
%23 = icmp eq i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %19
%25 = icmp eq i64 %20, 0
br i1 %25, label %37, label %28
26: ; preds = %19
%27 = tail call i32 @_error(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %39
28: ; preds = %24, %28
%29 = phi i64 [ %35, %28 ], [ 0, %24 ]
%30 = tail call i64 (...) @rand()
%31 = urem i64 %30, %6
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %22, i64 %29
store i8 %33, i8* %34
%35 = add nuw i64 %29, 1
%36 = icmp eq i64 %35, %20
br i1 %36, label %37, label %28
37: ; preds = %28, %24
%38 = getelementptr inbounds i8, i8* %22, i64 %20
store i8 0, i8* %38
br label %39
39: ; preds = %3, %37, %26, %8
%40 = phi i8* [ null, %8 ], [ null, %26 ], [ %22, %37 ], [ null, %3 ]
ret i8* %40
}