#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 */
int ENOMEM;
int /*<<< orphan*/ assert(int);
scalar_t__ calloc(size_t, int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int random_char(char **buf, size_t len) {
  static int rand_init = 0;
  char *b;
  int rnd;
  size_t s;
  if (!rand_init) {
    srand(time(NULL));
    rand_init = 1;
  }
  b = ((char *)calloc((len), sizeof(char)));
  if (!b)
    return -ENOMEM;
  for (s = 0; s < len; s++) {
    rnd = rand() % 98;
    assert(rnd < 98);
    switch (rnd) {
    case 95:
      b[s] = '\t';
      break;
    case 96:
      b[s] = '\n';
      break;
    case 97:
      b[s] = '\r';
      break;
    default:
      b[s] = ' ' + rnd;
      break;
    }
  }
  *buf = b;
  return 0;
}


x86 assembly (clang, -O0):
<random_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x0,0x2ee5(%rip)
jne    1187 <random_char+0x37>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x1,0x2ec5(%rip)
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b7 <random_char+0x67>
xor    %eax,%eax
mov    0x2e33(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12a8 <random_char+0x158>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1296 <random_char+0x146>
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rcx
imul   $0x5397829d,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x62,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sub    $0x62,%eax
setl   %al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x5f,%eax
je     123a <random_char+0xea>
jmp    1218 <random_char+0xc8>
mov    -0x34(%rbp),%eax
sub    $0x60,%eax
je     124b <random_char+0xfb>
jmp    1229 <random_char+0xd9>
mov    -0x34(%rbp),%eax
sub    $0x61,%eax
je     125c <random_char+0x10c>
jmp    126d <random_char+0x11d>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x9,(%rax,%rcx,1)
jmp    1280 <random_char+0x130>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
jmp    1280 <random_char+0x130>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0xd,(%rax,%rcx,1)
jmp    1280 <random_char+0x130>
mov    -0x24(%rbp),%eax
add    $0x20,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1285 <random_char+0x135>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11bf <random_char+0x6f>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_char>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbx
cmpb   $0x0,0x2ee4(%rip)
jne    117f <random_char+0x2f>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movb   $0x1,0x2ecd(%rip)
mov    %r15,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     120e <random_char+0xbe>
mov    %rax,%r12
mov    %rbx,(%rsp)
test   %r15,%r15
je     1203 <random_char+0xb3>
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%r14
imul   $0x5397829d,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x62,%eax,%ebp
mov    %r14d,%r13d
sub    %ebp,%r13d
mov    $0x1,%edi
call   1050 <assert@plt>
neg    %ebp
lea    (%r14,%rbp,1),%eax
add    $0xffffffa1,%eax
lea    0x20(%r13),%edx
lea    -0x2f8(,%r13,8),%ecx
ff
mov    $0xd0a09,%esi
shr    %cl,%esi
cmp    $0x3,%eax
movzbl %dl,%eax
cmovb  %esi,%eax
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11a0 <random_char+0x50>
mov    (%rsp),%rax
mov    %r12,(%rax)
xor    %eax,%eax
jmp    1219 <random_char+0xc9>
mov    0x2dcb(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@random_char.rand_init = internal global i32 0
@ENOMEM = global i32 0
define i32 @random_char(i8** %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
store i8** %0, i8*** %4
store i64 %1, i64* %5
%9 = load i32, i32* @random_char.rand_init
%10 = icmp ne i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = call i32 @time(i32* null)
%13 = call i32 @srand(i32 %12)
store i32 1, i32* @random_char.rand_init
br label %14
14: ; preds = %11, %2
%15 = load i64, i64* %5
%16 = call i64 @calloc(i64 %15, i32 1)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %23, label %20
20: ; preds = %14
%21 = load i32, i32* @ENOMEM
%22 = sub nsw i32 0, %21
store i32 %22, i32* %3
br label %62
23: ; preds = %14
store i64 0, i64* %8
br label %24
24: ; preds = %56, %23
%25 = load i64, i64* %8
%26 = load i64, i64* %5
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %59
28: ; preds = %24
%29 = call i32 (...) @rand()
%30 = srem i32 %29, 98
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 98
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* %7
switch i32 %35, label %48 [
i32 95, label %36
i32 96, label %40
i32 97, label %44
]
36: ; preds = %28
%37 = load i8*, i8** %6
%38 = load i64, i64* %8
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8 9, i8* %39
br label %55
40: ; preds = %28
%41 = load i8*, i8** %6
%42 = load i64, i64* %8
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 10, i8* %43
br label %55
44: ; preds = %28
%45 = load i8*, i8** %6
%46 = load i64, i64* %8
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8 13, i8* %47
br label %55
48: ; preds = %28
%49 = load i32, i32* %7
%50 = add nsw i32 32, %49
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %6
%53 = load i64, i64* %8
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8 %51, i8* %54
br label %55
55: ; preds = %48, %44, %40, %36
br label %56
56: ; preds = %55
%57 = load i64, i64* %8
%58 = add i64 %57, 1
store i64 %58, i64* %8
br label %24
59: ; preds = %24
%60 = load i8*, i8** %6
%61 = load i8**, i8*** %4
store i8* %60, i8** %61
store i32 0, i32* %3
br label %62
62: ; preds = %59, %20
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@random_char.rand_init = internal unnamed_addr global i1 false
@ENOMEM = global i32 0
define i32 @random_char(i8** nocapture writeonly %0, i64 %1) {
%3 = load i1, i1* @random_char.rand_init
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @time(i32* null)
%6 = tail call i32 @srand(i32 %5)
store i1 true, i1* @random_char.rand_init
br label %7
7: ; preds = %4, %2
%8 = tail call i64 @calloc(i64 %1, i32 1)
%9 = inttoptr i64 %8 to i8*
%10 = icmp eq i64 %8, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = icmp eq i64 %1, 0
br i1 %12, label %33, label %16
13: ; preds = %7
%14 = load i32, i32* @ENOMEM
%15 = sub nsw i32 0, %14
br label %34
16: ; preds = %11, %16
%17 = phi i64 [ %31, %16 ], [ 0, %11 ]
%18 = tail call i32 (...) @rand()
%19 = srem i32 %18, 98
%20 = tail call i32 @assert(i32 1)
%21 = add nsw i32 %19, -95
%22 = icmp ult i32 %21, 3
%23 = trunc i32 %19 to i8
%24 = add nsw i8 %23, 32
%25 = trunc i32 %21 to i24
%26 = shl i24 %25, 3
%27 = lshr i24 854537, %26
%28 = trunc i24 %27 to i8
%29 = select i1 %22, i8 %28, i8 %24
%30 = getelementptr inbounds i8, i8* %9, i64 %17
store i8 %29, i8* %30
%31 = add nuw i64 %17, 1
%32 = icmp eq i64 %31, %1
br i1 %32, label %33, label %16
33: ; preds = %16, %11
store i8* %9, i8** %0
br label %34
34: ; preds = %33, %13
%35 = phi i32 [ 0, %33 ], [ %15, %13 ]
ret i32 %35
}