#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t getrandom(char *, int, unsigned int);
scalar_t__ is_english_alphanumeric(char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void getrandom_alphanumeric(char *buf, size_t len) {
  if (!buf || !len) {
    do {
      fflush(stdout);
      fprintf(stderr, "buf: %p len: %zu?", (void *)buf, len);
      fprintf(stderr, "\n");
    } while (0);
    exit(EXIT_FAILURE);
  }
  size_t max = (len - 1);
  size_t pos = 0;
  do {
    char rnd_buf[(16 * 4)];
    unsigned int flags = 0;
    ssize_t got = getrandom(rnd_buf, (16 * 4), flags);
    for (ssize_t i = 0; i < got && pos < max; ++i) {
      char c = rnd_buf[i];
      if (is_english_alphanumeric(c)) {
        buf[pos++] = c;
      }
    }
  } while (pos < max);
  buf[pos++] = '\0';
}


x86 assembly (clang, -O0):
<getrandom_alphanumeric>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1179 <getrandom_alphanumeric+0x29>
cmpq   $0x0,-0x10(%rbp)
jne    11d0 <getrandom_alphanumeric+0x80>
jmp    117e <getrandom_alphanumeric+0x2e>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x64(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%edx
mov    $0x40,%esi
call   1070 <getrandom@plt>
mov    %rax,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%rcx
xor    %eax,%eax
cmp    -0x70(%rbp),%rcx
mov    %al,-0x7a(%rbp)
jae    1229 <getrandom_alphanumeric+0xd9>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
setb   %al
mov    %al,-0x7a(%rbp)
mov    -0x7a(%rbp),%al
test   $0x1,%al
jne    1239 <getrandom_alphanumeric+0xe9>
jmp    1286 <getrandom_alphanumeric+0x136>
mov    -0x78(%rbp),%rax
mov    -0x60(%rbp,%rax,1),%al
mov    %al,-0x79(%rbp)
movsbl -0x79(%rbp),%edi
call   1040 <is_english_alphanumeric@plt>
cmp    $0x0,%rax
je     1270 <getrandom_alphanumeric+0x120>
mov    -0x79(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x20(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    1275 <getrandom_alphanumeric+0x125>
mov    -0x78(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x78(%rbp)
jmp    1208 <getrandom_alphanumeric+0xb8>
jmp    128b <getrandom_alphanumeric+0x13b>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     11e4 <getrandom_alphanumeric+0x94>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
movb   $0x0,(%rax,%rcx,1)
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrandom_alphanumeric>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r13
mov    %rdi,%r14
test   %rdi,%rdi
je     11f6 <getrandom_alphanumeric+0xa6>
test   %r13,%r13
je     11f6 <getrandom_alphanumeric+0xa6>
add    $0xffffffffffffffff,%r13
xor    %ebx,%ebx
jmp    1184 <getrandom_alphanumeric+0x34>
xchg   %ax,%ax
test   %al,%al
je     11e2 <getrandom_alphanumeric+0x92>
mov    %rsp,%rdi
mov    $0x40,%esi
xor    %edx,%edx
call   1070 <getrandom@plt>
mov    %rax,%r12
cmp    %r13,%rbx
setb   %al
test   %r12,%r12
je     1180 <getrandom_alphanumeric+0x30>
cmp    %r13,%rbx
jae    1180 <getrandom_alphanumeric+0x30>
mov    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rsp,%rbp,1),%r15d
movsbl %r15b,%edi
call   1040 <is_english_alphanumeric@plt>
test   %rax,%rax
je     11cc <getrandom_alphanumeric+0x7c>
mov    %r15b,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %r13,%rbx
setb   %al
cmp    %r12,%rbp
jae    1180 <getrandom_alphanumeric+0x30>
add    $0x1,%rbp
cmp    %r13,%rbx
jb     11b0 <getrandom_alphanumeric+0x60>
jmp    1180 <getrandom_alphanumeric+0x30>
movb   $0x0,(%r14,%rbx,1)
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2dd5(%rip),%rbx
mov    (%rbx),%edi
lea    0xdec(%rip),%rsi
mov    %r14,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xde8(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"buf: %p len: %zu?\00"
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define void @getrandom_alphanumeric(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca [64 x i8]
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8
store i8* %0, i8** %3
store i64 %1, i64* %4
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i64, i64* %4
%16 = icmp ne i64 %15, 0
br i1 %16, label %30, label %17
17: ; preds = %14, %2
br label %18
18: ; preds = %17
%19 = load i32, i32* @stdout
%20 = call i32 @fflush(i32 %19)
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %3
%23 = load i64, i64* %4
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %22, i64 %23)
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %18
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %14
%31 = load i64, i64* %4
%32 = sub i64 %31, 1
store i64 %32, i64* %5
store i64 0, i64* %6
br label %33
33: ; preds = %65, %30
store i32 0, i32* %8
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%35 = load i32, i32* %8
%36 = call i64 @getrandom(i8* %34, i32 64, i32 %35)
store i64 %36, i64* %9
store i64 0, i64* %10
br label %37
37: ; preds = %61, %33
%38 = load i64, i64* %10
%39 = load i64, i64* %9
%40 = icmp ult i64 %38, %39
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i64, i64* %6
%43 = load i64, i64* %5
%44 = icmp ult i64 %42, %43
br label %45
45: ; preds = %41, %37
%46 = phi i1 [ false, %37 ], [ %44, %41 ]
br i1 %46, label %47, label %64
47: ; preds = %45
%48 = load i64, i64* %10
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 %48
%50 = load i8, i8* %49
store i8 %50, i8* %11
%51 = load i8, i8* %11
%52 = call i64 @is_english_alphanumeric(i8 signext %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %60
54: ; preds = %47
%55 = load i8, i8* %11
%56 = load i8*, i8** %3
%57 = load i64, i64* %6
%58 = add i64 %57, 1
store i64 %58, i64* %6
%59 = getelementptr inbounds i8, i8* %56, i64 %57
store i8 %55, i8* %59
br label %60
60: ; preds = %54, %47
br label %61
61: ; preds = %60
%62 = load i64, i64* %10
%63 = add i64 %62, 1
store i64 %63, i64* %10
br label %37
64: ; preds = %45
br label %65
65: ; preds = %64
%66 = load i64, i64* %6
%67 = load i64, i64* %5
%68 = icmp ult i64 %66, %67
br i1 %68, label %33, label %69
69: ; preds = %65
%70 = load i8*, i8** %3
%71 = load i64, i64* %6
%72 = add i64 %71, 1
store i64 %72, i64* %6
%73 = getelementptr inbounds i8, i8* %70, i64 %71
store i8 0, i8* %73
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"buf: %p len: %zu?\00"
@.str.1 = [2 x i8] c"\0A\00"
@EXIT_FAILURE = global i32 0
define void @getrandom_alphanumeric(i8* %0, i64 %1) {
%3 = alloca [64 x i8]
%4 = icmp ne i8* %0, null
%5 = icmp ne i64 %1, 0
%6 = and i1 %4, %5
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = load i32, i32* @stdout
%9 = tail call i32 @fflush(i32 %8)
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1)
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = add i64 %1, -1
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
br label %19
19: ; preds = %25, %16
%20 = phi i64 [ 0, %16 ], [ %26, %25 ]
%21 = call i64 @getrandom(i8* %18, i32 64, i32 0)
%22 = icmp ne i64 %21, 0
%23 = icmp ult i64 %20, %17
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %28, label %25
25: ; preds = %38, %19
%26 = phi i64 [ %20, %19 ], [ %39, %38 ]
%27 = phi i1 [ %23, %19 ], [ %42, %38 ]
br i1 %27, label %19, label %44
28: ; preds = %19, %38
%29 = phi i64 [ %39, %38 ], [ %20, %19 ]
%30 = phi i64 [ %40, %38 ], [ 0, %19 ]
%31 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = call i64 @is_english_alphanumeric(i8 signext %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %28
%36 = add nuw i64 %29, 1
%37 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 %32, i8* %37
br label %38
38: ; preds = %35, %28
%39 = phi i64 [ %36, %35 ], [ %29, %28 ]
%40 = add nuw i64 %30, 1
%41 = icmp ult i64 %40, %21
%42 = icmp ult i64 %39, %17
%43 = select i1 %41, i1 %42, i1 false
br i1 %43, label %28, label %25
44: ; preds = %25
%45 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 0, i8* %45
ret void
}