#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 */
scalar_t__ EINVAL;
scalar_t__ ERANGE;
int /*<<< orphan*/ O_RDONLY;
int atol(char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *genpass(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Usage: %s <num> <len>\n", argv[0]);
    fprintf(stderr,
            "   Where <num> is the number of passwords of length <len>.\n");
    return 35;
  }
  errno = 0;
  int num = atol(argv[1]);
  if (errno == EINVAL || errno == ERANGE || num < 1) {
    fprintf(stderr, "<num> must be a valid positive integer.\n");
    return 5;
  }
  errno = 0;
  int len = atol(argv[2]);
  if (errno == EINVAL || errno == ERANGE || len < 1) {
    fprintf(stderr, "<len> must be a valid positive integer.\n");
    return 6;
  }
  int fd = open("/dev/random", O_RDONLY);
  if (fd < 0) {
    fprintf(stderr, "Sigh, couldn't open /dev/random.");
    return 1;
  }
  for (int m = 0; m < num; m++) {
    char *pss = genpass(fd, len);
    if (pss == NULL)
      return 3;
    printf("%s\n", pss);
    free(pss);
  }
  close(fd);
}


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     11d1 <main+0x61>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x23,-0x4(%rbp)
jmp    137c <main+0x20c>
mov    0x2df0(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atol@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%rax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%rax
je     122d <main+0xbd>
mov    0x2db8(%rip),%rax
mov    (%rax),%rax
mov    0x2dc6(%rip),%rcx
cmp    (%rcx),%rax
je     122d <main+0xbd>
cmpl   $0x1,-0x14(%rbp)
jge    1250 <main+0xe0>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x5,-0x4(%rbp)
jmp    137c <main+0x20c>
mov    0x2d71(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atol@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%rax
mov    0x2d41(%rip),%rcx
cmp    (%rcx),%rax
je     12ac <main+0x13c>
mov    0x2d39(%rip),%rax
mov    (%rax),%rax
mov    0x2d47(%rip),%rcx
cmp    (%rcx),%rax
je     12ac <main+0x13c>
cmpl   $0x1,-0x18(%rbp)
jge    12cf <main+0x15f>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x6,-0x4(%rbp)
jmp    137c <main+0x20c>
mov    0x2d12(%rip),%rax
mov    (%rax),%esi
lea    0xdc6(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1314 <main+0x1a4>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137c <main+0x20c>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1374 <main+0x204>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1070 <genpass@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    134d <main+0x1dd>
movl   $0x3,-0x4(%rbp)
jmp    137c <main+0x20c>
mov    -0x28(%rbp),%rsi
lea    0xd7a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    131b <main+0x1ab>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    124b <main+0xdb>
mov    0x2e3d(%rip),%rax
movq   $0x0,(%rax)
mov    0x8(%rbp),%rdi
call   1080 <atol@plt>
mov    %eax,%ebx
mov    0x2e1c(%rip),%rax
cmpq   $0x0,(%rax)
je     127d <main+0x10d>
mov    0x2e2b(%rip),%rax
cmpq   $0x0,(%rax)
je     127d <main+0x10d>
test   %ebx,%ebx
jle    127d <main+0x10d>
mov    0x10(%rbp),%rdi
call   1080 <atol@plt>
test   %eax,%eax
jle    12a2 <main+0x132>
mov    %eax,%r14d
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
lea    0xeba(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     12c0 <main+0x150>
mov    %eax,%r12d
lea    0xed0(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %r14d,%esi
call   1070 <genpass@plt>
test   %rax,%rax
je     12de <main+0x16e>
mov    %rax,%rbp
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0xffffffff,%ebx
jne    1210 <main+0xa0>
mov    %r12d,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1299 <main+0x129>
mov    0x2d7e(%rip),%rbx
mov    (%rbx),%edi
mov    0x0(%rbp),%rdx
lea    0xda1(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xda8(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x23,%eax
jmp    1299 <main+0x129>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x5,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x6,%eax
jmp    1299 <main+0x129>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    1299 <main+0x129>
mov    $0x3,%eax
jmp    1299 <main+0x129>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s <num> <len>\0A\00"
@.str.1 = [60 x i8] c" Where <num> is the number of passwords of length <len>.\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@.str.2 = [41 x i8] c"<num> must be a valid positive integer.\0A\00"
@.str.3 = [41 x i8] c"<len> must be a valid positive integer.\0A\00"
@.str.4 = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@.str.5 = [33 x i8] c"Sigh, couldn't open /dev/random.\00"
@.str.6 = [4 x i8] c"%s\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
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
store i32 35, i32* %3
br label %88
21: ; preds = %2
store i64 0, i64* @errno
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atol(i8* %24)
store i32 %25, i32* %6
%26 = load i64, i64* @errno
%27 = load i64, i64* @EINVAL
%28 = icmp eq i64 %26, %27
br i1 %28, label %36, label %29
29: ; preds = %21
%30 = load i64, i64* @errno
%31 = load i64, i64* @ERANGE
%32 = icmp eq i64 %30, %31
br i1 %32, label %36, label %33
33: ; preds = %29
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 1
br i1 %35, label %36, label %39
36: ; preds = %33, %29, %21
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
store i32 5, i32* %3
br label %88
39: ; preds = %33
store i64 0, i64* @errno
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @atol(i8* %42)
store i32 %43, i32* %7
%44 = load i64, i64* @errno
%45 = load i64, i64* @EINVAL
%46 = icmp eq i64 %44, %45
br i1 %46, label %54, label %47
47: ; preds = %39
%48 = load i64, i64* @errno
%49 = load i64, i64* @ERANGE
%50 = icmp eq i64 %48, %49
br i1 %50, label %54, label %51
51: ; preds = %47
%52 = load i32, i32* %7
%53 = icmp slt i32 %52, 1
br i1 %53, label %54, label %57
54: ; preds = %51, %47, %39
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
store i32 6, i32* %3
br label %88
57: ; preds = %51
%58 = load i32, i32* @O_RDONLY
%59 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %58)
store i32 %59, i32* %8
%60 = load i32, i32* %8
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %88
65: ; preds = %57
store i32 0, i32* %9
br label %66
66: ; preds = %82, %65
%67 = load i32, i32* %9
%68 = load i32, i32* %6
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %85
70: ; preds = %66
%71 = load i32, i32* %8
%72 = load i32, i32* %7
%73 = call i8* @genpass(i32 %71, i32 %72)
store i8* %73, i8** %10
%74 = load i8*, i8** %10
%75 = icmp eq i8* %74, null
br i1 %75, label %76, label %77
76: ; preds = %70
store i32 3, i32* %3
br label %88
77: ; preds = %70
%78 = load i8*, i8** %10
%79 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %78)
%80 = load i8*, i8** %10
%81 = call i32 @free(i8* %80)
br label %82
82: ; preds = %77
%83 = load i32, i32* %9
%84 = add nsw i32 %83, 1
store i32 %84, i32* %9
br label %66
85: ; preds = %66
%86 = load i32, i32* %8
%87 = call i32 @close(i32 %86)
br label %88
88: ; preds = %85, %76, %62, %54, %36, %13
%89 = load i32, i32* %3
ret i32 %89
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s <num> <len>\0A\00"
@.str.1 = [60 x i8] c" Where <num> is the number of passwords of length <len>.\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@ERANGE = global i64 0
@.str.2 = [41 x i8] c"<num> must be a valid positive integer.\0A\00"
@.str.3 = [41 x i8] c"<len> must be a valid positive integer.\0A\00"
@.str.4 = [12 x i8] c"/dev/random\00"
@O_RDONLY = global i32 0
@.str.5 = [33 x i8] c"Sigh, couldn't open /dev/random.\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0))
br label %50
10: ; preds = %2
store i64 0, i64* @errno
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atol(i8* %12)
%14 = load i64, i64* @EINVAL
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = load i64, i64* @ERANGE
%18 = icmp eq i64 %17, 0
%19 = icmp slt i32 %13, 1
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %21, label %24
21: ; preds = %16, %10
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %50
24: ; preds = %16
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = tail call i32 @atol(i8* %26)
%28 = icmp slt i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %50
32: ; preds = %24
%33 = load i32, i32* @O_RDONLY
%34 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
br label %50
39: ; preds = %32, %43
%40 = phi i32 [ %46, %43 ], [ 0, %32 ]
%41 = tail call i8* @genpass(i32 %34, i32 %27)
%42 = icmp eq i8* %41, null
br i1 %42, label %50, label %43
43: ; preds = %39
%44 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %41)
%45 = tail call i32 @free(i8* %41)
%46 = add nuw nsw i32 %40, 1
%47 = icmp eq i32 %46, %13
br i1 %47, label %48, label %39
48: ; preds = %43
%49 = tail call i32 @close(i32 %34)
br label %50
50: ; preds = %39, %21, %36, %48, %29, %4
%51 = phi i32 [ 35, %4 ], [ 5, %21 ], [ 6, %29 ], [ 1, %36 ], [ 0, %48 ], [ 3, %39 ]
ret i32 %51
}