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

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ memset(char *, char, int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
int write(int, char const *, int /*<<< orphan*/);
int main() {
  int data_processed;
  int file_pipes[2];
  const char some_data[] = "123";
  char buffer[BUFSIZ + 1];
  pid_t fork_result;
  memset(buffer, '\0', sizeof(buffer));
  if (pipe(file_pipes) == 0) {
    getchar();
    fork_result = fork();
    getchar();
    if (fork_result == -1) {
      fprintf(stderr, "Fork failure");
      exit(EXIT_FAILURE);
    }
    if (fork_result == 0) {
      data_processed = read(file_pipes[0], buffer, BUFSIZ);
      printf("Read %d bytes: %s\n", data_processed, buffer);
      exit(EXIT_SUCCESS);
    } else {
      data_processed = write(file_pipes[1], some_data, strlen(some_data));
      printf("Wrote %d bytes\n", data_processed);
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x333231,-0x14(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    -0x10(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
jne    12c9 <main+0x129>
mov    $0x0,%al
call   1090 <getchar@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1090 <getchar@plt>
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1246 <main+0xa6>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    128b <main+0xeb>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%edi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    -0x38(%rbp),%rdx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xd67(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c9 <main+0x129>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x333231,-0x1c(%rbp)
mov    0x2e1d(%rip),%r15
mov    (%r15),%edx
add    $0x1,%edx
mov    %rsp,%rbx
lea    0xf(%rdx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    -0x24(%rbp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
jne    1282 <main+0xe2>
xor    %eax,%eax
call   1090 <getchar@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1090 <getchar@plt>
test   %r14d,%r14d
je     1234 <main+0x94>
cmp    $0xffffffff,%r14d
jne    1257 <main+0xb7>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    (%r15),%edx
mov    %rbx,%rsi
call   1080 <read@plt>
lea    0xdc4(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1282 <main+0xe2>
mov    -0x20(%rbp),%ebx
lea    -0x1c(%rbp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xda7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@__const.main.some_data = [4 x i8] c"123\00"
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"Fork failure\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [19 x i8] c"Read %d bytes: %s\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [16 x i8] c"Wrote %d bytes\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca [4 x i8]
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [4 x i8]* %4 to i8*
%9 = load i32, i32* @BUFSIZ
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
%14 = trunc i64 %11 to i32
%15 = call i32 @memset(i8* %13, i8 signext 0, i32 %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%17 = call i64 @pipe(i32* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %52
19: ; preds = %0
%20 = call i32 (...) @getchar()
%21 = call i32 (...) @fork()
store i32 %21, i32* %7
%22 = call i32 (...) @getchar()
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %19
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%35 = load i32, i32* %34
%36 = load i32, i32* @BUFSIZ
%37 = call i32 @read(i32 %35, i8* %13, i32 %36)
store i32 %37, i32* %2
%38 = load i32, i32* %2
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* %13)
%40 = load i32, i32* @EXIT_SUCCESS
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %30
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%46 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @write(i32 %44, i8* %45, i32 %47)
store i32 %48, i32* %2
%49 = load i32, i32* %2
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %42
br label %52
52: ; preds = %51, %0
%53 = load i32, i32* @EXIT_SUCCESS
%54 = call i32 @exit(i32 %53)
unreachable
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [13 x i8] c"Fork failure\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [19 x i8] c"Read %d bytes: %s\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [16 x i8] c"Wrote %d bytes\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = bitcast [2 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 3355185, i32* %2
%5 = load i32, i32* @BUFSIZ
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = call i32 @memset(i8* %8, i8 signext 0, i32 %6)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%11 = call i64 @pipe(i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %0
%14 = call i32 (...) @getchar()
%15 = call i32 (...) @fork()
%16 = call i32 (...) @getchar()
switch i32 %15, label %29 [
i32 -1, label %17
i32 0, label %22
]
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = load i32, i32* %10
%24 = load i32, i32* @BUFSIZ
%25 = call i32 @read(i32 %23, i8* %8, i32 %24)
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %25, i8* %8)
%27 = load i32, i32* @EXIT_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %13
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @strlen(i8* %4)
%33 = call i32 @write(i32 %31, i8* %4, i32 %32)
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %29, %0
%36 = load i32, i32* @EXIT_SUCCESS
%37 = call i32 @exit(i32 %36)
unreachable
}