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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int read(int, unsigned char *, int);
int main() {
  int fd = open("/dev/urandom", O_RDONLY);
  char pwd[10 + 1];
  unsigned char pwrand[10];
  static const char pwchars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                "abcdefghijklmnopqrstuvwxyz"
                                "0123456789.-";
  int i;
  if (fd == -1)
    err(1, "open(/dev/urandom)");
  if (read(fd, pwrand, sizeof(pwrand)) != sizeof(pwrand))
    err(1, "read(/dev/urandom)");
  close(fd);
  for (i = 0; i < sizeof(pwrand); i++)
    pwd[i] = pwchars[pwrand[i] % (sizeof(pwchars) - 1)];
  pwd[i] = '\0';
  printf("%s\n", pwd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1192 <main+0x42>
mov    $0x1,%edi
lea    0xe80(%rip),%rsi
call   1060 <err@plt>
mov    -0x8(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
cltq
cmp    $0xa,%rax
je     11c0 <main+0x70>
mov    $0x1,%edi
lea    0xe65(%rip),%rsi
call   1060 <err@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0xa,%rax
jae    120c <main+0xbc>
movslq -0x24(%rbp),%rax
movzbl -0x1d(%rbp,%rax,1),%eax
mov    %eax,%ecx
and    $0x3f,%rcx
lea    0xe4d(%rip),%rax
mov    (%rax,%rcx,1),%cl
movslq -0x24(%rbp),%rax
mov    %cl,-0x13(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cf <main+0x7f>
movslq -0x24(%rbp),%rax
movb   $0x0,-0x13(%rbp,%rax,1)
lea    -0x13(%rbp),%rsi
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1182 <main+0x32>
lea    0xe95(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
lea    0xb(%rsp),%rsi
mov    %ebx,%edi
mov    $0xa,%edx
call   1050 <read@plt>
cmp    $0xa,%eax
je     11a9 <main+0x59>
lea    0xe81(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
mov    %ebx,%edi
call   1040 <close@plt>
movzbl 0xb(%rsp),%ecx
and    $0x3f,%ecx
lea    0xe81(%rip),%rax
mov    (%rcx,%rax,1),%cl
mov    %cl,0x15(%rsp)
movzbl 0xc(%rsp),%ecx
and    $0x3f,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x16(%rsp)
movzbl 0xd(%rsp),%ecx
and    $0x3f,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x17(%rsp)
movzbl 0xe(%rsp),%ecx
and    $0x3f,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x18(%rsp)
movzbl 0xf(%rsp),%ecx
and    $0x3f,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x19(%rsp)
movzbl 0x10(%rsp),%ecx
and    $0x3f,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x1a(%rsp)
movzbl 0x11(%rsp),%ecx
and    $0x3f,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x1b(%rsp)
movzbl 0x12(%rsp),%ecx
and    $0x3f,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x1c(%rsp)
movzbl 0x13(%rsp),%ecx
and    $0x3f,%ecx
mov    (%rcx,%rax,1),%cl
mov    %cl,0x1d(%rsp)
movzbl 0x14(%rsp),%ecx
and    $0x3f,%ecx
mov    (%rcx,%rax,1),%al
mov    %al,0x1e(%rsp)
movb   $0x0,0x1f(%rsp)
lea    0xdda(%rip),%rdi
lea    0x15(%rsp),%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@main.pwchars = internal constant [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-\00"
@.str.1 = [19 x i8] c"open(/dev/urandom)\00"
@.str.2 = [19 x i8] c"read(/dev/urandom)\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [11 x i8]
%4 = alloca [10 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = load i32, i32* %2
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 10)
%16 = sext i32 %15 to i64
%17 = icmp ne i64 %16, 10
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = load i32, i32* %2
%22 = call i32 @close(i32 %21)
store i32 0, i32* %5
br label %23
23: ; preds = %39, %20
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = icmp ult i64 %25, 10
br i1 %26, label %27, label %42
27: ; preds = %23
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i64
%33 = urem i64 %32, 64
%34 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 %37
store i8 %35, i8* %38
br label %39
39: ; preds = %27
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %23
42: ; preds = %23
%43 = load i32, i32* %5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 %44
store i8 0, i8* %45
%46 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/urandom\00"
@O_RDONLY = global i32 0
@main.pwchars = internal unnamed_addr constant [65 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-\00"
@.str.1 = [19 x i8] c"open(/dev/urandom)\00"
@.str.2 = [19 x i8] c"read(/dev/urandom)\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [11 x i8]
%2 = alloca [10 x i8]
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%7 = icmp eq i32 %4, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32 @read(i32 %4, i8* %6, i32 10)
%12 = icmp eq i32 %11, 10
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = tail call i32 @close(i32 %4)
%17 = load i8, i8* %6
%18 = and i8 %17, 63
%19 = zext i8 %18 to i64
%20 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %5
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 1
%23 = load i8, i8* %22
%24 = and i8 %23, 63
%25 = zext i8 %24 to i64
%26 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 1
store i8 %27, i8* %28
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 2
%30 = load i8, i8* %29
%31 = and i8 %30, 63
%32 = zext i8 %31 to i64
%33 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 2
store i8 %34, i8* %35
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 3
%37 = load i8, i8* %36
%38 = and i8 %37, 63
%39 = zext i8 %38 to i64
%40 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 3
store i8 %41, i8* %42
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 4
%44 = load i8, i8* %43
%45 = and i8 %44, 63
%46 = zext i8 %45 to i64
%47 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 4
store i8 %48, i8* %49
%50 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 5
%51 = load i8, i8* %50
%52 = and i8 %51, 63
%53 = zext i8 %52 to i64
%54 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %53
%55 = load i8, i8* %54
%56 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 5
store i8 %55, i8* %56
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 6
%58 = load i8, i8* %57
%59 = and i8 %58, 63
%60 = zext i8 %59 to i64
%61 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 6
store i8 %62, i8* %63
%64 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 7
%65 = load i8, i8* %64
%66 = and i8 %65, 63
%67 = zext i8 %66 to i64
%68 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 7
store i8 %69, i8* %70
%71 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 8
%72 = load i8, i8* %71
%73 = and i8 %72, 63
%74 = zext i8 %73 to i64
%75 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %74
%76 = load i8, i8* %75
%77 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 8
store i8 %76, i8* %77
%78 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 9
%79 = load i8, i8* %78
%80 = and i8 %79, 63
%81 = zext i8 %80 to i64
%82 = getelementptr inbounds [65 x i8], [65 x i8]* @main.pwchars, i64 0, i64 %81
%83 = load i8, i8* %82
%84 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 9
store i8 %83, i8* %84
%85 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 10
store i8 0, i8* %85
%86 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
ret i32 0
}