#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 unsigned int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
double log(int);
int pow(double, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(unsigned int);
unsigned int rollDie(unsigned int, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("Usage: passgen randFile numKeys\n");
    return 1;
  }
  FILE *file = fopen(argv[1], "r");
  uint32_t keys = atoi(argv[2]);
  uint32_t i;
  printf("password:");
  for (i = 0u; i < keys; i++) {
    uint32_t randVal = rollDie(32u, file);
    putchar('a' + randVal);
  }
  printf("\nThis password has %.2f bits of entropy\n",
         log(pow(32.0, keys)) / log(2));
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ba <main+0x3a>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127d <main+0xfd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe60(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    122d <main+0xad>
mov    -0x18(%rbp),%rsi
mov    $0x20,%edi
call   1060 <rollDie@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
add    $0x61,%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11f7 <main+0x77>
mov    -0x1c(%rbp),%edi
movsd  0xdc8(%rip),%xmm0
call   1090 <pow@plt>
mov    %eax,%edi
call   1070 <log@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x2,%edi
call   1070 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
lea    0xdcf(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1245 <main+0xb5>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe5a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r15d
lea    0xe41(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <printf@plt>
test   %r15d,%r15d
je     11fa <main+0x6a>
mov    %r15d,%ebp
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
mov    %rbx,%rsi
call   1070 <rollDie@plt>
lea    0x61(%rax),%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
jne    11e0 <main+0x50>
movsd  0xdfe(%rip),%xmm0
mov    %r15d,%edi
call   10a0 <pow@plt>
mov    %eax,%edi
call   1080 <log@plt>
movsd  %xmm0,(%rsp)
mov    $0x2,%edi
call   1080 <log@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
lea    0xde4(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1257 <main+0xc7>
lea    0xdf1(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"Usage: passgen randFile numKeys\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"password:\00"
@.str.3 = [41 x i8] c"\0AThis password has %.2f bits of entropy\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %46
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
br label %24
24: ; preds = %34, %14
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = icmp ult i32 %25, %26
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load i32*, i32** %6
%30 = call i32 @rollDie(i32 32, i32* %29)
store i32 %30, i32* %9
%31 = load i32, i32* %9
%32 = add i32 97, %31
%33 = call i32 @putchar(i32 %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %8
%36 = add i32 %35, 1
store i32 %36, i32* %8
br label %24
37: ; preds = %24
%38 = load i32, i32* %7
%39 = call i32 @pow(double 3.200000e+01, i32 %38)
%40 = call double @log(i32 %39)
%41 = call double @log(i32 2)
%42 = fdiv double %40, %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), double %42)
%44 = load i32*, i32** %6
%45 = call i32 @fclose(i32* %44)
store i32 0, i32* %3
br label %46
46: ; preds = %37, %12
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"password:\00"
@.str.3 = [41 x i8] c"\0AThis password has %.2f bits of entropy\0A\00"
@str = [32 x i8] c"Usage: passgen randFile numKeys\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
br label %29
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32 %12, 0
br i1 %14, label %22, label %15
15: ; preds = %6, %15
%16 = phi i32 [ %20, %15 ], [ 0, %6 ]
%17 = tail call i32 @rollDie(i32 32, i32* %9)
%18 = add i32 %17, 97
%19 = tail call i32 @putchar(i32 %18)
%20 = add nuw i32 %16, 1
%21 = icmp eq i32 %20, %12
br i1 %21, label %22, label %15
22: ; preds = %15, %6
%23 = tail call i32 @pow(double 3.200000e+01, i32 %12)
%24 = tail call double @log(i32 %23)
%25 = tail call double @log(i32 2)
%26 = fdiv double %24, %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), double %26)
%28 = tail call i32 @fclose(i32* %9)
br label %29
29: ; preds = %22, %4
%30 = phi i32 [ 1, %4 ], [ 0, %22 ]
ret i32 %30
}