#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(void) {
  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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rcx
xor    %edx,%edx
call   1060 <socketpair@plt>
cmp    $0x0,%rax
jge    11e7 <main+0x47>
mov    $0xffffffff,%edi
lea    0xe1e(%rip),%rsi
call   1090 <err@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    120e <main+0x6e>
mov    $0xffffffff,%edi
lea    0xe02(%rip),%rsi
call   1090 <err@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1221 <main+0x81>
mov    -0x1c(%rbp),%edi
call   1050 <receive_and_exit@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1269 <main+0xc9>
lea    0xdc3(%rip),%rdi
call   1030 <warn@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jne    127c <main+0xdc>
mov    -0x1c(%rbp),%edi
call   1080 <shutdown_and_exit@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
cmp    $0x0,%rax
jge    12b3 <main+0x113>
mov    $0xffffffff,%edi
lea    0xd62(%rip),%rsi
call   1090 <err@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
lea    0xd51(%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() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca [2 x i32]
store i32 0, i32* %1
%5 = load i32, i32* @PF_LOCAL
%6 = load i32, i32* @SOCK_STREAM
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %4, 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 = %0
%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, %0
%13 = call i64 (...) @fork()
store i64 %13, i64* %2
%14 = load i64, i64* %2
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @err(i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = load i64, i64* %2
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @receive_and_exit(i32 %23)
br label %25
25: ; preds = %21, %18
%26 = call i32 @sleep(i32 1)
%27 = call i64 (...) @fork()
store i64 %27, i64* %3
%28 = load i64, i64* %3
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = load i64, i64* %2
%33 = load i32, i32* @SIGKILL
%34 = call i64 @kill(i64 %32, i32 %33)
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %25
%37 = load i64, i64* %3
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%41 = load i32, i32* %40
%42 = call i32 @shutdown_and_exit(i32 %41)
br label %43
43: ; preds = %39, %36
%44 = call i32 @sleep(i32 1)
%45 = load i64, i64* %3
%46 = load i32, i32* @SIGKILL
%47 = call i64 @kill(i64 %45, i32 %46)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %43
%50 = call i32 @err(i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %49, %43
%52 = call i32 @sleep(i32 1)
%53 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%54 = 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() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = load i32, i32* @PF_LOCAL
%4 = load i32, i32* @SOCK_STREAM
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i64 @socketpair(i32 %3, i32 %4, i32 0, i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @err(i32 -1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i64 (...) @fork()
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @err(i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %21
15: ; preds = %10
%16 = icmp eq i64 %11, 0
br i1 %16, label %17, label %21
17: ; preds = %15
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @receive_and_exit(i32 %19)
br label %21
21: ; preds = %13, %17, %15
%22 = call i32 @sleep(i32 1)
%23 = call i64 (...) @fork()
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = call i32 @warn(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @SIGKILL
%28 = call i64 @kill(i64 %11, i32 %27)
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %21
%31 = icmp eq i64 %23, 0
br i1 %31, label %32, label %36
32: ; preds = %30
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%34 = load i32, i32* %33
%35 = call i32 @shutdown_and_exit(i32 %34)
br label %36
36: ; preds = %32, %30
%37 = call i32 @sleep(i32 1)
%38 = load i32, i32* @SIGKILL
%39 = call i64 @kill(i64 %23, i32 %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @err(i32 -1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %36
%44 = call i32 @sleep(i32 1)
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%46 = call i32 @exit(i32 0)
unreachable
}