#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;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execlp(char *, char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getpid();
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, int, int);
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";
  pid_t fork_result;
  if (pipe(file_pipes) == 0) {
    fork_result = fork();
    if (fork_result == (pid_t)-1) {
      fprintf(stderr, "Fork failure");
      exit(EXIT_FAILURE);
    }
    if (fork_result == (pid_t)0) {
      close(0);
      dup(file_pipes[0]);
      close(file_pipes[0]);
      close(file_pipes[1]);
      execlp("od", "od", "-c", (char *)0);
      exit(EXIT_FAILURE);
    } else {
      close(file_pipes[0]);
      data_processed = write(file_pipes[1], some_data, strlen(some_data));
      close(file_pipes[1]);
      printf("%d - wrote %d bytes\n", (int)getpid(), data_processed);
    }
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe3b(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    -0x10(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
jne    12bb <main+0x10b>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    1214 <main+0x64>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1266 <main+0xb6>
xor    %edi,%edi
call   1080 <close@plt>
mov    -0x10(%rbp),%edi
call   1070 <dup@plt>
mov    -0x10(%rbp),%edi
call   1080 <close@plt>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
lea    0xdcc(%rip),%rsi
lea    0xdc8(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10c0 <execlp@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%edi
call   1080 <close@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
lea    0xd66(%rip),%rdi
call   1060 <printf@plt>
jmp    12bb <main+0x10b>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x333231,0x14(%rsp)
lea    0xc(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
jne    128b <main+0xdb>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
je     11fb <main+0x4b>
cmp    $0xffffffffffffffff,%rax
jne    1243 <main+0x93>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1235 <main+0x85>
xor    %edi,%edi
call   1080 <close@plt>
mov    0xc(%rsp),%edi
call   1070 <dup@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x10(%rsp),%edi
call   1080 <close@plt>
lea    0xde9(%rip),%rdi
lea    0xde5(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   10c0 <execlp@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x10(%rsp),%ebx
lea    0x14(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%edi
call   1080 <close@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd91(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1060 <printf@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"Fork failure\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"od\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [21 x i8] c"%d - wrote %d bytes\0A\00"
@EXIT_SUCCESS = global i32 0
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 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %39
8: ; preds = %0
%9 = call i64 (...) @fork()
switch i64 %9, label %27 [
i64 -1, label %10
i64 0, label %15
]
10: ; preds = %8
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %8
%16 = call i32 @close(i32 0)
%17 = load i32, i32* %5
%18 = call i32 @dup(i32 %17)
%19 = load i32, i32* %5
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = call i32 @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* null)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %8
%28 = load i32, i32* %5
%29 = call i32 @close(i32 %28)
%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 = load i32, i32* %30
%35 = call i32 @close(i32 %34)
%36 = call i64 (...) @getpid()
%37 = trunc i64 %36 to i32
%38 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %33)
br label %39
39: ; preds = %27, %0
%40 = load i32, i32* @EXIT_SUCCESS
%41 = call i32 @exit(i32 %40)
unreachable
}