#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__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ memcmp(char const *, char *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char const *, int);
int main(void) {
  const char msg[] = "Hello, World!";
  char buf[512];
  int rv;
  int pfd[2];
  if (pipe(pfd)) {
    perror("pipe");
    return 1;
  }
  if (write(pfd[1], msg, sizeof msg) != sizeof msg) {
    perror("write");
    return 1;
  }
  while ((rv = read(pfd[0], buf, sizeof buf)) < sizeof msg) {
    if (rv == -1 && errno == EINTR)
      continue;
    perror("read");
    return 1;
  }
  if (memcmp(msg, buf, sizeof msg)) {
    fprintf(stderr, "Message miscompare!\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe87(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xe85(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xe7f(%rip),%ax
mov    %ax,-0x6(%rbp)
lea    -0x22c(%rbp),%rdi
call   1040 <pipe@plt>
cmp    $0x0,%rax
je     11bf <main+0x5f>
lea    0xe60(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b0 <main+0x150>
mov    -0x228(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
cltq
cmp    $0xe,%rax
je     11f7 <main+0x97>
lea    0xe2d(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b0 <main+0x150>
jmp    11fc <main+0x9c>
mov    -0x22c(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %eax,-0x224(%rbp)
cltq
cmp    $0xe,%rax
jae    1269 <main+0x109>
cmpl   $0xffffffff,-0x224(%rbp)
jne    1251 <main+0xf1>
mov    0x2d9f(%rip),%rax
mov    (%rax),%rax
mov    0x2d8d(%rip),%rcx
cmp    (%rcx),%rax
jne    1251 <main+0xf1>
jmp    11fc <main+0x9c>
lea    0xdc1(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b0 <main+0x150>
lea    -0x12(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0xe,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
je     12a9 <main+0x149>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xd86(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b0 <main+0x150>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x228,%rsp
movabs $0x21646c726f5720,%rax
mov    %rax,0x16(%rsp)
movabs $0x57202c6f6c6c6548,%rax
2c 20 57
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <pipe@plt>
test   %rax,%rax
jne    1209 <main+0xa9>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
cmp    $0xe,%eax
jne    1217 <main+0xb7>
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0x200,%edx
call   1050 <read@plt>
cmp    $0xd,%eax
jbe    1225 <main+0xc5>
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rsi
mov    $0xe,%edx
call   1060 <memcmp@plt>
test   %rax,%rax
je     11ff <main+0x9f>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe31(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x228,%rsp
ret
xor    %eax,%eax
add    $0x228,%rsp
ret
lea    0xdfe(%rip),%rdi
call   1080 <perror@plt>
jmp    11f2 <main+0x92>
lea    0xdf5(%rip),%rdi
call   1080 <perror@plt>
jmp    11f2 <main+0x92>
lea    0xded(%rip),%rdi
call   1080 <perror@plt>
jmp    11f2 <main+0x92>

LLVM IR (-O0):
@__const.main.msg = [14 x i8] c"Hello, World!\00"
@.str = [5 x i8] c"pipe\00"
@.str.1 = [6 x i8] c"write\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.3 = [21 x i8] c"Message miscompare!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = alloca [2 x i32]
store i32 0, i32* %1
%6 = bitcast [14 x i8]* %2 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %48
12: ; preds = %0
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%16 = call i32 @write(i32 %14, i8* %15, i32 14)
%17 = sext i32 %16 to i64
%18 = icmp ne i64 %17, 14
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %48
21: ; preds = %12
br label %22
22: ; preds = %36, %21
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%24 = load i32, i32* %23
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%26 = call i32 @read(i32 %24, i8* %25, i32 512)
store i32 %26, i32* %4
%27 = sext i32 %26 to i64
%28 = icmp ult i64 %27, 14
br i1 %28, label %29, label %39
29: ; preds = %22
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i64, i64* @errno
%34 = load i64, i64* @EINTR
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %32
br label %22
37: ; preds = %32, %29
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %48
39: ; preds = %22
%40 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%42 = call i64 @memcmp(i8* %40, i8* %41, i32 14)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %48
47: ; preds = %39
store i32 0, i32* %1
br label %48
48: ; preds = %47, %44, %37, %19, %10
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@__const.main.msg = [14 x i8] c"Hello, World!\00"
@.str = [5 x i8] c"pipe\00"
@.str.1 = [6 x i8] c"write\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.2 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.3 = [21 x i8] c"Message miscompare!\0A\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = alloca [512 x i8]
%3 = alloca [2 x i32]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %31
12: ; preds = %0
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @write(i32 %14, i8* %4, i32 14)
%16 = icmp eq i32 %15, 14
br i1 %16, label %19, label %17
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %31
19: ; preds = %12
%20 = load i32, i32* %7
%21 = call i32 @read(i32 %20, i8* %5, i32 512)
%22 = icmp ult i32 %21, 14
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %31
25: ; preds = %19
%26 = call i64 @memcmp(i8* %4, i8* %5, i32 14)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %25, %28, %23, %17, %10
%32 = phi i32 [ 1, %10 ], [ 1, %17 ], [ 1, %23 ], [ 1, %28 ], [ 0, %25 ]
ret i32 %32
}