#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  int pipefd[2];
  char c;
  char foo[] = "Hoi";
  int rv;
  printf("start\n");
  rv = pipe(pipefd);
  printf("pipe: %d [%d %d]\n", rv, pipefd[0], pipefd[1]);
  write(pipefd[1], foo, strlen(foo));
  close(pipefd[1]);
  while (read(pipefd[0], &c, 1) > 0)
    printf("READ %d %c\n", c, c);
  printf("Done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8b(%rip),%eax
mov    %eax,-0x11(%rbp)
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x11(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x11(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jle    120c <main+0xac>
movsbl -0xd(%rbp),%esi
movsbl -0xd(%rbp),%edx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11d6 <main+0x76>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x696f48,0x14(%rsp)
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   1080 <pipe@plt>
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%ecx
lea    0xe5c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@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   1040 <write@plt>
mov    0x10(%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
lea    0xb(%rsp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %rax,%rax
jle    1227 <main+0xb7>
lea    0xe20(%rip),%r14
lea    0xb(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
movsbl 0xb(%rsp),%edx
mov    %r14,%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %rax,%rax
jg     1200 <main+0x90>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.foo = [4 x i8] c"Hoi\00"
@.str = [7 x i8] c"start\0A\00"
@.str.1 = [18 x i8] c"pipe: %d [%d %d]\0A\00"
@.str.2 = [12 x i8] c"READ %d %c\0A\00"
@.str.3 = [6 x i8] c"Done\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i8
%4 = alloca [4 x i8]
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [4 x i8]* %4 to i8*
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %12, i32 %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @write(i32 %17, i8* %18, i32 %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
br label %25
25: ; preds = %30, %0
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%27 = load i32, i32* %26
%28 = call i64 @read(i32 %27, i8* %3, i32 1)
%29 = icmp sgt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = load i8, i8* %3
%32 = sext i8 %31 to i32
%33 = load i8, i8* %3
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %34)
br label %25
36: ; preds = %25
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"pipe: %d [%d %d]\0A\00"
@.str.2 = [12 x i8] c"READ %d %c\0A\00"
@str = [6 x i8] c"start\00"
@str.4 = [5 x i8] c"Done\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i8
%3 = alloca i32
%4 = bitcast [2 x i32]* %1 to i8*
%5 = bitcast i32* %3 to i8*
store i32 6909768, i32* %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = load i32, i32* %7
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %9, i32 %11)
%13 = load i32, i32* %10
%14 = call i32 @strlen(i8* %5)
%15 = call i32 @write(i32 %13, i8* %5, i32 %14)
%16 = load i32, i32* %10
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* %7
%19 = call i64 @read(i32 %18, i8* %2, i32 1)
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %0, %21
%22 = load i8, i8* %2
%23 = sext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %23)
%25 = load i32, i32* %7
%26 = call i64 @read(i32 %25, i8* %2, i32 1)
%27 = icmp sgt i64 %26, 0
br i1 %27, label %21, label %28
28: ; preds = %21, %0
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}