#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 int /*<<< orphan*/ val;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int evutil_socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int, int *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char **argv) {
  int fds[2];
  int ret;
  ret = evutil_socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
  if (ret < 0) {
    printf("evutil_socketpair falt %d!", ret);
    return -1;
  }
  if (fork()) {
    int count = 0;
    int val;
    close(fds[1]);
    while (1) {
      ++count;
      write(fds[0], &count, sizeof count);
      read(fds[0], &val, sizeof val);
      printf("recv data :%d\n", val);
    }
  } else {
    int val;
    close(fds[0]);
    while (1) {
      sleep(1);
      read(fds[1], &val, sizeof(val));
      printf("recv data :%d\n", val);
      val = -val;
      write(fds[1], &val, sizeof val);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rcx
xor    %edx,%edx
call   1050 <evutil_socketpair@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ca <main+0x5a>
mov    -0x1c(%rbp),%esi
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
je     122c <main+0xbc>
movl   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x24(%rbp),%esi
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
jmp    11ea <main+0x7a>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    -0x28(%rbp),%esi
lea    0xdc2(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    1234 <main+0xc4>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rcx
xor    %edx,%edx
call   1050 <evutil_socketpair@plt>
test   %eax,%eax
js     1207 <main+0x97>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     1225 <main+0xb5>
mov    0x10(%rsp),%edi
call   1060 <close@plt>
mov    $0x1,%ebp
lea    0x8(%rsp),%r14
lea    0x14(%rsp),%r15
lea    0xe54(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    %ebp,0x8(%rsp)
mov    0xc(%rsp),%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    0xc(%rsp),%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
add    $0x1,%ebp
jmp    11d0 <main+0x60>
lea    0xdf2(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0xc(%rsp),%edi
call   1060 <close@plt>
lea    0x8(%rsp),%rbx
lea    0xde1(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    0x8(%rsp),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
neg    %ebp
mov    %ebp,0x8(%rsp)
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
jmp    1240 <main+0xd0>

LLVM IR (-O0):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [27 x i8] c"evutil_socketpair falt %d!\00"
@.str.1 = [15 x i8] c"recv data :%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @AF_UNIX
%12 = load i32, i32* @SOCK_STREAM
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%14 = call i32 @evutil_socketpair(i32 %11, i32 %12, i32 0, i32* %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32, i32* %7
%19 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %18)
ret i32 -1
20: ; preds = %2
%21 = call i64 (...) @fork()
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %38
23: ; preds = %20
store i32 0, i32* %8
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %23, %27
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%31 = load i32, i32* %30
%32 = call i32 @write(i32 %31, i32* %8, i32 4)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%34 = load i32, i32* %33
%35 = call i32 @read(i32 %34, i32* %9, i32 4)
%36 = load i32, i32* %9
%37 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %27
38: ; preds = %20
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%40 = load i32, i32* %39
%41 = call i32 @close(i32 %40)
br label %42
42: ; preds = %38, %42
%43 = call i32 @sleep(i32 1)
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%45 = load i32, i32* %44
%46 = call i32 @read(i32 %45, i32* %10, i32 4)
%47 = load i32, i32* %10
%48 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = load i32, i32* %10
%50 = sub nsw i32 0, %49
store i32 %50, i32* %10
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%52 = load i32, i32* %51
%53 = call i32 @write(i32 %52, i32* %10, i32 4)
br label %42
}

LLVM IR (-O2):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [27 x i8] c"evutil_socketpair falt %d!\00"
@.str.1 = [15 x i8] c"recv data :%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [2 x i32]* %3 to i8*
%8 = load i32, i32* @AF_UNIX
%9 = load i32, i32* @SOCK_STREAM
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%11 = call i32 @evutil_socketpair(i32 %8, i32 %9, i32 0, i32* %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 -1
15: ; preds = %2
%16 = call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %33, label %18
18: ; preds = %15
%19 = bitcast i32* %4 to i8*
%20 = bitcast i32* %5 to i8*
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
br label %24
24: ; preds = %24, %18
%25 = phi i32 [ %26, %24 ], [ 0, %18 ]
%26 = add nuw nsw i32 %25, 1
store i32 %26, i32* %4
%27 = load i32, i32* %10
%28 = call i32 @write(i32 %27, i32* %4, i32 4)
%29 = load i32, i32* %10
%30 = call i32 @read(i32 %29, i32* %5, i32 4)
%31 = load i32, i32* %5
%32 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %24
33: ; preds = %15
%34 = bitcast i32* %6 to i8*
%35 = load i32, i32* %10
%36 = call i32 @close(i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
br label %38
38: ; preds = %38, %33
%39 = call i32 @sleep(i32 1)
%40 = load i32, i32* %37
%41 = call i32 @read(i32 %40, i32* %6, i32 4)
%42 = load i32, i32* %6
%43 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = sub nsw i32 0, %42
store i32 %44, i32* %6
%45 = load i32, i32* %37
%46 = call i32 @write(i32 %45, i32* %6, i32 4)
br label %38
}