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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, int *, int);
int main() {
  int fd_1[2];
  int fd_2[2];
  int buff[2];
  int input[2];
  buff[0] = 10;
  buff[1] = 15;
  int buffer[1];
  pipe(fd_1);
  pipe(fd_2);
  pid_t pid = fork();
  if (pid != 0) {
    printf("father start\n");
    printf("f1\n");
    sleep(1);
    printf("f2\n");
    write(fd_1[1], buff, 8);
    printf("%d  %d\n", buff[0], buff[1]);
    printf("f3\n");
    read(fd_2[0], buffer, 4);
    printf("f4n\n");
    printf("%d\n", buffer[0]);
  } else {
    printf("son start\n");
    printf("s1\n");
    printf("slept\n");
    read(fd_1[0], input, 8);
    printf("s2\n");
    input[0] += input[1];
    printf("s3 %d\n", input[0]);
    write(fd_2[1], input, 4);
    printf("son end\n");
    exit(0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x1c(%rbp)
movl   $0xf,-0x18(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
lea    -0x14(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1251 <main+0xe1>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x8,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12da <main+0x16a>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x8,%edx
call   1060 <read@plt>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd94(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movabs $0xf0000000a,%rax
mov    %rax,0x18(%rsp)
lea    0x10(%rsp),%rdi
call   1060 <pipe@plt>
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     1253 <main+0xd3>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <sleep@plt>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%rsp),%edi
lea    0x18(%rsp),%rsi
mov    $0x8,%edx
call   1040 <write@plt>
lea    0xe00(%rip),%rdi
mov    $0xa,%esi
mov    $0xf,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
mov    %rsp,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%esi
lea    0xdc0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xdb5(%rip),%rdi
call   1030 <puts@plt>
lea    0xdb3(%rip),%rdi
call   1030 <puts@plt>
lea    0xdaa(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
mov    $0x8,%edx
call   1070 <read@plt>
lea    0xd90(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%esi
add    0x4(%rsp),%esi
mov    %esi,(%rsp)
lea    0xd60(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
lea    0xd5e(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"father start\0A\00"
@.str.1 = [4 x i8] c"f1\0A\00"
@.str.2 = [4 x i8] c"f2\0A\00"
@.str.3 = [8 x i8] c"%d %d\0A\00"
@.str.4 = [4 x i8] c"f3\0A\00"
@.str.5 = [5 x i8] c"f4n\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.7 = [11 x i8] c"son start\0A\00"
@.str.8 = [4 x i8] c"s1\0A\00"
@.str.9 = [7 x i8] c"slept\0A\00"
@.str.10 = [4 x i8] c"s2\0A\00"
@.str.11 = [7 x i8] c"s3 %d\0A\00"
@.str.12 = [9 x i8] c"son end\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = alloca [1 x i32]
%7 = alloca i64
store i32 0, i32* %1
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
store i32 10, i32* %8
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
store i32 15, i32* %9
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%13 = call i32 @pipe(i32* %12)
%14 = call i64 (...) @fork()
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %40
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @sleep(i32 1)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%25 = call i32 @write(i32 %23, i32* %24, i32 8)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds [1 x i32], [1 x i32]* %6, i64 0, i64 0
%35 = call i32 @read(i32 %33, i32* %34, i32 4)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%37 = getelementptr inbounds [1 x i32], [1 x i32]* %6, i64 0, i64 0
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %38)
br label %63
40: ; preds = %0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%45 = load i32, i32* %44
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%47 = call i32 @read(i32 %45, i32* %46, i32 8)
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%50 = load i32, i32* %49
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%52 = load i32, i32* %51
%53 = add nsw i32 %52, %50
store i32 %53, i32* %51
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%55 = load i32, i32* %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %55)
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%58 = load i32, i32* %57
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%60 = call i32 @write(i32 %58, i32* %59, i32 4)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
%62 = call i32 @exit(i32 0)
unreachable
63: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@.str.3 = [8 x i8] c"%d %d\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.11 = [7 x i8] c"s3 %d\0A\00"
@str = [10 x i8] c"son start\00"
@str.13 = [3 x i8] c"s1\00"
@str.14 = [6 x i8] c"slept\00"
@str.15 = [3 x i8] c"s2\00"
@str.16 = [8 x i8] c"son end\00"
@str.17 = [13 x i8] c"father start\00"
@str.18 = [3 x i8] c"f1\00"
@str.19 = [3 x i8] c"f2\00"
@str.20 = [3 x i8] c"f3\00"
@str.21 = [4 x i8] c"f4n\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = alloca [1 x i32]
%6 = bitcast [2 x i32]* %1 to i8*
%7 = bitcast [2 x i32]* %2 to i8*
%8 = bitcast [2 x i32]* %3 to i8*
%9 = bitcast [2 x i32]* %4 to i8*
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 10, i32* %10
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 15, i32* %11
%12 = bitcast [1 x i32]* %5 to i8*
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%16 = call i32 @pipe(i32* %15)
%17 = call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %35, label %19
19: ; preds = %0
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.17, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.18, i64 0, i64 0))
%22 = call i32 @sleep(i32 1)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.19, i64 0, i64 0))
%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, i32* %10, i32 8)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 10, i32 15)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.20, i64 0, i64 0))
%29 = load i32, i32* %15
%30 = getelementptr inbounds [1 x i32], [1 x i32]* %5, i64 0, i64 0
%31 = call i32 @read(i32 %29, i32* %30, i32 4)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.21, i64 0, i64 0))
%33 = load i32, i32* %30
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %33)
ret i32 0
35: ; preds = %0
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.13, i64 0, i64 0))
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.14, i64 0, i64 0))
%39 = load i32, i32* %13
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%41 = call i32 @read(i32 %39, i32* %40, i32 8)
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str.15, i64 0, i64 0))
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%44 = load i32, i32* %43
%45 = load i32, i32* %40
%46 = add nsw i32 %45, %44
store i32 %46, i32* %40
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%49 = load i32, i32* %48
%50 = call i32 @write(i32 %49, i32* %40, i32 4)
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.16, i64 0, i64 0))
%52 = call i32 @exit(i32 0)
unreachable
}