#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 */
scalar_t__ close(int);
int /*<<< orphan*/ exit(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 resstring[14];
  if (pipe(fd) < 0) {
    printf("Can\'t create pipe\n");
    exit(-1);
  }
  size = write(fd[1], string, 14);
  if (size != 14) {
    printf("Can\'t write all string\n");
    exit(-1);
  }
  size = read(fd[0], resstring, 14);
  if (size < 0) {
    printf("Can\'t read string\n");
    exit(-1);
  }
  printf("%s\n", resstring);
  if (close(fd[0]) < 0) {
    printf("Can\'t close input stream\n");
  }
  if (close(fd[1]) < 0) {
    printf("Can\'t close output stream\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x26(%rbp)
mov    0xe88(%rip),%eax
mov    %eax,-0x1e(%rbp)
mov    0xe82(%rip),%ax
mov    %ax,-0x1a(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    11b9 <main+0x59>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0xe,-0x18(%rbp)
je     11f1 <main+0x91>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0xe,%edx
call   1070 <read@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jae    1229 <main+0xc9>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    -0x34(%rbp),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
jge    125b <main+0xfb>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
jge    127b <main+0x11b>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movabs $0x21646c726f7720,%rax
mov    %rax,0x16(%rsp)
movabs $0x77202c6f6c6c6548,%rax
2c 20 77
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
js     1205 <main+0xa5>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xe,%edx
call   1040 <write@plt>
cmp    $0xe,%rax
jne    120e <main+0xae>
mov    0x8(%rsp),%edi
lea    0x22(%rsp),%rbx
mov    %rbx,%rsi
mov    $0xe,%edx
call   1070 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
test   %rax,%rax
jns    11e3 <main+0x83>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
test   %rax,%rax
jns    11fd <main+0x9d>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xe4c(%rip),%rdi
jmp    1215 <main+0xb5>
lea    0xe2c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@__const.main.string = [14 x i8] c"Hello, world!\00"
@.str = [19 x i8] c"Can't create pipe\0A\00"
@.str.1 = [24 x i8] c"Can't write all string\0A\00"
@.str.2 = [19 x i8] c"Can't read string\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [26 x i8] c"Can't close input stream\0A\00"
@.str.5 = [27 x i8] c"Can't close output stream\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i64
%4 = alloca [14 x i8]
%5 = alloca [14 x i8]
store i32 0, i32* %1
%6 = bitcast [14 x i8]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %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 = call i64 @write(i32 %15, i8* %16, i32 14)
store i64 %17, i64* %3
%18 = load i64, i64* %3
%19 = icmp ne i64 %18, 14
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %13
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%27 = call i64 @read(i32 %25, i8* %26, i32 14)
store i64 %27, i64* %3
%28 = load i64, i64* %3
%29 = icmp ult i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %23
%34 = getelementptr inbounds [14 x i8], [14 x i8]* %5, 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)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i64 @close(i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %33
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %33
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%44 = load i32, i32* %43
%45 = call i64 @close(i32 %44)
%46 = icmp slt i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %49
49: ; preds = %47, %42
ret i32 0
}

LLVM IR (-O2):
@__const.main.string = [14 x i8] c"Hello, world!\00"
@str = [26 x i8] c"Can't close output stream\00"
@str.6 = [25 x i8] c"Can't close input stream\00"
@str.7 = [23 x i8] c"Can't write all string\00"
@str.8 = [18 x i8] c"Can't create pipe\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [14 x i8]
%3 = alloca [14 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 [14 x i8], [14 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i64 @write(i32 %15, i8* %5, i32 14)
%17 = icmp eq i64 %16, 14
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %13
%22 = load i32, i32* %7
%23 = call i64 @read(i32 %22, i8* %6, i32 14)
%24 = call i32 @puts(i8* %6)
%25 = load i32, i32* %7
%26 = call i64 @close(i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
br label %30
30: ; preds = %28, %21
%31 = load i32, i32* %14
%32 = call i64 @close(i32 %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %34, %30
ret i32 0
}