#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__ pid_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ fork();
scalar_t__ getpid();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ print_buffer(unsigned char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ random_bytes(unsigned char *, int);
int /*<<< orphan*/ random_stir();
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  char c = 0;
  int pipefd[2];
  pipe(pipefd);
  setbuf(stdout, NULL);
  if (fork() == 0) {
    unsigned char buffer[32];
    pid_t grandparent_pid = getpid();
    random_bytes(buffer, sizeof(buffer));
    if (fork() == 0) {
      random_stir();
      setsid();
      while (1) {
        pid_t grandchild_pid = fork();
        if (grandchild_pid == 0) {
          random_stir();
          if (getpid() == grandparent_pid) {
            random_bytes(buffer, sizeof(buffer));
            print_buffer(buffer, sizeof(buffer));
            printf("\n");
          }
          _exit(0);
        }
        wait(NULL);
        if (grandchild_pid == grandparent_pid) {
          break;
        }
      }
      write(pipefd[1], &c, 1);
      _exit(0);
    }
    random_bytes(buffer, sizeof(buffer));
    print_buffer(buffer, sizeof(buffer));
    printf(" ");
    _exit(0);
  }
  wait(NULL);
  close(pipefd[1]);
  read(pipefd[0], &c, 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
lea    -0x10(%rbp),%rdi
call   1090 <pipe@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <setbuf@plt>
mov    $0x0,%al
call   1100 <fork@plt>
cmp    $0x0,%rax
jne    131c <main+0x13c>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   10d0 <random_bytes@plt>
mov    $0x0,%al
call   1100 <fork@plt>
cmp    $0x0,%rax
jne    12ed <main+0x10d>
mov    $0x0,%al
call   10c0 <random_stir@plt>
mov    $0x0,%al
call   10a0 <setsid@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    12b4 <main+0xd4>
mov    $0x0,%al
call   10c0 <random_stir@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
cmp    -0x38(%rbp),%rax
jne    12ad <main+0xcd>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   10d0 <random_bytes@plt>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   10e0 <print_buffer@plt>
lea    0xd58(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10f0 <wait@plt>
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    12d0 <main+0xf0>
jmp    12d5 <main+0xf5>
jmp    1257 <main+0x77>
mov    -0xc(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   10d0 <random_bytes@plt>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   10e0 <print_buffer@plt>
lea    0xcf2(%rip),%rdi
call   1070 <printf@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10f0 <wait@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    -0x10(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   10b0 <read@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movb   $0x0,0x7(%rsp)
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1070 <setbuf@plt>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
je     123f <main+0x5f>
xor    %edi,%edi
call   10f0 <wait@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x8(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   10b0 <read@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1060 <getpid@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x20,%esi
call   10d0 <random_bytes@plt>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
jne    12b5 <main+0xd5>
xor    %eax,%eax
call   10c0 <random_stir@plt>
xor    %eax,%eax
call   10a0 <setsid@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
je     12e5 <main+0x105>
mov    %rax,%rbx
xor    %edi,%edi
call   10f0 <wait@plt>
cmp    %r14,%rbx
jne    1280 <main+0xa0>
mov    0xc(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   10d0 <random_bytes@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
call   10e0 <print_buffer@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
xor    %eax,%eax
call   10c0 <random_stir@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
cmp    %r14,%rax
jne    1321 <main+0x141>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   10d0 <random_bytes@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
call   10e0 <print_buffer@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [2 x i32]
%4 = alloca [32 x i8]
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
store i8 0, i8* %2
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = load i32, i32* @stdout
%10 = call i32 @setbuf(i32 %9, i32* null)
%11 = call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %58
13: ; preds = %0
%14 = call i64 (...) @getpid()
store i64 %14, i64* %5
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%16 = call i32 @random_bytes(i8* %15, i32 32)
%17 = call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %51
19: ; preds = %13
%20 = call i32 (...) @random_stir()
%21 = call i32 (...) @setsid()
br label %22
22: ; preds = %19, %45
%23 = call i64 (...) @fork()
store i64 %23, i64* %6
%24 = load i64, i64* %6
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = call i32 (...) @random_stir()
%28 = call i64 (...) @getpid()
%29 = load i64, i64* %5
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%33 = call i32 @random_bytes(i8* %32, i32 32)
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%35 = call i32 @print_buffer(i8* %34, i32 32)
%36 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %31, %26
%38 = call i32 @_exit(i32 0)
unreachable
39: ; preds = %22
%40 = call i32 @wait(i32* null)
%41 = load i64, i64* %6
%42 = load i64, i64* %5
%43 = icmp eq i64 %41, %42
br i1 %43, label %44, label %45
44: ; preds = %39
br label %46
45: ; preds = %39
br label %22
46: ; preds = %44
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%48 = load i32, i32* %47
%49 = call i32 @write(i32 %48, i8* %2, i32 1)
%50 = call i32 @_exit(i32 0)
unreachable
51: ; preds = %13
%52 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%53 = call i32 @random_bytes(i8* %52, i32 32)
%54 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%55 = call i32 @print_buffer(i8* %54, i32 32)
%56 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%57 = call i32 @_exit(i32 0)
unreachable
58: ; preds = %0
%59 = call i32 @wait(i32* null)
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%61 = load i32, i32* %60
%62 = call i32 @close(i32 %61)
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%64 = load i32, i32* %63
%65 = call i32 @read(i32 %64, i8* %2, i32 1)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
define i32 @main() {
%1 = alloca i8
%2 = alloca [2 x i32]
%3 = alloca [32 x i8]
store i8 0, i8* %1
%4 = bitcast [2 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = load i32, i32* @stdout
%8 = call i32 @setbuf(i32 %7, i32* null)
%9 = call i64 (...) @fork()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %46
11: ; preds = %0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%13 = call i64 (...) @getpid()
%14 = call i32 @random_bytes(i8* %12, i32 32)
%15 = call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %41
17: ; preds = %11
%18 = call i32 (...) @random_stir()
%19 = call i32 (...) @setsid()
br label %20
20: ; preds = %33, %17
%21 = call i64 (...) @fork()
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = call i32 (...) @random_stir()
%25 = call i64 (...) @getpid()
%26 = icmp eq i64 %25, %13
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = call i32 @random_bytes(i8* %12, i32 32)
%29 = call i32 @print_buffer(i8* %12, i32 32)
%30 = call i32 @putchar(i32 10)
br label %31
31: ; preds = %27, %23
%32 = call i32 @_exit(i32 0)
unreachable
33: ; preds = %20
%34 = call i32 @wait(i32* null)
%35 = icmp eq i64 %21, %13
br i1 %35, label %36, label %20
36: ; preds = %33
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @write(i32 %38, i8* %1, i32 1)
%40 = call i32 @_exit(i32 0)
unreachable
41: ; preds = %11
%42 = call i32 @random_bytes(i8* %12, i32 32)
%43 = call i32 @print_buffer(i8* %12, i32 32)
%44 = call i32 @putchar(i32 32)
%45 = call i32 @_exit(i32 0)
unreachable
46: ; preds = %0
%47 = call i32 @wait(i32* null)
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%49 = load i32, i32* %48
%50 = call i32 @close(i32 %49)
%51 = load i32, i32* %5
%52 = call i32 @read(i32 %51, i8* %1, i32 1)
ret i32 0
}