#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 */
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ wait(int *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  pid_t cpid;
  int fifod[2];
  int sta;
  char buf[256] = "Linux C\n";
  if (pipe(fifod) < 0) {
    printf("pipe error.\n");
    exit(1);
  }
  cpid = fork();
  if (cpid < 0) {
    printf("fork error.\n");
    exit(1);
  }
  if (cpid == 0) {
    close(fifod[0]);
    write(fifod[1], buf, sizeof(buf));
  } else {
    close(fifod[1]);
    read(fifod[0], buf, sizeof(buf));
    printf("Received message from child process: \n%s", buf);
    if (cpid = wait(&sta)) {
      printf("wait error.\n");
      exit(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe50(%rip),%rsi
mov    $0x100,%edx
call   1080 <memcpy@plt>
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    11e5 <main+0x55>
lea    0xf2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1213 <main+0x83>
lea    0xf0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    123f <main+0xaf>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1030 <write@plt>
jmp    12a4 <main+0x114>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
lea    -0x120(%rbp),%rsi
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rdi
call   10a0 <wait@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     129f <main+0x10f>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    12a4 <main+0x114>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x110,%rsp
lea    0xe51(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x100,%edx
call   1090 <memcpy@plt>
lea    0x4(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
js     124a <main+0xaa>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
js     1253 <main+0xb3>
je     1223 <main+0x83>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x100,%edx
call   1080 <read@plt>
lea    0xeff(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rdi
call   10b0 <wait@plt>
test   %rax,%rax
je     123f <main+0x9f>
lea    0xf08(%rip),%rdi
jmp    125a <main+0xba>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x100,%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
ret
lea    0xef0(%rip),%rdi
jmp    125a <main+0xba>
lea    0xedb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.buf = [256 x i8] c"Linux C\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [13 x i8] c"pipe error.\0A\00"
@.str.1 = [13 x i8] c"fork error.\0A\00"
@.str.2 = [41 x i8] c"Received message from child process: \0A%s\00"
@.str.3 = [13 x i8] c"wait error.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca [256 x i8]
store i32 0, i32* %1
%6 = bitcast [256 x i8]* %5 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, 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 ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i64 (...) @fork()
store i64 %14, i64* %2
%15 = load i64, i64* %2
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %13
%21 = load i64, i64* %2
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %20
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%30 = call i32 @write(i32 %28, i8* %29, i32 256)
br label %47
31: ; preds = %20
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%36 = load i32, i32* %35
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%38 = call i32 @read(i32 %36, i8* %37, i32 256)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = call i64 @wait(i32* %4)
store i64 %41, i64* %2
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %31
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %31
br label %47
47: ; preds = %46, %23
ret i32 0
}

LLVM IR (-O2):
@__const.main.buf = [256 x i8] c"Linux C\0A\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.2 = [41 x i8] c"Received message from child process: \0A%s\00"
@str = [12 x i8] c"wait error.\00"
@str.4 = [12 x i8] c"fork error.\00"
@str.5 = [12 x i8] c"pipe error.\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [256 x i8], [256 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 ([12 x i8], [12 x i8]* @str.5, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i64 (...) @fork()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = icmp eq i64 %14, 0
br i1 %20, label %21, label %27
21: ; preds = %19
%22 = load i32, i32* %7
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @write(i32 %25, i8* %6, i32 256)
br label %39
27: ; preds = %19
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = load i32, i32* %7
%32 = call i32 @read(i32 %31, i8* %6, i32 256)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%34 = call i64 @wait(i32* %2)
%35 = icmp eq i64 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %27
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %27, %21
ret i32 0
}