#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 scalar_t__ uint8_t;
typedef scalar_t__ uint16_t;
typedef int /*<<< orphan*/ r;
typedef int /*<<< orphan*/ n;

/* Variables and functions */
int /*<<< orphan*/ fflush_or_die(int /*<<< orphan*/);
int /*<<< orphan*/ fread_or_die(scalar_t__ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite_or_die(scalar_t__ const *, int, int,
                                 int /*<<< orphan*/);
scalar_t__ get_random_byte();
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[], char *env[]) {
  uint8_t n;
  do {
    fread_or_die(&n, sizeof(n), 1, stdin);
    for (uint16_t i = 0; i < n; ++i) {
      uint8_t const r = get_random_byte();
      fwrite_or_die(&r, sizeof(r), 1, stdout);
    }
    fflush_or_die(stdout);
  } while (n != 0);
  return 0;
}


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)
mov    %rdx,-0x18(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%ecx
lea    -0x20(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread_or_die@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    11c4 <main+0x84>
mov    $0x0,%al
call   1050 <get_random_byte@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1040 <fwrite_or_die@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    117e <main+0x3e>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush_or_die@plt>
cmpq   $0x0,-0x20(%rbp)
jne    115a <main+0x1a>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    0x2e94(%rip),%r15
mov    %rsp,%r14
mov    0x2e7a(%rip),%r13
lea    0x8(%rsp),%r12
jmp    1180 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%edi
call   1060 <fflush_or_die@plt>
cmpq   $0x0,(%rsp)
je     11ce <main+0x8e>
mov    (%r15),%ecx
mov    %r14,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread_or_die@plt>
cmpq   $0x0,(%rsp)
jle    1170 <main+0x30>
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <get_random_byte@plt>
mov    %rax,0x8(%rsp)
mov    0x0(%r13),%ecx
mov    %r12,%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1040 <fwrite_or_die@plt>
add    $0x1,%rbx
cmp    (%rsp),%rbx
jl     11a0 <main+0x60>
jmp    1170 <main+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
br label %11
11: ; preds = %28, %3
%12 = load i32, i32* @stdin
%13 = call i32 @fread_or_die(i64* %8, i32 8, i32 1, i32 %12)
store i64 0, i64* %9
br label %14
14: ; preds = %22, %11
%15 = load i64, i64* %9
%16 = load i64, i64* %8
%17 = icmp slt i64 %15, %16
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = call i64 (...) @get_random_byte()
store i64 %19, i64* %10
%20 = load i32, i32* @stdout
%21 = call i32 @fwrite_or_die(i64* %10, i32 8, i32 1, i32 %20)
br label %22
22: ; preds = %18
%23 = load i64, i64* %9
%24 = add nsw i64 %23, 1
store i64 %24, i64* %9
br label %14
25: ; preds = %14
%26 = load i32, i32* @stdout
%27 = call i32 @fflush_or_die(i32 %26)
br label %28
28: ; preds = %25
%29 = load i64, i64* %8
%30 = icmp ne i64 %29, 0
br i1 %30, label %11, label %31
31: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i64* %4 to i8*
%7 = bitcast i64* %5 to i8*
br label %8
8: ; preds = %13, %3
%9 = load i32, i32* @stdin
%10 = call i32 @fread_or_die(i64* %4, i32 8, i32 1, i32 %9)
%11 = load i64, i64* %4
%12 = icmp sgt i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %18, %8
%14 = load i32, i32* @stdout
%15 = call i32 @fflush_or_die(i32 %14)
%16 = load i64, i64* %4
%17 = icmp eq i64 %16, 0
br i1 %17, label %26, label %8
18: ; preds = %8, %18
%19 = phi i64 [ %23, %18 ], [ 0, %8 ]
%20 = call i64 (...) @get_random_byte()
store i64 %20, i64* %5
%21 = load i32, i32* @stdout
%22 = call i32 @fwrite_or_die(i64* %5, i32 8, i32 1, i32 %21)
%23 = add nuw nsw i64 %19, 1
%24 = load i64, i64* %4
%25 = icmp slt i64 %23, %24
br i1 %25, label %18, label %13
26: ; preds = %13
ret i32 0
}