#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*/ BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ execl(char *, char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ memset(char *, char, int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, 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";
  char buffer[BUFSIZ + 1];
  pid_t fork_result;
  memset(buffer, '\0', sizeof(buffer));
  if (pipe(file_pipes) == 0) {
    fork_result = fork();
    if (fork_result == (pid_t)-1) {
      fprintf(stderr, "Fork failure");
      exit(EXIT_FAILURE);
    }
    if (fork_result == 0) {
      sprintf(buffer, "%d", file_pipes[0]);
      (void)execl("pipe4", "pipe4", buffer, (char *)0);
      exit(EXIT_FAILURE);
    } else {
      data_processed = write(file_pipes[1], some_data, strlen(some_data));
      printf("%d - wrote %d bytes\n", getpid(), 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    0x2e0b(%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   1070 <memset@plt>
lea    -0x10(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jne    12d2 <main+0x122>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0xffffffffffffffff,-0x30(%rbp)
jne    124a <main+0x9a>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
jne    128d <main+0xdd>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xdae(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x38(%rbp),%rdx
lea    0xda1(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10c0 <execl@plt>
mov    0x2d4a(%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   1050 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%edx
lea    0xd52(%rip),%rdi
call   1060 <printf@plt>
jmp    12d2 <main+0x122>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x333231,-0x14(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%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   1070 <memset@plt>
lea    -0x1c(%rbp),%rdi
call   1080 <pipe@plt>
test   %rax,%rax
jne    128c <main+0xdc>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
je     1224 <main+0x74>
cmp    $0xffffffffffffffff,%rax
jne    1258 <main+0xa8>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
call   1090 <fprintf@plt>
jmp    124a <main+0x9a>
mov    -0x1c(%rbp),%edx
lea    0xddf(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
lea    0xdd3(%rip),%rdi
mov    %rdi,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   10c0 <execl@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%ebx
lea    -0x14(%rbp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xd93(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1060 <printf@plt>
mov    0x2d35(%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 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"pipe4\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 i8*
%6 = alloca i64
%7 = alloca i64
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 %49
19: ; preds = %0
%20 = call i64 (...) @fork()
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = icmp eq i64 %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 i64, i64* %7
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%33 = load i32, i32* %32
%34 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = call i32 @execl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* null)
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %28
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = call i32 @write(i32 %40, i8* %41, i32 %43)
store i32 %44, i32* %2
%45 = call i32 (...) @getpid()
%46 = load i32, i32* %2
%47 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %45, i32 %46)
br label %48
48: ; preds = %38
br label %49
49: ; preds = %48, %0
%50 = load i32, i32* @EXIT_SUCCESS
%51 = call i32 @exit(i32 %50)
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 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c"pipe4\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 = 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 i64 (...) @fork()
switch i64 %14, label %26 [
i64 -1, label %15
i64 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 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = call i32 @execl(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* null)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %13
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @strlen(i8* %4)
%30 = call i32 @write(i32 %28, i8* %4, i32 %29)
%31 = call i32 (...) @getpid()
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %30)
br label %33
33: ; preds = %26, %0
%34 = load i32, i32* @EXIT_SUCCESS
%35 = call i32 @exit(i32 %34)
unreachable
}