#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memcmp(char *, char *, int);
int pipe(int *);
int read(int, char *, int);
int write(int, char *, int);
int main(int argc, char **argv) {
  int fds[2];
  int r;
  char hw[] = "hello world";
  char buf[12];
  r = pipe(fds);
  if (r < 0) {
    char msg[] = "failed to create pipe";
    write(2, msg, sizeof msg - 1);
    exit(1);
  }
  r = write(fds[1], hw, sizeof hw - 1);
  if (r != sizeof hw - 1) {
    char msg[] = "write failed";
    write(2, msg, sizeof msg - 1);
    exit(1);
  }
  r = read(fds[0], buf, sizeof buf - 1);
  if (r != sizeof hw - 1) {
    char msg[] = "write failed";
    write(2, msg, sizeof msg - 1);
    exit(1);
  }
  if (!memcmp(buf, hw, sizeof hw - 1))
    r = 0;
  else
    r = 1;
  close(fds[1]);
  close(fds[0]);
  return r;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe83(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe81(%rip),%eax
mov    %eax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e7 <main+0x87>
mov    0xe79(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe76(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe74(%rip),%eax
mov    %eax,-0x40(%rbp)
mov    0xe6e(%rip),%ax
mov    %ax,-0x3c(%rbp)
lea    -0x50(%rbp),%rsi
mov    $0x2,%edi
mov    $0x15,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0xb,%rax
je     1243 <main+0xe3>
mov    0xdfc(%rip),%rax
mov    %rax,-0x5d(%rbp)
mov    0xdfa(%rip),%eax
mov    %eax,-0x55(%rbp)
mov    0xdf5(%rip),%al
mov    %al,-0x51(%rbp)
lea    -0x5d(%rbp),%rsi
mov    $0x2,%edi
mov    $0xc,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0xb,%edx
call   1060 <read@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0xb,%rax
je     129f <main+0x13f>
mov    0xda0(%rip),%rax
mov    %rax,-0x6a(%rbp)
mov    0xd9e(%rip),%eax
mov    %eax,-0x62(%rbp)
mov    0xd99(%rip),%al
mov    %al,-0x5e(%rbp)
lea    -0x6a(%rbp),%rsi
mov    $0x2,%edi
mov    $0xc,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x34(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xb,%edx
call   1070 <memcmp@plt>
cmp    $0x0,%eax
jne    12c6 <main+0x166>
movl   $0x0,-0x1c(%rbp)
jmp    12cd <main+0x16d>
movl   $0x1,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,0x28(%rsp)
movl   $0x646c72,0x30(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
test   %eax,%eax
js     1222 <main+0xc2>
mov    0xc(%rsp),%edi
lea    0x28(%rsp),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
cmp    $0xb,%eax
jne    11f3 <main+0x93>
mov    0x8(%rsp),%edi
lea    0x34(%rsp),%rsi
mov    $0xb,%edx
call   1060 <read@plt>
cmp    $0xb,%eax
jne    11f3 <main+0x93>
lea    0x34(%rsp),%rdi
lea    0x28(%rsp),%rsi
mov    $0xb,%edx
call   1070 <memcmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
ret
movabs $0x64656c69616620,%rax
mov    %rax,0x15(%rsp)
movabs $0x6166206574697277,%rax
20 66 61
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    $0x2,%edi
mov    $0xc,%edx
jmp    124c <main+0xec>
movaps 0xdf7(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x65706970206574,%rax
mov    %rax,0x1e(%rsp)
lea    0x10(%rsp),%rsi
mov    $0x2,%edi
mov    $0x15,%edx
call   1030 <write@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@__const.main.hw = [12 x i8] c"hello world\00"
@__const.main.msg = [22 x i8] c"failed to create pipe\00"
@__const.main.msg.1 = [13 x i8] c"write failed\00"
@__const.main.msg.2 = [13 x i8] c"write failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca [12 x i8]
%9 = alloca [12 x i8]
%10 = alloca [22 x i8]
%11 = alloca [13 x i8]
%12 = alloca [13 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [12 x i8]* %8 to i8*
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%15 = call i32 @pipe(i32* %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = bitcast [22 x i8]* %10 to i8*
%20 = getelementptr inbounds [22 x i8], [22 x i8]* %10, i64 0, i64 0
%21 = call i32 @write(i32 2, i8* %20, i32 21)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%25 = load i32, i32* %24
%26 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%27 = call i32 @write(i32 %25, i8* %26, i32 11)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = icmp ne i64 %29, 11
br i1 %30, label %31, label %36
31: ; preds = %23
%32 = bitcast [13 x i8]* %11 to i8*
%33 = getelementptr inbounds [13 x i8], [13 x i8]* %11, i64 0, i64 0
%34 = call i32 @write(i32 2, i8* %33, i32 12)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %23
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%38 = load i32, i32* %37
%39 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%40 = call i32 @read(i32 %38, i8* %39, i32 11)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = icmp ne i64 %42, 11
br i1 %43, label %44, label %49
44: ; preds = %36
%45 = bitcast [13 x i8]* %12 to i8*
%46 = getelementptr inbounds [13 x i8], [13 x i8]* %12, i64 0, i64 0
%47 = call i32 @write(i32 2, i8* %46, i32 12)
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %36
%50 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%51 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%52 = call i32 @memcmp(i8* %50, i8* %51, i32 11)
%53 = icmp ne i32 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %49
store i32 0, i32* %7
br label %56
55: ; preds = %49
store i32 1, i32* %7
br label %56
56: ; preds = %55, %54
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%58 = load i32, i32* %57
%59 = call i32 @close(i32 %58)
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%61 = load i32, i32* %60
%62 = call i32 @close(i32 %61)
%63 = load i32, i32* %7
ret i32 %63
}

LLVM IR (-O2):
@__const.main.hw = [12 x i8] c"hello world\00"
@__const.main.msg = [22 x i8] c"failed to create pipe\00"
@__const.main.msg.2 = [13 x i8] c"write failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [12 x i8]
%5 = alloca [12 x i8]
%6 = alloca [22 x i8]
%7 = alloca [13 x i8]
%8 = alloca [13 x i8]
%9 = bitcast [2 x i32]* %3 to i8*
%10 = getelementptr inbounds [12 x i8], [12 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%13 = call i32 @pipe(i32* %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = getelementptr inbounds [22 x i8], [22 x i8]* %6, i64 0, i64 0
%17 = call i32 @write(i32 2, i8* %16, i32 21)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @write(i32 %21, i8* %10, i32 11)
%23 = icmp eq i32 %22, 11
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
%26 = call i32 @write(i32 2, i8* %25, i32 12)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = load i32, i32* %12
%30 = call i32 @read(i32 %29, i8* %11, i32 11)
%31 = icmp eq i32 %30, 11
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = getelementptr inbounds [13 x i8], [13 x i8]* %8, i64 0, i64 0
%34 = call i32 @write(i32 2, i8* %33, i32 12)
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %28
%37 = call i32 @memcmp(i8* %11, i8* %10, i32 11)
%38 = icmp ne i32 %37, 0
%39 = zext i1 %38 to i32
%40 = load i32, i32* %20
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* %12
%43 = call i32 @close(i32 %42)
ret i32 %39
}