int main() {
  int fd[2];
  int r;
  char buf[20];
  printf("%d\n", getpid());
  r = pipe(fd);
  write(fd[1], "hello", 5);
  write(fd[1], "world", 5);
  r = read(fd[0], buf, 20);
  buf[r] = 0;
  printf("%s\n", buf);
  write(fd[1], "mizu", 4);
  r = read(fd[0], buf, 20);
  buf[r] = 0;
  printf("%s\n", buf);
  while (1) {
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xc(%rbp),%rdi
mov    $0x0,%al
call   1060 <pipe@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe76(%rip),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe66(%rip),%rsi
mov    $0x5,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1070 <read@plt>
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe29(%rip),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
mov    $0x0,%al
call   1070 <read@plt>
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1228 <main+0xd8>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe8d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rdi
xor    %eax,%eax
call   1070 <pipe@plt>
mov    0xc(%rsp),%edi
lea    0xe71(%rip),%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    0xc(%rsp),%edi
lea    0xe60(%rip),%rsi
mov    $0x5,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x14,%edx
xor    %eax,%eax
call   1080 <read@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
lea    0xe28(%rip),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x14,%edx
xor    %eax,%eax
call   1080 <read@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbx,%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
jmp    1220 <main+0xc0>

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

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