#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;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(void) {
  int fd[2];
  int id;
  char string[] = "Jaaasooon!\n";
  char readbuffer[64];
  pipe(fd);
  id = fork();
  if (id == 0) {
    printf("+Start child work\n");
    close(fd[1]);
    read(fd[0], readbuffer, sizeof(readbuffer));
    printf("Received string: %s", readbuffer);
    printf("+Finish child work\n");
    return 0;
  } else {
    printf("+Start parent work\n");
    printf("Parent ID %d\n", id);
    close(fd[0]);
    write(fd[1], string, (strlen(string) + 1));
    printf("+Finish parent work\n");
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x1c(%rbp)
mov    0xe78(%rip),%eax
mov    %eax,-0x14(%rbp)
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1203 <main+0x93>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1080 <read@plt>
lea    -0x60(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1269 <main+0xf9>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x1c(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
movabs $0x6f6f6f736161614a,%rax
6f 6f 6f
mov    %rax,0x10(%rsp)
movl   $0xa216e,0x18(%rsp)
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     1202 <main+0x82>
mov    %eax,%ebx
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
lea    0xe58(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <write@plt>
lea    0xe41(%rip),%rdi
jmp    1245 <main+0xc5>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x40,%edx
call   1090 <read@plt>
lea    0xdd8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe22(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@__const.main.string = [12 x i8] c"Jaaasooon!\0A\00"
@.str.1 = [20 x i8] c"Received string: %s\00"
@.str.4 = [14 x i8] c"Parent ID %d\0A\00"
@str = [19 x i8] c"+Start parent work\00"
@str.6 = [20 x i8] c"+Finish parent work\00"
@str.7 = [18 x i8] c"+Start child work\00"
@str.8 = [19 x i8] c"+Finish child work\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [12 x i8]
%3 = alloca [64 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [64 x i8], [64 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()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %7
%17 = call i32 @read(i32 %16, i8* %6, i32 64)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %29
19: ; preds = %0
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 %9)
%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 i64 @strlen(i8* %5)
%27 = add nsw i64 %26, 1
%28 = call i32 @write(i32 %25, i8* %5, i64 %27)
br label %29
29: ; preds = %19, %11
%30 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0), %19 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str.8, i64 0, i64 0), %11 ]
%31 = call i32 @puts(i8* dereferenceable(1) %30)
ret i32 0
}