#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char **, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned char);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char *argv[]) {
  int i;
  int n;
  unsigned char random[1024];
  unsigned char text[] =
      "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
  if (argc <= 1)
    n = 10;
  else {
    sscanf(argv[1], "%d", &n);
    if (n < 0 || n > 65536)
      n = 10;
  }
  FILE *rnd = fopen("/dev/urandom", "r");
  while (n > 0) {
    fread(&random, 1024, 1, rnd);
    for (i = 0; i < (n > 1024 ? 1024 : n); i++)
      if (random[i] < 4 * 62)
        printf("%c", text[random[i] % 62]);
      else
        n++;
    n -= 1024;
  }
  fclose(rnd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x460(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x3f,%edx
call   1060 <memcpy@plt>
cmpl   $0x1,-0x8(%rbp)
jg     11a7 <main+0x47>
movl   $0xa,-0x18(%rbp)
jmp    11e2 <main+0x82>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe89(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1070 <sscanf@plt>
cmpl   $0x0,-0x18(%rbp)
jl     11d6 <main+0x76>
cmpl   $0x10000,-0x18(%rbp)
jle    11dd <main+0x7d>
movl   $0xa,-0x18(%rbp)
jmp    11e2 <main+0x82>
lea    0xe59(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x468(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    12e0 <main+0x180>
lea    -0x420(%rbp),%rdi
mov    -0x468(%rbp),%rcx
mov    $0x400,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x46c(%rbp)
cmpl   $0x400,-0x18(%rbp)
jle    1250 <main+0xf0>
mov    $0x400,%eax
mov    %eax,-0x470(%rbp)
jmp    1259 <main+0xf9>
mov    -0x18(%rbp),%eax
mov    %eax,-0x470(%rbp)
mov    -0x46c(%rbp),%eax
mov    -0x470(%rbp),%ecx
cmp    %ecx,%eax
jge    12d0 <main+0x170>
movslq -0x14(%rbp),%rax
movzbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0xf8,%eax
jge    12b4 <main+0x154>
movslq -0x14(%rbp),%rax
movzbl -0x420(%rbp,%rax,1),%eax
ff
mov    $0x3e,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
lea    0xdaf(%rip),%rdi
movzbl -0x460(%rbp,%rax,1),%esi
ff
call   1050 <printf@plt>
jmp    12bd <main+0x15d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12c2 <main+0x162>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122a <main+0xca>
mov    -0x18(%rbp),%eax
sub    $0x400,%eax
mov    %eax,-0x18(%rbp)
jmp    11fc <main+0x9c>
mov    -0x468(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x410,%rsp
cmp    $0x1,%edi
jle    1184 <main+0x34>
mov    0x8(%rsi),%rdi
lea    0xecf(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1060 <sscanf@plt>
cmpl   $0x10001,0xc(%rsp)
jb     118c <main+0x3c>
movl   $0xa,0xc(%rsp)
lea    0xeaf(%rip),%rdi
lea    0xeb5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
cmpl   $0x0,0xc(%rsp)
jle    1274 <main+0x124>
lea    0x10(%rsp),%r14
lea    0xe47(%rip),%r12
lea    0xe91(%rip),%r13
jmp    11e5 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x400(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0x400,%eax
jle    1274 <main+0x124>
mov    %r14,%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    126b <main+0x11b>
xor    %ebx,%ebx
jmp    1230 <main+0xe0>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%eax
mov    %eax,0xc(%rsp)
add    $0x1,%rbx
cmp    $0x400,%eax
mov    $0x400,%ecx
cmovl  %eax,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rbx
jge    11d0 <main+0x80>
movzbl 0x10(%rsp,%rbx,1),%ecx
cmp    $0xf7,%cl
ja     1210 <main+0xc0>
mov    %ecx,%eax
shr    %al
movzbl %al,%eax
imul   $0x85,%eax,%eax
shr    $0xc,%eax
mov    %eax,%edx
shl    $0x6,%edx
sub    %eax,%edx
sub    %eax,%edx
sub    %dl,%cl
movzbl %cl,%eax
movzbl (%rax,%r12,1),%esi
mov    %r13,%rdi
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
jmp    1217 <main+0xc7>
add    $0xfffffc00,%eax
mov    %eax,0xc(%rsp)
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.text = [63 x i8] c"0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM\00"
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"/dev/urandom\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%c\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 [1024 x i8]
%9 = alloca [63 x i8]
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [63 x i8]* %9 to i8*
%12 = load i32, i32* %4
%13 = icmp sle i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 10, i32* %7
br label %27
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %15
%23 = load i32, i32* %7
%24 = icmp sgt i32 %23, 65536
br i1 %24, label %25, label %26
25: ; preds = %22, %15
store i32 10, i32* %7
br label %26
26: ; preds = %25, %22
br label %27
27: ; preds = %26, %14
%28 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %10
br label %29
29: ; preds = %71, %27
%30 = load i32, i32* %7
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %74
32: ; preds = %29
%33 = bitcast [1024 x i8]* %8 to i8**
%34 = load i32*, i32** %10
%35 = call i32 @fread(i8** %33, i32 1024, i32 1, i32* %34)
store i32 0, i32* %6
br label %36
36: ; preds = %68, %32
%37 = load i32, i32* %6
%38 = load i32, i32* %7
%39 = icmp sgt i32 %38, 1024
br i1 %39, label %40, label %41
40: ; preds = %36
br label %43
41: ; preds = %36
%42 = load i32, i32* %7
br label %43
43: ; preds = %41, %40
%44 = phi i32 [ 1024, %40 ], [ %42, %41 ]
%45 = icmp slt i32 %37, %44
br i1 %45, label %46, label %71
46: ; preds = %43
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = zext i8 %50 to i32
%52 = icmp slt i32 %51, 248
br i1 %52, label %53, label %64
53: ; preds = %46
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %55
%57 = load i8, i8* %56
%58 = zext i8 %57 to i32
%59 = srem i32 %58, 62
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [63 x i8], [63 x i8]* %9, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %62)
br label %67
64: ; preds = %46
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %7
br label %67
67: ; preds = %64, %53
br label %68
68: ; preds = %67
%69 = load i32, i32* %6
%70 = add nsw i32 %69, 1
store i32 %70, i32* %6
br label %36
71: ; preds = %43
%72 = load i32, i32* %7
%73 = sub nsw i32 %72, 1024
store i32 %73, i32* %7
br label %29
74: ; preds = %29
%75 = load i32*, i32** %10
%76 = call i32 @fclose(i32* %75)
ret i32 0
}

LLVM IR (-O2):
@__const.main.text = [63 x i8] c"0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM\00"
@.str = [3 x i8] c"%d\00"
@.str.1 = [13 x i8] c"/dev/urandom\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 10, i32* %3
br label %16
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %3
%14 = icmp ugt i32 %13, 65536
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 10, i32* %3
br label %16
16: ; preds = %15, %9, %8
%17 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %53
20: ; preds = %16
%21 = bitcast [1024 x i8]* %4 to i8**
br label %22
22: ; preds = %20, %50
%23 = call i32 @fread(i8** %21, i32 1024, i32 1, i32* %17)
%24 = load i32, i32* %3
%25 = icmp sgt i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = add nsw i32 %24, -1024
store i32 %27, i32* %3
br label %53
28: ; preds = %22, %43
%29 = phi i64 [ %45, %43 ], [ 0, %22 ]
%30 = phi i32 [ %44, %43 ], [ %24, %22 ]
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %29
%32 = load i8, i8* %31
%33 = icmp ult i8 %32, -8
br i1 %33, label %34, label %41
34: ; preds = %28
%35 = urem i8 %32, 62
%36 = zext i8 %35 to i64
%37 = getelementptr inbounds [63 x i8], [63 x i8]* @__const.main.text, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %38)
%40 = load i32, i32* %3
br label %43
41: ; preds = %28
%42 = add nsw i32 %30, 1
store i32 %42, i32* %3
br label %43
43: ; preds = %34, %41
%44 = phi i32 [ %40, %34 ], [ %42, %41 ]
%45 = add nuw nsw i64 %29, 1
%46 = icmp slt i32 %44, 1024
%47 = select i1 %46, i32 %44, i32 1024
%48 = sext i32 %47 to i64
%49 = icmp slt i64 %45, %48
br i1 %49, label %28, label %50
50: ; preds = %43
%51 = add nsw i32 %44, -1024
store i32 %51, i32* %3
%52 = icmp sgt i32 %44, 1024
br i1 %52, label %22, label %53
53: ; preds = %50, %26, %16
%54 = call i32 @fclose(i32* %17)
ret i32 0
}