#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 */
char RAND_bytes(unsigned char *, int);
int /*<<< orphan*/ detect_idiots(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(unsigned char *);
int help(char *);
scalar_t__ malloc(unsigned long);
char printable(unsigned char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  unsigned long int len;
  unsigned long int count;
  char success1 = 0;
  char success2 = 0;
  unsigned char *password;
  srand(time(NULL));
  if (argc == 1) {
    exit(help(argv[0]));
  }
  detect_idiots(argv[2]);
  len = strtoul(argv[2], NULL, 10);
  password = (unsigned char *)malloc(len + 1);
  password[len] = 0;
  if (!strcmp(argv[1], "wpa")) {
    if (len < 7 || len > 63) {
      printf("ERROR: password length (%li) outside of useful range: [%i,%i]\n",
             len, 7, 63);
      exit(1);
    }
    for (count = 0; count < len; ++count, success2 = 0) {
      while (!success2) {
        success1 = RAND_bytes(password + count, 1);
        success2 = printable(password[count]);
      }
    }
  }
  if (success1) {
    printf("Your password is:\n%s\n", password);
  }
  free(password);
  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)
movb   $0x0,-0x21(%rbp)
movb   $0x0,-0x22(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmpl   $0x1,-0x8(%rbp)
jne    120b <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <help@plt>
mov    %eax,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <detect_idiots@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   10b0 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xda2(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1326 <main+0x166>
cmpq   $0x7,-0x18(%rbp)
jb     1282 <main+0xc2>
cmpq   $0x3f,-0x18(%rbp)
jbe    12a8 <main+0xe8>
mov    -0x18(%rbp),%rsi
lea    0xd77(%rip),%rdi
mov    $0x7,%edx
mov    $0x3f,%ecx
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1321 <main+0x161>
jmp    12c3 <main+0x103>
cmpb   $0x0,-0x22(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12d9 <main+0x119>
jmp    1307 <main+0x147>
mov    -0x30(%rbp),%rdi
add    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1040 <RAND_bytes@plt>
mov    %al,-0x21(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   10d0 <printable@plt>
mov    %al,-0x22(%rbp)
jmp    12c3 <main+0x103>
jmp    130c <main+0x14c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
movb   $0x0,-0x22(%rbp)
jmp    12b0 <main+0xf0>
jmp    1326 <main+0x166>
cmpb   $0x0,-0x21(%rbp)
je     1342 <main+0x182>
mov    -0x30(%rbp),%rsi
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%ebx
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmp    $0x1,%ebx
je     129e <main+0xde>
mov    0x10(%r15),%rdi
call   1070 <detect_idiots@plt>
mov    0x10(%r15),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   10b0 <strtoul@plt>
mov    %rax,%r12
lea    0x1(%rax),%rdi
call   10a0 <malloc@plt>
mov    %rax,%r14
movb   $0x0,(%rax,%r12,1)
mov    0x8(%r15),%rdi
lea    0xde3(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    128a <main+0xca>
lea    -0x40(%r12),%rax
cmp    $0xffffffffffffffc7,%rax
jb     12ad <main+0xed>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r14,%r13,1),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x1,%esi
call   1040 <RAND_bytes@plt>
mov    %eax,%ebx
movzbl (%r15),%edi
call   10d0 <printable@plt>
test   %al,%al
je     1250 <main+0x90>
add    $0x1,%r13
cmp    %r12,%r13
jne    1240 <main+0x80>
test   %bl,%bl
je     128a <main+0xca>
lea    0xdc3(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    (%r15),%rdi
call   10c0 <help@plt>
mov    %eax,%edi
call   10e0 <exit@plt>
lea    0xd50(%rip),%rdi
mov    %r12,%rsi
mov    $0x7,%edx
mov    $0x3f,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"wpa\00"
@.str.1 = [63 x i8] c"ERROR: password length (%li) outside of useful range: [%i,%i]\0A\00"
@.str.2 = [22 x i8] c"Your password is:\0A%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %8
store i8 0, i8* %9
%11 = call i32 @time(i32* null)
%12 = call i32 @srand(i32 %11)
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @help(i8* %18)
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @detect_idiots(i8* %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i64 @strtoul(i8* %28, i32* null, i32 10)
store i64 %29, i64* %6
%30 = load i64, i64* %6
%31 = add i64 %30, 1
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %10
%34 = load i8*, i8** %10
%35 = load i64, i64* %6
%36 = getelementptr inbounds i8, i8* %34, i64 %35
store i8 0, i8* %36
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @strcmp(i8* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%41 = icmp ne i32 %40, 0
br i1 %41, label %77, label %42
42: ; preds = %21
%43 = load i64, i64* %6
%44 = icmp ult i64 %43, 7
br i1 %44, label %48, label %45
45: ; preds = %42
%46 = load i64, i64* %6
%47 = icmp ugt i64 %46, 63
br i1 %47, label %48, label %52
48: ; preds = %45, %42
%49 = load i64, i64* %6
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i64 %49, i32 7, i32 63)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %45
store i64 0, i64* %7
br label %53
53: ; preds = %73, %52
%54 = load i64, i64* %7
%55 = load i64, i64* %6
%56 = icmp ult i64 %54, %55
br i1 %56, label %57, label %76
57: ; preds = %53
br label %58
58: ; preds = %62, %57
%59 = load i8, i8* %9
%60 = icmp ne i8 %59, 0
%61 = xor i1 %60, true
br i1 %61, label %62, label %72
62: ; preds = %58
%63 = load i8*, i8** %10
%64 = load i64, i64* %7
%65 = getelementptr inbounds i8, i8* %63, i64 %64
%66 = call signext i8 @RAND_bytes(i8* %65, i32 1)
store i8 %66, i8* %8
%67 = load i8*, i8** %10
%68 = load i64, i64* %7
%69 = getelementptr inbounds i8, i8* %67, i64 %68
%70 = load i8, i8* %69
%71 = call signext i8 @printable(i8 zeroext %70)
store i8 %71, i8* %9
br label %58
72: ; preds = %58
br label %73
73: ; preds = %72
%74 = load i64, i64* %7
%75 = add i64 %74, 1
store i64 %75, i64* %7
store i8 0, i8* %9
br label %53
76: ; preds = %53
br label %77
77: ; preds = %76, %21
%78 = load i8, i8* %8
%79 = icmp ne i8 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %77
%81 = load i8*, i8** %10
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %80, %77
%84 = load i8*, i8** %10
%85 = call i32 @free(i8* %84)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"wpa\00"
@.str.1 = [63 x i8] c"ERROR: password length (%li) outside of useful range: [%i,%i]\0A\00"
@.str.2 = [22 x i8] c"Your password is:\0A%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @help(i8* %7)
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @detect_idiots(i8* %12)
%14 = load i8*, i8** %11
%15 = tail call i64 @strtoul(i8* nocapture %14, i32* null, i32 10)
%16 = add i64 %15, 1
%17 = tail call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
%19 = getelementptr inbounds i8, i8* %18, i64 %15
store i8 0, i8* %19
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %45
24: ; preds = %10
%25 = add i64 %15, -64
%26 = icmp ult i64 %25, -57
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i64 %15, i32 7, i32 63)
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %24, %38
%31 = phi i64 [ %39, %38 ], [ 0, %24 ]
%32 = getelementptr inbounds i8, i8* %18, i64 %31
br label %33
33: ; preds = %30, %33
%34 = tail call signext i8 @RAND_bytes(i8* %32, i32 1)
%35 = load i8, i8* %32
%36 = tail call signext i8 @printable(i8 zeroext %35)
%37 = icmp eq i8 %36, 0
br i1 %37, label %33, label %38
38: ; preds = %33
%39 = add nuw i64 %31, 1
%40 = icmp eq i64 %39, %15
br i1 %40, label %41, label %30
41: ; preds = %38
%42 = icmp eq i8 %34, 0
br i1 %42, label %45, label %43
43: ; preds = %41
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %45
45: ; preds = %10, %43, %41
%46 = tail call i32 @free(i8* %18)
ret i32 0
}