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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main() {
  int fd[2], nbytes;
  pid_t childpid;
  char string[] = "Hellow world\n";
  char readbuffer[80];
  pipe(fd);
  if ((childpid = fork()) == -1) {
    perror("Forking failure");
    exit(1);
  }
  if (childpid == 0) {
    close(fd[0]);
    write(fd[1], string, strlen(string));
    exit(0);
  } else {
    close(fd[1]);
    read(fd[0], readbuffer, sizeof(readbuffer));
    printf("Received the string: %s ", readbuffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe57(%rip),%rax
mov    %rax,-0x22(%rbp)
mov    0xe55(%rip),%eax
mov    %eax,-0x1a(%rbp)
mov    0xe4f(%rip),%ax
mov    %ax,-0x16(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f3 <main+0x63>
lea    0xe2a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    123d <main+0xad>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x22(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x22(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x50,%edx
call   1080 <read@plt>
lea    -0x80(%rbp),%rsi
lea    0xdbd(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
movabs $0xa646c726f7720,%rax
mov    %rax,0x16(%rsp)
movabs $0x7720776f6c6c6548,%rax
77 20 77
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1207 <main+0x77>
cmp    $0xffffffff,%eax
je     1234 <main+0xa4>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x50,%edx
call   1080 <read@plt>
lea    0xe29(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret
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>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdd3(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.string = [14 x i8] c"Hellow world\0A\00"
@.str = [16 x i8] c"Forking failure\00"
@.str.1 = [25 x i8] c"Received the string: %s \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca [14 x i8]
%6 = alloca [80 x i8]
store i32 0, i32* %1
%7 = bitcast [14 x i8]* %5 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i32 (...) @fork()
store i32 %10, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds [14 x i8], [14 x i8]* %5, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @write(i32 %23, i8* %24, i32 %26)
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %15
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%36 = call i32 @read(i32 %34, i8* %35, i32 80)
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%38 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@__const.main.string = [14 x i8] c"Hellow world\0A\00"
@.str = [16 x i8] c"Forking failure\00"
@.str.1 = [25 x i8] c"Received the string: %s \00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [14 x i8]
%3 = alloca [80 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 [80 x i8], [80 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = call i32 (...) @fork()
switch i32 %9, label %21 [
i32 -1, label %10
i32 0, label %13
]
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i32, i32* %7
%15 = call i32 @close(i32 %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @strlen(i8* %5)
%19 = call i32 @write(i32 %17, i8* %5, i32 %18)
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %0
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %7
%26 = call i32 @read(i32 %25, i8* %6, i32 80)
%27 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %6)
ret i32 0
}