#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*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ receiver(int);
int /*<<< orphan*/ sender(int);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int main() {
  int fd[2], wstat;
  pid_t child;
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd)) {
    perror("socketpair");
    abort();
  }
  child = fork();
  if (child < 0) {
    perror("fork");
    abort();
  }
  if (child) {
    close(fd[1]);
    receiver(fd[0]);
    wait(&wstat);
    fprintf(stderr, "child exited %d\n", wstat);
    if (wstat) {
      abort();
    }
  } else {
    close(fd[0]);
    sender(fd[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rcx
xor    %edx,%edx
call   1070 <socketpair@plt>
cmp    $0x0,%rax
je     11d9 <main+0x49>
lea    0xe33(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1202 <main+0x72>
lea    0xe15(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpq   $0x0,-0x18(%rbp)
je     1254 <main+0xc4>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1060 <receiver@plt>
lea    -0x10(%rbp),%rdi
call   10a0 <wait@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xdd7(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,-0x10(%rbp)
je     124f <main+0xbf>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1264 <main+0xd4>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1090 <sender@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rcx
xor    %edx,%edx
call   1070 <socketpair@plt>
test   %rax,%rax
jne    1221 <main+0x91>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
js     122a <main+0x9a>
je     1208 <main+0x78>
mov    0x14(%rsp),%edi
call   1040 <close@plt>
mov    0x10(%rsp),%edi
call   1060 <receiver@plt>
lea    0xc(%rsp),%rdi
call   10a0 <wait@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%edx
lea    0xe1b(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x0,0xc(%rsp)
je     121a <main+0x8a>
xor    %eax,%eax
call   1030 <abort@plt>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
mov    0x14(%rsp),%edi
call   1090 <sender@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xdd8(%rip),%rdi
jmp    1231 <main+0xa1>
lea    0xdda(%rip),%rdi
call   1080 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [11 x i8] c"socketpair\00"
@.str.1 = [5 x i8] c"fork\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"child exited %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i64 @socketpair(i32 %5, i32 %6, i32 0, i32* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (...) @abort()
unreachable
13: ; preds = %0
%14 = call i64 (...) @fork()
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (...) @abort()
unreachable
20: ; preds = %13
%21 = load i64, i64* %4
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @receiver(i32 %28)
%30 = call i32 @wait(i32* %3)
%31 = load i32, i32* @stderr
%32 = load i32, i32* %3
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %3
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %23
%37 = call i32 (...) @abort()
unreachable
38: ; preds = %23
br label %46
39: ; preds = %20
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%44 = load i32, i32* %43
%45 = call i32 @sender(i32 %44)
br label %46
46: ; preds = %39, %38
ret i32 0
}

LLVM IR (-O2):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [11 x i8] c"socketpair\00"
@.str.1 = [5 x i8] c"fork\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"child exited %d\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = bitcast [2 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = call i64 @socketpair(i32 %5, i32 %6, i32 0, i32* %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (...) @abort()
unreachable
13: ; preds = %0
%14 = call i64 (...) @fork()
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %13
%20 = icmp eq i64 %14, 0
br i1 %20, label %35, label %21
21: ; preds = %19
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %7
%26 = call i32 @receiver(i32 %25)
%27 = call i32 @wait(i32* %2)
%28 = load i32, i32* @stderr
%29 = load i32, i32* %2
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %2
%32 = icmp eq i32 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %21
%34 = call i32 (...) @abort()
unreachable
35: ; preds = %19
%36 = load i32, i32* %7
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @sender(i32 %39)
br label %41
41: ; preds = %21, %35
ret i32 0
}