#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 /*<<< orphan*/);
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ scanf(char *, int *, int *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
int main() {
  int a, b, sum;
  int c2p[2], p2c[2];
  pipe(c2p);
  pipe(p2c);
  int res = fork();
  if (res < 0) {
    printf("Error forking\n");
    return 0;
  }
  if (res == 0) {
    close(p2c[1]);
    close(c2p[0]);
    read(p2c[0], &a, sizeof(int));
    read(p2c[0], &b, sizeof(int));
    close(p2c[0]);
    sum = a + b;
    write(c2p[1], &sum, sizeof(int));
    close(c2p[1]);
    exit(0);
  }
  close(p2c[0]);
  close(c2p[1]);
  scanf("%d%d", &a, &b);
  write(p2c[1], &a, sizeof(int));
  write(p2c[1], &b, sizeof(int));
  close(p2c[1]);
  read(c2p[0], &sum, sizeof(int));
  close(c2p[0]);
  printf("Sum: %d\n", sum);
  wait(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
lea    -0x20(%rbp),%rdi
call   1060 <pipe@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11df <main+0x4f>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <main+0x142>
cmpl   $0x0,-0x24(%rbp)
jne    124c <main+0xbc>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x20(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    0xdac(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1080 <scanf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%esi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0x18(%rsp),%rdi
call   1070 <pipe@plt>
lea    0xc(%rsp),%rdi
call   1070 <pipe@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
js     1260 <main+0xc0>
je     1276 <main+0xd6>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x1c(%rsp),%edi
call   1060 <close@plt>
lea    0xe17(%rip),%rdi
lea    0x24(%rsp),%rbx
lea    0x20(%rsp),%r14
mov    %rbx,%rsi
mov    %r14,%rdx
call   1090 <scanf@plt>
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    0x10(%rsp),%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    0x10(%rsp),%edi
call   1060 <close@plt>
mov    0x18(%rsp),%edi
lea    0x14(%rsp),%rsi
mov    $0x4,%edx
call   1080 <read@plt>
mov    0x18(%rsp),%edi
call   1060 <close@plt>
mov    0x14(%rsp),%esi
lea    0xdb5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
jmp    126c <main+0xcc>
lea    0xda7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
mov    0x10(%rsp),%edi
call   1060 <close@plt>
mov    0x18(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
lea    0x24(%rsp),%rsi
mov    $0x4,%edx
call   1080 <read@plt>
mov    0xc(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0x4,%edx
call   1080 <read@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x20(%rsp),%eax
add    0x24(%rsp),%eax
mov    %eax,0x14(%rsp)
mov    0x1c(%rsp),%edi
lea    0x14(%rsp),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    0x1c(%rsp),%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Error forking\0A\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [9 x i8] c"Sum: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i32]
%6 = alloca [2 x i32]
%7 = alloca i32
store i32 0, i32* %1
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = call i32 (...) @fork()
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %72
17: ; preds = %0
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %46
20: ; preds = %17
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @read(i32 %28, i32* %2, i32 4)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%31 = load i32, i32* %30
%32 = call i32 @read(i32 %31, i32* %3, i32 4)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%34 = load i32, i32* %33
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %2
%37 = load i32, i32* %3
%38 = add nsw i32 %36, %37
store i32 %38, i32* %4
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @write(i32 %40, i32* %4, i32 4)
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%43 = load i32, i32* %42
%44 = call i32 @close(i32 %43)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %17
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%48 = load i32, i32* %47
%49 = call i32 @close(i32 %48)
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
%53 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%55 = load i32, i32* %54
%56 = call i32 @write(i32 %55, i32* %2, i32 4)
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%58 = load i32, i32* %57
%59 = call i32 @write(i32 %58, i32* %3, i32 4)
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%61 = load i32, i32* %60
%62 = call i32 @close(i32 %61)
%63 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%64 = load i32, i32* %63
%65 = call i32 @read(i32 %64, i32* %4, i32 4)
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%67 = load i32, i32* %66
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* %4
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %69)
%71 = call i32 @wait(i32 0)
store i32 0, i32* %1
br label %72
72: ; preds = %46, %15
%73 = load i32, i32* %1
ret i32 %73
}

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