#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 ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int errno;
scalar_t__ getpid();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
main() {
  int fd[2];
  ssize_t sz;
  char buf[80];
  printf("This is pid %d\n", (int)getpid());
  pipe(fd);
  sz = read(fd[0], buf, sizeof(buf));
  printf("sz = %d\n", (int)sz);
  if (sz == -1)
    printf("errno = %d\n", errno);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x50,%edx
call   1060 <read@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0xffffffff,-0x10(%rbp)
jne    11af <main+0x6f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xead(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x50,%edx
call   1060 <read@plt>
mov    %eax,%ebx
lea    0xe90(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
cmp    $0xffffffff,%ebx
jne    11a1 <main+0x61>
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"This is pid %d\0A\00"
@.str.1 = [9 x i8] c"sz = %d\0A\00"
@.str.2 = [12 x i8] c"errno = %d\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca [80 x i8]
store i32 0, i32* %1
%5 = call i64 (...) @getpid()
%6 = trunc i64 %5 to i32
%7 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 80)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = load i32, i32* @errno
%20 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"This is pid %d\0A\00"
@.str.1 = [9 x i8] c"sz = %d\0A\00"
@.str.2 = [12 x i8] c"errno = %d\0A\00"
@errno = global i32 0
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [80 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%5 = tail call i64 (...) @getpid()
%6 = trunc i64 %5 to i32
%7 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = load i32, i32* %8
%11 = call i32 @read(i32 %10, i8* %4, i32 80)
%12 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %11, -1
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i32, i32* @errno
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %0
ret i32 0
}