#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*/);
scalar_t__ 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 a[4] = {1, 2, 3, 4};
  int c2p[2];
  pipe(c2p);
  if (fork() == 0) {
    a[2] += a[3];
    write(c2p[1], &a[2], sizeof(int));
    close(c2p[0]);
    close(c2p[1]);
    exit(0);
  }
  a[0] += a[1];
  wait(0);
  read(c2p[0], &a[2], sizeof(int));
  close(c2p[0]);
  close(c2p[1]);
  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    0xe6a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
call   1060 <pipe@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%rax
jne    11f4 <main+0x74>
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>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
xor    %edi,%edi
call   1090 <wait@plt>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
add    $0x8,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xdd4(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movaps 0xe75(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
je     11f5 <main+0x75>
movl   $0x3,0x10(%rsp)
xor    %edi,%edi
call   1090 <wait@plt>
mov    0x8(%rsp),%edi
lea    0x18(%rsp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x10(%rsp),%esi
add    0x18(%rsp),%esi
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret
lea    0x18(%rsp),%rsi
movl   $0x7,0x18(%rsp)
mov    0xc(%rsp),%edi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1080 <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 [4 x i32]
%3 = alloca [2 x i32]
store i32 0, i32* %1
%4 = bitcast [4 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %0
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%11 = load i32, i32* %10
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%13 = load i32, i32* %12
%14 = add nsw i32 %13, %11
store i32 %14, i32* %12
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%18 = call i32 @write(i32 %16, i32* %17, i32 4)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %0
%27 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%30 = load i32, i32* %29
%31 = add nsw i32 %30, %28
store i32 %31, i32* %29
%32 = call i32 @wait(i32 0)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%34 = load i32, i32* %33
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%36 = call i32 @read(i32 %34, i32* %35, i32 4)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%44 = load i32, i32* %43
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%46 = load i32, i32* %45
%47 = add nsw i32 %46, %44
store i32 %47, i32* %45
%48 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%49 = load i32, i32* %48
%50 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %49)
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 i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %0
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
store i32 7, i32* %10
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @write(i32 %12, i32* %10, i32 4)
%14 = load i32, i32* %5
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %11
%17 = call i32 @close(i32 %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %0
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 0
store i32 3, i32* %20
%21 = call i32 @wait(i32 0)
%22 = load i32, i32* %5
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %1, i64 0, i64 2
%24 = call i32 @read(i32 %22, i32* %23, i32 4)
%25 = load i32, i32* %5
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %23
%31 = load i32, i32* %20
%32 = add nsw i32 %31, %30
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %32)
ret i32 0
}