#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*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, int *, int);
int main() {
  int p;
  int a[] = {1, 2, 3, 4};
  int c2p[2];
  pipe(c2p);
  p = fork();
  a[0] += a[1];
  if (p == 0) {
    a[2] += a[3];
    write(c2p[1], &a[2], sizeof(int));
    exit(0);
  }
  wait(0);
  read(c2p[0], &a[2], sizeof(int));
  a[0] += a[2];
  printf("%d\n", a[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11e0 <main+0x70>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1080 <wait@plt>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0x18(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movaps 0xe85(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
movl   $0x3,(%rsp)
test   %eax,%eax
je     11cf <main+0x5f>
xor    %edi,%edi
call   1080 <wait@plt>
mov    0x10(%rsp),%edi
lea    0x8(%rsp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    (%rsp),%esi
add    0x8(%rsp),%esi
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0x8(%rsp),%rsi
movl   $0x7,0x8(%rsp)
mov    0x14(%rsp),%edi
mov    $0x4,%edx
call   1030 <write@plt>
xor    %edi,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@__const.main.a = [4 x i32] [i32 1, i32 2, i32 3, i32 4]
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [4 x i32]
%2 = alloca [2 x i32]
%3 = bitcast [4 x i32]* %1 to i8*
%4 = bitcast [2 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
store i32 3, i32* %8
%9 = icmp eq i32 %7, 0
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
store i32 7, i32* %11
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @write(i32 %13, i32* %11, i32 4)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %0
%17 = call i32 @wait(i32 0)
%18 = load i32, i32* %5
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
%20 = call i32 @read(i32 %18, i32* %19, i32 4)
%21 = load i32, i32* %19
%22 = load i32, i32* %8
%23 = add nsw i32 %22, %21
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
ret i32 0
}