#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*/ 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) {
    fork_result = fork();
    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    0x2e2b(%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    12ab <main+0x11b>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1228 <main+0x98>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
lea    0xdef(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    126d <main+0xdd>
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    -0x38(%rbp),%rdx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   10a0 <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    0xd85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12ab <main+0x11b>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x333231,-0x14(%rbp)
mov    0x2e2f(%rip),%r14
mov    (%r14),%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    -0x1c(%rbp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
jne    125d <main+0xcd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     120f <main+0x7f>
cmp    $0xffffffff,%eax
jne    1232 <main+0xa2>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    (%r14),%edx
mov    %rbx,%rsi
call   1080 <read@plt>
lea    0xde9(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    125d <main+0xcd>
mov    -0x18(%rbp),%ebx
lea    -0x14(%rbp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xdcc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   10a0 <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 %50
19: ; preds = %0
%20 = call i32 (...) @fork()
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %19
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %28
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%33 = load i32, i32* %32
%34 = load i32, i32* @BUFSIZ
%35 = call i32 @read(i32 %33, i8* %13, i32 %34)
store i32 %35, i32* %2
%36 = load i32, i32* %2
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %36, i8* %13)
%38 = load i32, i32* @EXIT_SUCCESS
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %28
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%42 = load i32, i32* %41
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%44 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = call i32 @write(i32 %42, i8* %43, i32 %45)
store i32 %46, i32* %2
%47 = load i32, i32* %2
%48 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %40
br label %50
50: ; preds = %49, %0
%51 = load i32, i32* @EXIT_SUCCESS
%52 = call i32 @exit(i32 %51)
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 %33
13: ; preds = %0
%14 = call i32 (...) @fork()
switch i32 %14, label %27 [
i32 -1, label %15
i32 0, label %20
]
15: ; preds = %13
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %13
%21 = load i32, i32* %10
%22 = load i32, i32* @BUFSIZ
%23 = call i32 @read(i32 %21, i8* %8, i32 %22)
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %8)
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %13
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @strlen(i8* %4)
%31 = call i32 @write(i32 %29, i8* %4, i32 %30)
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %27, %0
%34 = load i32, i32* @EXIT_SUCCESS
%35 = call i32 @exit(i32 %34)
unreachable
}