#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 */
typedef int /*<<< orphan*/ dict;

/* Variables and functions */
int /*<<< orphan*/ assert(char *);
int random();
char *mkpasswd(char *s, size_t size) {
  assert(s);
  if (!size) {
    return (NULL);
  }
  --size;
  static const char dict[] = "0123456789"
                             "abcdefghijklmnopqrstuvwxyz"
                             "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for (size_t i = 0; i < size; ++i) {
    s[i] = dict[random() % ((sizeof(dict) / sizeof(dict[0])) - 1)];
  }
  s[size] = 0;
  return (s);
}


x86 assembly (clang, -O0):
<mkpasswd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1151 <mkpasswd+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11c0 <mkpasswd+0xa0>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11ac <mkpasswd+0x8c>
mov    $0x0,%al
call   1040 <random@plt>
cltq
mov    $0x3e,%ecx
xor    %edx,%edx
div    %rcx
lea    0xe73(%rip),%rax
mov    (%rax,%rdx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1165 <mkpasswd+0x45>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkpasswd>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r13
mov    %rdi,%r14
call   1030 <assert@plt>
test   %r13,%r13
je     11a3 <mkpasswd+0x83>
add    $0xffffffffffffffff,%r13
je     119c <mkpasswd+0x7c>
movabs $0x8421084210842109,%r15
08 21 84
lea    0xeb0(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <random@plt>
movslq %eax,%rcx
mov    %rcx,%rax
shr    %rax
mul    %r15
shr    $0x4,%rdx
mov    %rdx,%rax
shl    $0x6,%rax
mov    %rdx,%rsi
sub    %rax,%rsi
add    %rdx,%rsi
add    %rcx,%rsi
movzbl (%r12,%rsi,1),%eax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1160 <mkpasswd+0x40>
movb   $0x0,(%r14,%r13,1)
jmp    11a6 <mkpasswd+0x86>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@mkpasswd.dict = internal constant [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @mkpasswd(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i8*, i8** %4
%8 = call i32 @assert(i8* %7)
%9 = load i64, i64* %5
%10 = icmp ne i64 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %2
store i8* null, i8** %3
br label %36
12: ; preds = %2
%13 = load i64, i64* %5
%14 = add i64 %13, -1
store i64 %14, i64* %5
store i64 0, i64* %6
br label %15
15: ; preds = %28, %12
%16 = load i64, i64* %6
%17 = load i64, i64* %5
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = call i32 (...) @random()
%21 = sext i32 %20 to i64
%22 = urem i64 %21, 62
%23 = getelementptr inbounds [63 x i8], [63 x i8]* @mkpasswd.dict, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %4
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8 %24, i8* %27
br label %28
28: ; preds = %19
%29 = load i64, i64* %6
%30 = add i64 %29, 1
store i64 %30, i64* %6
br label %15
31: ; preds = %15
%32 = load i8*, i8** %4
%33 = load i64, i64* %5
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %4
store i8* %35, i8** %3
br label %36
36: ; preds = %31, %11
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@mkpasswd.dict = internal unnamed_addr constant [63 x i8] c"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define i8* @mkpasswd(i8* %0, i64 %1) {
%3 = tail call i32 @assert(i8* %0)
%4 = icmp eq i64 %1, 0
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = add i64 %1, -1
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %10, %5
%9 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 0, i8* %9
br label %20
10: ; preds = %5, %10
%11 = phi i64 [ %18, %10 ], [ 0, %5 ]
%12 = tail call i32 (...) @random()
%13 = sext i32 %12 to i64
%14 = urem i64 %13, 62
%15 = getelementptr inbounds [63 x i8], [63 x i8]* @mkpasswd.dict, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 %16, i8* %17
%18 = add nuw i64 %11, 1
%19 = icmp eq i64 %18, %6
br i1 %19, label %8, label %10
20: ; preds = %2, %8
%21 = phi i8* [ %0, %8 ], [ null, %2 ]
ret i8* %21
}