#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*/ PF_LOCAL;
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
scalar_t__ kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ receive_and_exit(int);
int /*<<< orphan*/ shutdown_and_exit(int);
int /*<<< orphan*/ sleep(int);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int /*<<< orphan*/ warn(char *);
int main(int argc, char *argv[]) {
  pid_t pida, pidb;
  int sv[2];
  if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0)
    err(-1, "socketpair");
  pida = fork();
  if (pida < 0)
    err(-1, "fork");
  if (pida == 0)
    receive_and_exit(sv[1]);
  sleep(1);
  pidb = fork();
  if (pidb < 0) {
    warn("fork");
    (void)kill(pida, SIGKILL);
    exit(-1);
  }
  if (pidb == 0)
    shutdown_and_exit(sv[1]);
  sleep(1);
  if (kill(pidb, SIGKILL) < 0)
    err(-1, "kill");
  sleep(1);
  printf("ok 1 - unix_sorflush\n");
  exit(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    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rcx
xor    %edx,%edx
call   1060 <socketpair@plt>
cmp    $0x0,%rax
jge    11ee <main+0x4e>
mov    $0xffffffff,%edi
lea    0xe17(%rip),%rsi
call   1090 <err@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1215 <main+0x75>
mov    $0xffffffff,%edi
lea    0xdfb(%rip),%rsi
call   1090 <err@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1228 <main+0x88>
mov    -0x24(%rbp),%edi
call   1050 <receive_and_exit@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1270 <main+0xd0>
lea    0xdbc(%rip),%rdi
call   1030 <warn@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1283 <main+0xe3>
mov    -0x24(%rbp),%edi
call   1080 <shutdown_and_exit@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d40(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
cmp    $0x0,%rax
jge    12ba <main+0x11a>
mov    $0xffffffff,%edi
lea    0xd5b(%rip),%rsi
call   1090 <err@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xd4a(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
xor    %edx,%edx
call   1060 <socketpair@plt>
test   %rax,%rax
jns    11d6 <main+0x36>
lea    0xe34(%rip),%rsi
mov    $0xffffffff,%edi
call   1090 <err@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %rax,%r14
test   %rax,%rax
jns    11f8 <main+0x58>
lea    0xe1f(%rip),%rsi
mov    $0xffffffff,%edi
call   1090 <err@plt>
jmp    1203 <main+0x63>
jne    1203 <main+0x63>
mov    0x4(%rsp),%edi
call   1050 <receive_and_exit@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jns    1240 <main+0xa0>
lea    0xdeb(%rip),%rdi
call   1030 <warn@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <kill@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    %rax,%rbx
jne    124e <main+0xae>
mov    0x4(%rsp),%edi
call   1080 <shutdown_and_exit@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <kill@plt>
test   %rax,%rax
jns    127f <main+0xdf>
lea    0xd9b(%rip),%rsi
mov    $0xffffffff,%edi
call   1090 <err@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xd85(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str = [11 x i8] c"socketpair\00"
@.str.1 = [5 x i8] c"fork\00"
@SIGKILL = global i32 0
@.str.2 = [5 x i8] c"kill\00"
@.str.3 = [22 x i8] c"ok 1 - unix_sorflush\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @PF_LOCAL
%10 = load i32, i32* @SOCK_STREAM
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%12 = call i64 @socketpair(i32 %9, i32 %10, i32 0, i32* %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @err(i32 -1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = call i64 (...) @fork()
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @err(i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = load i64, i64* %6
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 @receive_and_exit(i32 %27)
br label %29
29: ; preds = %25, %22
%30 = call i32 @sleep(i32 1)
%31 = call i64 (...) @fork()
store i64 %31, i64* %7
%32 = load i64, i64* %7
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%36 = load i64, i64* %6
%37 = load i32, i32* @SIGKILL
%38 = call i64 @kill(i64 %36, i32 %37)
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %29
%41 = load i64, i64* %7
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%45 = load i32, i32* %44
%46 = call i32 @shutdown_and_exit(i32 %45)
br label %47
47: ; preds = %43, %40
%48 = call i32 @sleep(i32 1)
%49 = load i64, i64* %7
%50 = load i32, i32* @SIGKILL
%51 = call i64 @kill(i64 %49, i32 %50)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %47
%54 = call i32 @err(i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %53, %47
%56 = call i32 @sleep(i32 1)
%57 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@PF_LOCAL = global i32 0
@SOCK_STREAM = global i32 0
@.str = [11 x i8] c"socketpair\00"
@.str.1 = [5 x i8] c"fork\00"
@SIGKILL = global i32 0
@.str.2 = [5 x i8] c"kill\00"
@str = [21 x i8] c"ok 1 - unix_sorflush\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = load i32, i32* @PF_LOCAL
%6 = load i32, i32* @SOCK_STREAM
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i64 @socketpair(i32 %5, i32 %6, i32 0, i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @err(i32 -1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = call i64 (...) @fork()
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @err(i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %23
17: ; preds = %12
%18 = icmp eq i64 %13, 0
br i1 %18, label %19, label %23
19: ; preds = %17
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @receive_and_exit(i32 %21)
br label %23
23: ; preds = %15, %19, %17
%24 = call i32 @sleep(i32 1)
%25 = call i64 (...) @fork()
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @SIGKILL
%30 = call i64 @kill(i64 %13, i32 %29)
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %23
%33 = icmp eq i64 %25, 0
br i1 %33, label %34, label %38
34: ; preds = %32
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @shutdown_and_exit(i32 %36)
br label %38
38: ; preds = %34, %32
%39 = call i32 @sleep(i32 1)
%40 = load i32, i32* @SIGKILL
%41 = call i64 @kill(i64 %25, i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 @err(i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %38
%46 = call i32 @sleep(i32 1)
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%48 = call i32 @exit(i32 0)
unreachable
}