#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 fork();
int pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fork_result;
  int pipes[2];
  char buff[1024];
  int ret_code;
  char message[] = "This is the message to be transmitted";
  ret_code = pipe(pipes);
  if (ret_code != 0)
    exit(1);
  fork_result = fork();
  if (fork_result == 0) {
    close(pipes[0]);
    ret_code = write(pipes[1], message, strlen(message));
    if (ret_code < 0)
      exit(2);
    close(pipes[1]);
  } else {
    close(pipes[1]);
    ret_code = read(pipes[0], buff, strlen(message));
    if (ret_code < 0)
      exit(3);
    close(pipes[0]);
    printf("found message=\"%s\"\n", buff);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x450(%rbp),%rdi
lea    0xe49(%rip),%rsi
mov    $0x26,%edx
call   1090 <memcpy@plt>
lea    -0x1c(%rbp),%rdi
call   1070 <pipe@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
je     11e7 <main+0x57>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1264 <main+0xd4>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x45c(%rbp)
lea    -0x450(%rbp),%rax
mov    %rax,-0x458(%rbp)
lea    -0x450(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x45c(%rbp),%edi
mov    -0x458(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jge    1257 <main+0xc7>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
jmp    12db <main+0x14b>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x46c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x468(%rbp)
lea    -0x450(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x46c(%rbp),%edi
mov    -0x468(%rbp),%rsi
mov    %eax,%edx
call   1080 <read@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jge    12c0 <main+0x130>
mov    $0x3,%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
lea    -0x420(%rbp),%rsi
lea    0xd50(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x448,%rsp
movaps 0xe7f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe63(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movabs $0x64657474696d73,%rax
mov    %rax,0x2e(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
test   %eax,%eax
jne    11fe <main+0x7e>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
jne    1208 <main+0x88>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    123b <main+0xbb>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%ebx
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
lea    0x40(%rsp),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1080 <read@plt>
test   %eax,%eax
jns    124b <main+0xcb>
mov    $0x3,%edi
call   1090 <exit@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
lea    0xdcb(%rip),%rdi
lea    0x40(%rsp),%rsi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@__const.main.message = [38 x i8] c"This is the message to be transmitted\00"
@.str = [20 x i8] c"found message=\22%s\22\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [1024 x i8]
%5 = alloca [38 x i8]
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [38 x i8], [38 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = call i32 (...) @fork()
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %14
%18 = load i32, i32* %9
%19 = call i32 @close(i32 %18)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @strlen(i8* %8)
%23 = call i32 @write(i32 %21, i8* %8, i32 %22)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = call i32 @exit(i32 2)
unreachable
27: ; preds = %17
%28 = load i32, i32* %20
%29 = call i32 @close(i32 %28)
br label %44
30: ; preds = %14
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* %9
%35 = call i32 @strlen(i8* %8)
%36 = call i32 @read(i32 %34, i8* %7, i32 %35)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %30
%39 = call i32 @exit(i32 3)
unreachable
40: ; preds = %30
%41 = load i32, i32* %9
%42 = call i32 @close(i32 %41)
%43 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %44
44: ; preds = %40, %27
%45 = call i32 @exit(i32 0)
unreachable
}