#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 u_int;
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  void *sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ ncpus;

/* Variables and functions */
void *AF_LOCAL;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_un *, int);
scalar_t__ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
scalar_t__ listen(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int socket(void *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
scalar_t__ sysctlbyname(char *, int *, size_t *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ warnx(char *);
int main(int argc, char **argv) {
  struct sockaddr_un servaddr;
  int listenfd, connfd, pid;
  u_int counter, ncpus;
  size_t len;
  len = sizeof(ncpus);
  if (sysctlbyname("kern.smp.cpus", &ncpus, &len, NULL, 0) < 0)
    err(1, "kern.smp.cpus");
  if (len != sizeof(ncpus))
    errx(1, "kern.smp.cpus: invalid length");
  if (ncpus < 2)
    warnx("SMP not present, test may be unable to trigger race");
  if ((listenfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0)
    err(1, "parent: socket error");
  (void)unlink("/tmp/mytest.socket");
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sun_family = AF_LOCAL;
  strcpy(servaddr.sun_path, "/tmp/mytest.socket");
  if (bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
    err(1, "parent: bind error");
  if (listen(listenfd, 1024) < 0)
    err(1, "parent: listen error");
  pid = fork();
  if (pid == -1)
    err(1, "fork()");
  if (pid != 0) {
    close(listenfd);
    sleep(1);
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sun_family = AF_LOCAL;
    strcpy(servaddr.sun_path, "/tmp/mytest.socket");
    for (counter = 0; counter < 100000; counter++) {
      if ((connfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) {
        (void)kill(pid, SIGTERM);
        err(1, "parent: socket error");
      }
      if (connect(connfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
        (void)kill(pid, SIGTERM);
        err(1, "parent: connect error");
      }
      if (close(connfd) < 0) {
        (void)kill(pid, SIGTERM);
        err(1, "parent: close error");
      }
      usleep(100);
    }
    (void)kill(pid, SIGTERM);
  } else {
    for (;;) {
      if ((connfd = accept(listenfd, (struct sockaddr *)NULL, NULL)) < 0)
        err(1, "child: accept error");
      if (close(connfd) < 0)
        err(1, "child: close error");
    }
  }
  printf("OK\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x4,-0x40(%rbp)
lea    0xdab(%rip),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x40(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1110 <sysctlbyname@plt>
cmp    $0x0,%rax
jge    1284 <main+0x54>
mov    $0x1,%edi
lea    0xd81(%rip),%rsi
call   10a0 <err@plt>
cmpq   $0x4,-0x40(%rbp)
je     12a0 <main+0x70>
mov    $0x1,%edi
lea    0xd73(%rip),%rsi
call   1050 <errx@plt>
cmpl   $0x2,-0x34(%rbp)
jge    12b6 <main+0x86>
lea    0xd7b(%rip),%rdi
call   1070 <warnx@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%rdi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    12ed <main+0xbd>
mov    $0x1,%edi
lea    0xd78(%rip),%rsi
call   10a0 <err@plt>
lea    0xd81(%rip),%rdi
call   1030 <unlink@plt>
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    0x2cd2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%edi
lea    0xd56(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    1350 <main+0x120>
mov    $0x1,%edi
lea    0xd3d(%rip),%rsi
call   10a0 <err@plt>
mov    -0x24(%rbp),%edi
mov    $0x400,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    1378 <main+0x148>
mov    $0x1,%edi
lea    0xd28(%rip),%rsi
call   10a0 <err@plt>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    139d <main+0x16d>
mov    $0x1,%edi
lea    0xd18(%rip),%rsi
call   10a0 <err@plt>
cmpl   $0x0,-0x2c(%rbp)
je     14df <main+0x2af>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1120 <sleep@plt>
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    0x2c12(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%edi
lea    0xc96(%rip),%rsi
call   1040 <strcpy@plt>
movl   $0x0,-0x30(%rbp)
cmpl   $0x186a0,-0x30(%rbp)
jge    14c9 <main+0x299>
mov    0x2be1(%rip),%rax
mov    (%rax),%rdi
mov    0x2bc7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    1440 <main+0x210>
mov    -0x2c(%rbp),%edi
mov    0x2bc0(%rip),%rax
mov    (%rax),%esi
call   1090 <kill@plt>
mov    $0x1,%edi
lea    0xc25(%rip),%rsi
call   10a0 <err@plt>
mov    -0x28(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1100 <connect@plt>
cmp    $0x0,%rax
jge    147d <main+0x24d>
mov    -0x2c(%rbp),%edi
mov    0x2b83(%rip),%rax
mov    (%rax),%esi
call   1090 <kill@plt>
mov    $0x1,%edi
lea    0xc3f(%rip),%rsi
call   10a0 <err@plt>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jge    14b1 <main+0x281>
mov    -0x2c(%rbp),%edi
mov    0x2b4f(%rip),%rax
mov    (%rax),%esi
call   1090 <kill@plt>
mov    $0x1,%edi
lea    0xc21(%rip),%rsi
call   10a0 <err@plt>
mov    $0x64,%edi
call   1140 <usleep@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13eb <main+0x1bb>
mov    -0x2c(%rbp),%edi
mov    0x2b15(%rip),%rax
mov    (%rax),%esi
call   1090 <kill@plt>
jmp    1538 <main+0x308>
jmp    14e4 <main+0x2b4>
mov    -0x24(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   10e0 <accept@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    1510 <main+0x2e0>
mov    $0x1,%edi
lea    0xbd6(%rip),%rsi
call   10a0 <err@plt>
mov    -0x28(%rbp),%edi
call   1080 <close@plt>
cmp    $0x0,%rax
jge    1533 <main+0x303>
mov    $0x1,%edi
lea    0xbc7(%rip),%rsi
call   10a0 <err@plt>
jmp    14e4 <main+0x2b4>
lea    0xbc9(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x4,0x20(%rsp)
lea    0xdb2(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x20(%rsp),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1110 <sysctlbyname@plt>
test   %rax,%rax
js     1399 <main+0x169>
cmpq   $0x4,0x20(%rsp)
jne    13b6 <main+0x186>
cmpl   $0x1,0xc(%rsp)
jg     128a <main+0x5a>
lea    0xda7(%rip),%rdi
call   1070 <warnx@plt>
mov    0x2d4f(%rip),%r15
mov    (%r15),%rdi
mov    0x2d35(%rip),%r12
mov    (%r12),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    12bd <main+0x8d>
lea    0xdad(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
lea    0xdb1(%rip),%rbp
mov    %rbp,%rdi
call   1030 <unlink@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%edi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x10,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    1317 <main+0xe7>
lea    0xd7b(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    %ebx,%edi
mov    $0x400,%esi
call   10b0 <listen@plt>
test   %rax,%rax
jns    1339 <main+0x109>
lea    0xd6c(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
xor    %eax,%eax
call   1130 <fork@plt>
test   %eax,%eax
jne    13d7 <main+0x1a7>
lea    0xd92(%rip),%r14
lea    0xd9f(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    137e <main+0x14e>
mov    $0x1,%edi
mov    %r14,%rsi
call   10a0 <err@plt>
mov    %ebp,%edi
call   1080 <close@plt>
test   %rax,%rax
jns    1360 <main+0x130>
mov    $0x1,%edi
mov    %r15,%rsi
call   10a0 <err@plt>
jmp    1360 <main+0x130>
lea    0xc60(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
cmpq   $0x4,0x20(%rsp)
je     1277 <main+0x47>
lea    0xc51(%rip),%rsi
mov    $0x1,%edi
call   1060 <errx@plt>
cmpl   $0x1,0xc(%rsp)
jle    127e <main+0x4e>
jmp    128a <main+0x5a>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    13ef <main+0x1bf>
lea    0xccb(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1120 <sleep@plt>
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   10d0 <bzero@plt>
mov    (%r15),%rax
mov    %rax,0x18(%rsp)
mov    0x10(%rsp),%edi
lea    0xc53(%rip),%rsi
call   1040 <strcpy@plt>
mov    $0x186a0,%r14d
mov    0x2bb4(%rip),%r13
jmp    1454 <main+0x224>
cs nopw 0x0(%rax,%rax,1)
mov    $0x64,%edi
call   1140 <usleep@plt>
add    $0xffffffff,%r14d
je     14e7 <main+0x2b7>
mov    (%r15),%rdi
mov    (%r12),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1484 <main+0x254>
mov    0x0(%r13),%esi
mov    %ebp,%edi
call   1090 <kill@plt>
mov    $0x1,%edi
lea    0xbe1(%rip),%rsi
call   10a0 <err@plt>
mov    %ebx,%edi
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   1100 <connect@plt>
test   %rax,%rax
jns    14b6 <main+0x286>
mov    0x0(%r13),%esi
mov    %ebp,%edi
call   1090 <kill@plt>
mov    $0x1,%edi
lea    0xc06(%rip),%rsi
call   10a0 <err@plt>
mov    %ebx,%edi
call   1080 <close@plt>
test   %rax,%rax
jns    1440 <main+0x210>
mov    0x0(%r13),%esi
mov    %ebp,%edi
call   1090 <kill@plt>
mov    $0x1,%edi
lea    0xbf0(%rip),%rsi
call   10a0 <err@plt>
jmp    1440 <main+0x210>
mov    0x0(%r13),%esi
mov    %ebp,%edi
call   1090 <kill@plt>
lea    0xc0f(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"kern.smp.cpus\00"
@.str.1 = [30 x i8] c"kern.smp.cpus: invalid length\00"
@.str.2 = [52 x i8] c"SMP not present, test may be unable to trigger race\00"
@AF_LOCAL = global i8* null
@SOCK_STREAM = global i32 0
@.str.3 = [21 x i8] c"parent: socket error\00"
@.str.4 = [19 x i8] c"/tmp/mytest.socket\00"
@.str.5 = [19 x i8] c"parent: bind error\00"
@.str.6 = [21 x i8] c"parent: listen error\00"
@.str.7 = [7 x i8] c"fork()\00"
@SIGTERM = global i32 0
@.str.8 = [22 x i8] c"parent: connect error\00"
@.str.9 = [20 x i8] c"parent: close error\00"
@.str.10 = [20 x i8] c"child: accept error\00"
@.str.11 = [19 x i8] c"child: close error\00"
@.str.12 = [4 x i8] c"OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_un
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 4, i64* %12
%13 = call i64 @sysctlbyname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %11, i64* %12, i32* null, i32 0)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = load i64, i64* %12
%19 = icmp ne i64 %18, 4
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @errx(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = load i32, i32* %11
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @warnx(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = load i8*, i8** @AF_LOCAL
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i8* %28, i32 %29, i32 0)
store i32 %30, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = call i32 @unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%36 = call i32 @bzero(%struct.sockaddr_un* %6, i32 16)
%37 = load i8*, i8** @AF_LOCAL
%38 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i8* %37, i8** %38
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @strcpy(i32 %40, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%42 = load i32, i32* %7
%43 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%44 = call i64 @bind(i32 %42, %struct.sockaddr* %43, i32 16)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %34
%47 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %46, %34
%49 = load i32, i32* %7
%50 = call i64 @listen(i32 %49, i32 1024)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
%55 = call i32 (...) @fork()
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %60
60: ; preds = %58, %54
%61 = load i32, i32* %9
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %114
63: ; preds = %60
%64 = load i32, i32* %7
%65 = call i64 @close(i32 %64)
%66 = call i32 @sleep(i32 1)
%67 = call i32 @bzero(%struct.sockaddr_un* %6, i32 16)
%68 = load i8*, i8** @AF_LOCAL
%69 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i8* %68, i8** %69
%70 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%71 = load i32, i32* %70
%72 = call i32 @strcpy(i32 %71, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %10
br label %73
73: ; preds = %107, %63
%74 = load i32, i32* %10
%75 = icmp slt i32 %74, 100000
br i1 %75, label %76, label %110
76: ; preds = %73
%77 = load i8*, i8** @AF_LOCAL
%78 = load i32, i32* @SOCK_STREAM
%79 = call i32 @socket(i8* %77, i32 %78, i32 0)
store i32 %79, i32* %8
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %86
81: ; preds = %76
%82 = load i32, i32* %9
%83 = load i32, i32* @SIGTERM
%84 = call i32 @kill(i32 %82, i32 %83)
%85 = call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %86
86: ; preds = %81, %76
%87 = load i32, i32* %8
%88 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%89 = call i64 @connect(i32 %87, %struct.sockaddr* %88, i32 16)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %96
91: ; preds = %86
%92 = load i32, i32* %9
%93 = load i32, i32* @SIGTERM
%94 = call i32 @kill(i32 %92, i32 %93)
%95 = call i32 @err(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
br label %96
96: ; preds = %91, %86
%97 = load i32, i32* %8
%98 = call i64 @close(i32 %97)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %105
100: ; preds = %96
%101 = load i32, i32* %9
%102 = load i32, i32* @SIGTERM
%103 = call i32 @kill(i32 %101, i32 %102)
%104 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
br label %105
105: ; preds = %100, %96
%106 = call i32 @usleep(i32 100)
br label %107
107: ; preds = %105
%108 = load i32, i32* %10
%109 = add nsw i32 %108, 1
store i32 %109, i32* %10
br label %73
110: ; preds = %73
%111 = load i32, i32* %9
%112 = load i32, i32* @SIGTERM
%113 = call i32 @kill(i32 %111, i32 %112)
br label %128
114: ; preds = %60
br label %115
115: ; preds = %127, %114
%116 = load i32, i32* %7
%117 = call i32 @accept(i32 %116, %struct.sockaddr* null, i32* null)
store i32 %117, i32* %8
%118 = icmp slt i32 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %115
%120 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
br label %121
121: ; preds = %119, %115
%122 = load i32, i32* %8
%123 = call i64 @close(i32 %122)
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %127
125: ; preds = %121
%126 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %127
127: ; preds = %125, %121
br label %115
128: ; preds = %110
%129 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0))
%130 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i8* }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"kern.smp.cpus\00"
@.str.1 = [30 x i8] c"kern.smp.cpus: invalid length\00"
@.str.2 = [52 x i8] c"SMP not present, test may be unable to trigger race\00"
@AF_LOCAL = global i8* null
@SOCK_STREAM = global i32 0
@.str.3 = [21 x i8] c"parent: socket error\00"
@.str.4 = [19 x i8] c"/tmp/mytest.socket\00"
@.str.5 = [19 x i8] c"parent: bind error\00"
@.str.6 = [21 x i8] c"parent: listen error\00"
@.str.7 = [7 x i8] c"fork()\00"
@SIGTERM = global i32 0
@.str.8 = [22 x i8] c"parent: connect error\00"
@.str.9 = [20 x i8] c"parent: close error\00"
@.str.10 = [20 x i8] c"child: accept error\00"
@.str.11 = [19 x i8] c"child: close error\00"
@str = [3 x i8] c"OK\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca i32
%5 = alloca i64
%6 = bitcast %struct.sockaddr_un* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i64* %5 to i8*
store i64 4, i64* %5
%9 = call i64 @sysctlbyname(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* %4, i64* %5, i32* null, i32 0)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i64, i64* %5
%15 = icmp eq i64 %14, 4
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i32 @errx(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @warnx(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = load i8*, i8** @AF_LOCAL
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i8* %24, i32 %25, i32 0)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %23
%31 = call i32 @unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @bzero(%struct.sockaddr_un* %3, i32 16)
%33 = load i8*, i8** @AF_LOCAL
%34 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i8* %33, i8** %34
%35 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @strcpy(i32 %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%38 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%39 = call i64 @bind(i32 %26, %struct.sockaddr* %38, i32 16)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %30
%42 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %41, %30
%44 = call i64 @listen(i32 %26, i32 1024)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = call i32 (...) @fork()
switch i32 %49, label %52 [
i32 -1, label %50
i32 0, label %92
]
50: ; preds = %48
%51 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %52
52: ; preds = %50, %48
%53 = call i64 @close(i32 %26)
%54 = call i32 @sleep(i32 1)
%55 = call i32 @bzero(%struct.sockaddr_un* %3, i32 16)
%56 = load i8*, i8** @AF_LOCAL
store i8* %56, i8** %34
%57 = load i32, i32* %35
%58 = call i32 @strcpy(i32 %57, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %59
59: ; preds = %52, %83
%60 = phi i32 [ 0, %52 ], [ %85, %83 ]
%61 = load i8*, i8** @AF_LOCAL
%62 = load i32, i32* @SOCK_STREAM
%63 = call i32 @socket(i8* %61, i32 %62, i32 0)
%64 = icmp slt i32 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %59
%66 = load i32, i32* @SIGTERM
%67 = call i32 @kill(i32 %49, i32 %66)
%68 = call i32 @err(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %65, %59
%70 = call i64 @connect(i32 %63, %struct.sockaddr* %38, i32 16)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %69
%73 = load i32, i32* @SIGTERM
%74 = call i32 @kill(i32 %49, i32 %73)
%75 = call i32 @err(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0))
br label %76
76: ; preds = %72, %69
%77 = call i64 @close(i32 %63)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %83
79: ; preds = %76
%80 = load i32, i32* @SIGTERM
%81 = call i32 @kill(i32 %49, i32 %80)
%82 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.9, i64 0, i64 0))
br label %83
83: ; preds = %79, %76
%84 = call i32 @usleep(i32 100)
%85 = add nuw nsw i32 %60, 1
%86 = icmp eq i32 %85, 100000
br i1 %86, label %87, label %59
87: ; preds = %83
%88 = load i32, i32* @SIGTERM
%89 = call i32 @kill(i32 %49, i32 %88)
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%91 = call i32 @exit(i32 0)
unreachable
92: ; preds = %48, %102
%93 = call i32 @accept(i32 %26, %struct.sockaddr* null, i32* null)
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %97
95: ; preds = %92
%96 = call i32 @err(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.10, i64 0, i64 0))
br label %97
97: ; preds = %95, %92
%98 = call i64 @close(i32 %93)
%99 = icmp slt i64 %98, 0
br i1 %99, label %100, label %102
100: ; preds = %97
%101 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
br label %102
102: ; preds = %100, %97
br label %92
}