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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ RAND_SSLeay();
scalar_t__ RAND_bytes(int /*<<< orphan*/ *, int const);
int /*<<< orphan*/ *RAND_get_rand_method();
int /*<<< orphan*/ RAND_set_rand_method(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, int const,
                           int);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int fwrite(int /*<<< orphan*/ *, int, int const, int /*<<< orphan*/);
int /*<<< orphan*/ *malloc(int const);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(void) {
  int rc;
  uint8_t *buf;
  const int size = 4096;
  if (RAND_get_rand_method() == NULL)
    RAND_set_rand_method(RAND_SSLeay());
  buf = malloc(size * sizeof(uint8_t));
  if (buf == NULL)
    return 1;
  while (1) {
    if (RAND_bytes(buf, size) == 0)
      return 1;
    rc = fwrite(buf, sizeof(uint8_t), size, stdout);
    if (rc < size) {
      fprintf(stderr,
              "ERROR: fwrite '%s' - bytes written %d, bytes to write %d, errno "
              "%d\n",
              "stdout", rc, size, errno);
      error(EXIT_FAILURE, errno, "ERROR: fwrite");
    }
  }
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1000,-0x14(%rbp)
mov    $0x0,%al
call   1030 <RAND_get_rand_method@plt>
cmp    $0x0,%rax
jne    11b5 <main+0x35>
mov    $0x0,%al
call   1040 <RAND_SSLeay@plt>
mov    %eax,%edi
call   1080 <RAND_set_rand_method@plt>
mov    $0x4000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11da <main+0x5a>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x101>
jmp    11df <main+0x5f>
mov    -0x10(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <RAND_bytes@plt>
cmp    $0x0,%rax
jne    1203 <main+0x83>
movl   $0x1,-0x4(%rbp)
jmp    1281 <main+0x101>
mov    -0x10(%rbp),%rdi
mov    0x2dba(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%esi
mov    $0x1000,%edx
call   10a0 <fwrite@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1000,-0x8(%rbp)
jge    127c <main+0xfc>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%ecx
mov    0x2d96(%rip),%rax
mov    (%rax),%r9d
lea    0xdb4(%rip),%rsi
lea    0xdf1(%rip),%rdx
mov    $0x1000,%r8d
call   1060 <fprintf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
lea    0xdd4(%rip),%rdx
call   1090 <error@plt>
jmp    11df <main+0x5f>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <RAND_get_rand_method@plt>
test   %rax,%rax
jne    11a5 <main+0x25>
xor    %eax,%eax
call   1040 <RAND_SSLeay@plt>
mov    %eax,%edi
call   1080 <RAND_set_rand_method@plt>
mov    $0x4000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1263 <main+0xe3>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1000,%esi
call   1050 <RAND_bytes@plt>
test   %rax,%rax
je     1263 <main+0xe3>
mov    0x2df0(%rip),%r13
mov    0x2df9(%rip),%rbp
lea    0xe5e(%rip),%r15
mov    0x2de3(%rip),%r14
lea    0xe57(%rip),%r12
jmp    1212 <main+0x92>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <RAND_bytes@plt>
test   %rax,%rax
je     1263 <main+0xe3>
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    $0x1000,%edx
call   10a0 <fwrite@plt>
cmp    $0xfff,%eax
jg     1200 <main+0x80>
mov    0x2daa(%rip),%rcx
mov    (%rcx),%edi
mov    0x0(%rbp),%r9d
lea    0xdbd(%rip),%rsi
mov    %r15,%rdx
mov    %eax,%ecx
mov    $0x1000,%r8d
call   1060 <fprintf@plt>
mov    (%r14),%edi
mov    0x0(%rbp),%esi
mov    %r12,%rdx
call   1090 <error@plt>
jmp    1200 <main+0x80>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@stderr = global i32 0
@.str = [68 x i8] c"ERROR: fwrite '%s' - bytes written %d, bytes to write %d, errno %d\0A\00"
@.str.1 = [7 x i8] c"stdout\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [14 x i8] c"ERROR: fwrite\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
store i32 4096, i32* %4
%5 = call i32* (...) @RAND_get_rand_method()
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (...) @RAND_SSLeay()
%9 = call i32 @RAND_set_rand_method(i32 %8)
br label %10
10: ; preds = %7, %0
%11 = call i32* @malloc(i32 16384)
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %10
store i32 1, i32* %1
br label %36
15: ; preds = %10
br label %16
16: ; preds = %15, %35
%17 = load i32*, i32** %3
%18 = call i64 @RAND_bytes(i32* %17, i32 4096)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 1, i32* %1
br label %36
21: ; preds = %16
%22 = load i32*, i32** %3
%23 = load i32, i32* @stdout
%24 = call i32 @fwrite(i32* %22, i32 4, i32 4096, i32 %23)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 4096
br i1 %26, label %27, label %35
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i32, i32* %2
%30 = load i32, i32* @errno
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 4096, i32 %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = load i32, i32* @errno
%34 = call i32 @error(i32 %32, i32 %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %27, %21
br label %16
36: ; preds = %20, %14
%37 = load i32, i32* %1
ret i32 %37
}

LLVM IR (-O2):
@stdout = global i32 0
@stderr = global i32 0
@.str = [68 x i8] c"ERROR: fwrite '%s' - bytes written %d, bytes to write %d, errno %d\0A\00"
@.str.1 = [7 x i8] c"stdout\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [14 x i8] c"ERROR: fwrite\00"
define i32 @main() {
%1 = tail call i32* (...) @RAND_get_rand_method()
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 (...) @RAND_SSLeay()
%5 = tail call i32 @RAND_set_rand_method(i32 %4)
br label %6
6: ; preds = %3, %0
%7 = tail call i32* @malloc(i32 16384)
%8 = icmp eq i32* %7, null
br i1 %8, label %26, label %9
9: ; preds = %6
%10 = tail call i64 @RAND_bytes(i32* %7, i32 4096)
%11 = icmp eq i64 %10, 0
br i1 %11, label %26, label %12
12: ; preds = %9, %23
%13 = load i32, i32* @stdout
%14 = tail call i32 @fwrite(i32* %7, i32 4, i32 4096, i32 %13)
%15 = icmp slt i32 %14, 4096
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 4096, i32 %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = load i32, i32* @errno
%22 = tail call i32 @error(i32 %20, i32 %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %16, %12
%24 = tail call i64 @RAND_bytes(i32* %7, i32 4096)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %12
26: ; preds = %23, %9, %6
ret i32 1
}