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

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, char, int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int /*<<< orphan*/);
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];
  memset(buffer, '\0', sizeof(buffer));
  if (pipe(file_pipes) == 0) {
    data_processed = write(file_pipes[1], some_data, strlen(some_data));
    printf("Wrote %d bytes\n", data_processed);
    data_processed = read(file_pipes[0], buffer, BUFSIZ);
    printf("Read %d bytes: %s\n", data_processed, buffer);
    exit(EXIT_SUCCESS);
  }
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x333231,-0x14(%rbp)
mov    0x2e53(%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,-0x30(%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    1245 <main+0xd5>
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    -0x30(%rbp),%rdx
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x333231,-0x24(%rbp)
mov    0x2e53(%rip),%r12
mov    (%r12),%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    -0x2c(%rbp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
jne    121a <main+0xaa>
mov    -0x28(%rbp),%r14d
lea    -0x24(%rbp),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe1f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    (%r12),%edx
mov    %rbx,%rsi
call   1080 <read@plt>
lea    0xe10(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [16 x i8] c"Wrote %d bytes\0A\00"
@.str.1 = [19 x i8] c"Read %d bytes: %s\0A\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = 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 %25
13: ; preds = %0
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @strlen(i8* %4)
%17 = call i32 @write(i32 %15, i8* %4, i32 %16)
%18 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %10
%20 = load i32, i32* @BUFSIZ
%21 = call i32 @read(i32 %19, i8* %8, i32 %20)
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %8)
%23 = load i32, i32* @EXIT_SUCCESS
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %0
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
}