#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);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
size_t write(int, char *, int);
int main() {
  int fd[2];
  size_t size;
  char string[] = "Hello, world!";
  char st[50];
  int sz = 14;
  printf("Ok\n");
  if (pipe(fd) == 0) {
    printf("Piped\n");
    size = write(fd[1], string, sz);
    size = read(fd[0], st, sz);
    printf("|%s|\n", st);
  }
  close(fd[0]);
  close(fd[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x26(%rbp)
mov    0xe98(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xe92(%rip),%ax
mov    %ax,-0x1a(%rbp)
movl   $0xe,-0x64(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jne    11ec <main+0x9c>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1030 <write@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1070 <read@plt>
mov    %rax,-0x18(%rbp)
lea    -0x60(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
movabs $0x21646c726f7720,%rax
mov    %rax,0x16(%rsp)
movabs $0x77202c6f6c6c6548,%rax
2c 20 77
mov    %rax,0x10(%rsp)
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
jne    11e4 <main+0x84>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xe,%edx
call   1040 <write@plt>
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xe,%edx
call   1080 <read@plt>
lea    0xe34(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.string = [14 x i8] c"Hello, world!\00"
@.str = [4 x i8] c"Ok\0A\00"
@.str.1 = [7 x i8] c"Piped\0A\00"
@.str.2 = [6 x i8] c"|%s|\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i64
%4 = alloca [14 x i8]
%5 = alloca [50 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [14 x i8]* %4 to i8*
store i32 14, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%10 = call i64 @pipe(i32* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds [14 x i8], [14 x i8]* %4, i64 0, i64 0
%17 = load i32, i32* %6
%18 = call i64 @write(i32 %15, i8* %16, i32 %17)
store i64 %18, i64* %3
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* %6
%23 = call i64 @read(i32 %20, i8* %21, i32 %22)
store i64 %23, i64* %3
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %12, %0
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
ret i32 0
}

LLVM IR (-O2):
@__const.main.string = [14 x i8] c"Hello, world!\00"
@.str.2 = [6 x i8] c"|%s|\0A\00"
@str = [3 x i8] c"Ok\00"
@str.3 = [6 x i8] c"Piped\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [14 x i8]
%3 = alloca [50 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%9 = call i64 @pipe(i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.3, i64 0, i64 0))
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i64 @write(i32 %14, i8* %5, i32 14)
%16 = load i32, i32* %8
%17 = call i64 @read(i32 %16, i8* %6, i32 14)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %19
19: ; preds = %11, %0
%20 = load i32, i32* %8
%21 = call i32 @close(i32 %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
ret i32 0
}