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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
size_t strlen(char const *);
size_t write(int, char const *, size_t);
int main(int argc, char **argv) {
  static const char mesg[] = "Don't Panic!";
  char buf[BUFSIZ];
  ssize_t rcount, wcount;
  int pipefd[2];
  size_t l;
  if (pipe(pipefd) < 0) {
    fprintf(stderr, "%s: pipe failed: %s\n", argv[0], strerror(errno));
    exit(1);
  }
  printf("Read end = fd %d, write end = fd %d\n", pipefd[0], pipefd[1]);
  l = strlen(mesg);
  if ((wcount = write(pipefd[1], mesg, l)) != l) {
    fprintf(stderr, "%s: write failed: %s\n", argv[0], strerror(errno));
    exit(1);
  }
  if ((rcount = read(pipefd[0], buf, BUFSIZ)) != wcount) {
    fprintf(stderr, "%s: read failed: %s\n", argv[0], strerror(errno));
    exit(1);
  }
  buf[rcount] = '\0';
  printf("Read <%s> from pipe\n", buf);
  (void)close(pipefd[0]);
  (void)close(pipefd[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
jge    122d <main+0x9d>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xdef(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x38(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdb8(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x40(%rbp),%rdx
lea    0xda1(%rip),%rsi
call   1030 <write@plt>
mov    %rax,-0x30(%rbp)
cmp    -0x40(%rbp),%rax
je     12b7 <main+0x127>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xd9f(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%rsi
mov    -0x38(%rbp),%edi
mov    0x2d13(%rip),%rax
mov    (%rax),%edx
call   1080 <read@plt>
mov    %rax,-0x28(%rbp)
cmp    -0x30(%rbp),%rax
je     131f <main+0x18f>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xd4d(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x48(%rbp),%rsi
mov    -0x28(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
lea    0xd40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e44(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x20(%rbp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
js     122a <main+0xaa>
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    0xe2c(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
cmp    $0xc,%rax
jne    124d <main+0xcd>
mov    -0x20(%rbp),%edi
mov    (%r15),%edx
mov    %rbx,%rsi
call   1070 <read@plt>
cmp    $0xc,%rax
jne    1270 <main+0xf0>
movb   $0x0,0xc(%rbx)
lea    0xe6f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2daf(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r14
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdc2(%rip),%rsi
jmp    1291 <main+0x111>
mov    0x2d8c(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r14
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdd9(%rip),%rsi
jmp    1291 <main+0x111>
mov    0x2d69(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%r14
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdcc(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@main.mesg = internal constant [13 x i8] c"Don't Panic!\00"
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"%s: pipe failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [37 x i8] c"Read end = fd %d, write end = fd %d\0A\00"
@.str.2 = [22 x i8] c"%s: write failed: %s\0A\00"
@.str.3 = [21 x i8] c"%s: read failed: %s\0A\00"
@.str.4 = [21 x i8] c"Read <%s> from pipe\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca [2 x i32]
%11 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%17 = call i64 @pipe(i32* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %32)
%34 = call i64 @strlen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @main.mesg, i64 0, i64 0))
store i64 %34, i64* %11
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%36 = load i32, i32* %35
%37 = load i64, i64* %11
%38 = call i64 @write(i32 %36, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @main.mesg, i64 0, i64 0), i64 %37)
store i64 %38, i64* %9
%39 = load i64, i64* %11
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %28
%42 = load i32, i32* @stderr
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 0
%45 = load i8*, i8** %44
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %45, i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %28
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%52 = load i32, i32* %51
%53 = load i32, i32* @BUFSIZ
%54 = call i64 @read(i32 %52, i8* %15, i32 %53)
store i64 %54, i64* %8
%55 = load i64, i64* %9
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %66
57: ; preds = %50
%58 = load i32, i32* @stderr
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %61, i8* %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %50
%67 = load i64, i64* %8
%68 = getelementptr inbounds i8, i8* %15, i64 %67
store i8 0, i8* %68
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %15)
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%71 = load i32, i32* %70
%72 = call i32 @close(i32 %71)
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%74 = load i32, i32* %73
%75 = call i32 @close(i32 %74)
store i32 0, i32* %3
%76 = load i8*, i8** %6
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@main.mesg = internal constant [13 x i8] c"Don't Panic!\00"
@BUFSIZ = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"%s: pipe failed: %s\0A\00"
@errno = global i32 0
@.str.1 = [37 x i8] c"Read end = fd %d, write end = fd %d\0A\00"
@.str.2 = [22 x i8] c"%s: write failed: %s\0A\00"
@.str.3 = [21 x i8] c"%s: read failed: %s\0A\00"
@.str.4 = [21 x i8] c"Read <%s> from pipe\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast [2 x i32]* %3 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%9 = call i64 @pipe(i32* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* %8
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %21)
%23 = load i32, i32* %20
%24 = call i64 @write(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @main.mesg, i64 0, i64 0), i64 12)
%25 = icmp eq i64 %24, 12
br i1 %25, label %33, label %26
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %28, i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %18
%34 = load i32, i32* %8
%35 = load i32, i32* @BUFSIZ
%36 = call i64 @read(i32 %34, i8* %6, i32 %35)
%37 = icmp eq i64 %36, 12
br i1 %37, label %45, label %38
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %1
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %40, i8* %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %33
%46 = getelementptr inbounds i8, i8* %6, i64 12
store i8 0, i8* %46
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%48 = load i32, i32* %8
%49 = call i32 @close(i32 %48)
%50 = load i32, i32* %20
%51 = call i32 @close(i32 %50)
ret i32 0
}