#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 */
struct dirent {
  scalar_t__ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ BUFSIZ;
int O_NDELAY;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int atoi(scalar_t__);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ create_fifo(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ erts_run_erl_log_error(int /*<<< orphan*/ *, int, char *,
                                          char *, ...);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sf_close(int);
int sf_open(char *, int, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strn_cat(char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ strn_catf(char *, int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ strn_cpy(char *, int /*<<< orphan*/, char *);
scalar_t__ strncmp(scalar_t__, char *, int);
int /*<<< orphan*/ unlink(char *);
int erts_run_erl_open_fifo(char *pipename, char *w_pipename, char *r_pipename) {
  int calculated_pipename = 0;
  int highest_pipe_num = 0;
  int fd;
  if (*pipename && pipename[strlen(pipename) - 1] == '/') {
    DIR *dirp;
    struct dirent *direntp;
    calculated_pipename = 1;
    dirp = opendir(pipename);
    if (!dirp) {
      erts_run_erl_log_error(NULL, 579,
                             "errno=%d\n"
                             "Can't access pipe directory '%s'."
                             "\n",
                             errno, pipename);
      return 1;
    }
    while ((direntp = readdir(dirp)) != NULL) {
      if (strncmp(direntp->d_name, "erlang.pipe", strlen("erlang.pipe")) == 0) {
        int num = atoi(direntp->d_name + strlen("erlang.pipe") + 1);
        if (num > highest_pipe_num)
          highest_pipe_num = num;
      }
    }
    closedir(dirp);
    strn_catf(pipename, BUFSIZ, "%s.%d", "erlang.pipe", highest_pipe_num + 1);
  }
  for (;;) {
    strn_cpy(w_pipename, BUFSIZ, pipename);
    strn_cat(w_pipename, BUFSIZ, ".r");
    if (create_fifo(w_pipename, (S_IWUSR | S_IRUSR | S_IWOTH | S_IROTH |
                                 S_IWGRP | S_IRGRP)) < 0) {
      erts_run_erl_log_error(NULL, 602,
                             "errno=%d\n"
                             "Cannot create FIFO %s for writing."
                             "\n",
                             errno, w_pipename);
      return 1;
    }
    strn_cpy(r_pipename, BUFSIZ, pipename);
    strn_cat(r_pipename, BUFSIZ, ".w");
    if ((fd = sf_open(r_pipename, O_WRONLY | O_NDELAY, 0)) >= 0) {
      sf_close(fd);
      if (calculated_pipename) {
        ++highest_pipe_num;
        strn_catf(pipename, BUFSIZ, "%s.%d", "erlang.pipe",
                  highest_pipe_num + 1);
        continue;
      }
      erts_run_erl_log_error(NULL, 621,
                             "Erlang already running on pipe %s.\n"
                             "\n",
                             pipename);
      unlink(w_pipename);
      return 1;
    }
    if (create_fifo(r_pipename, (S_IWUSR | S_IRUSR | S_IWOTH | S_IROTH |
                                 S_IWGRP | S_IRGRP)) < 0) {
      unlink(w_pipename);
      erts_run_erl_log_error(NULL, 627,
                             "errno=%d\n"
                             "Cannot create FIFO %s for reading."
                             "\n",
                             errno, r_pipename);
      return 1;
    }
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<erts_run_erl_open_fifo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1354 <erts_run_erl_open_fifo+0x174>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1354 <erts_run_erl_open_fifo+0x174>
movl   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    128c <erts_run_erl_open_fifo+0xac>
mov    0x2d66(%rip),%rax
movslq (%rax),%rcx
mov    -0x10(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edi
mov    $0x243,%esi
lea    0xd87(%rip),%rdx
mov    $0x0,%al
call   1100 <erts_run_erl_log_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    1561 <erts_run_erl_open_fifo+0x381>
jmp    1291 <erts_run_erl_open_fifo+0xb1>
mov    -0x38(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1323 <erts_run_erl_open_fifo+0x143>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
lea    0xd72(%rip),%rdi
call   1070 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%edx
lea    0xd60(%rip),%rsi
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    131e <erts_run_erl_open_fifo+0x13e>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
lea    0xd3f(%rip),%rdi
call   1070 <strlen@plt>
mov    -0x60(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0x1,%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    1319 <erts_run_erl_open_fifo+0x139>
mov    -0x44(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    131e <erts_run_erl_open_fifo+0x13e>
jmp    1291 <erts_run_erl_open_fifo+0xb1>
mov    -0x38(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x10(%rbp),%rdi
mov    0x2c99(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%r8d
add    $0x1,%r8d
lea    0xcf0(%rip),%rdx
lea    0xcdd(%rip),%rcx
call   10a0 <strn_catf@plt>
jmp    1359 <erts_run_erl_open_fifo+0x179>
mov    -0x18(%rbp),%rdi
mov    0x2c6c(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1080 <strn_cpy@plt>
mov    -0x18(%rbp),%rdi
mov    0x2c56(%rip),%rax
mov    (%rax),%esi
lea    0xcbb(%rip),%rdx
call   10e0 <strn_cat@plt>
mov    -0x18(%rbp),%rdi
mov    0x2c4d(%rip),%rax
mov    (%rax),%esi
mov    0x2c0c(%rip),%rax
or     (%rax),%esi
mov    0x2beb(%rip),%rax
or     (%rax),%esi
mov    0x2c02(%rip),%rax
or     (%rax),%esi
mov    0x2c31(%rip),%rax
or     (%rax),%esi
mov    0x2bf8(%rip),%rax
or     (%rax),%esi
call   10c0 <create_fifo@plt>
cmp    $0x0,%rax
jge    1402 <erts_run_erl_open_fifo+0x222>
mov    0x2bf0(%rip),%rax
movslq (%rax),%rcx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edi
mov    $0x25a,%esi
lea    0xc52(%rip),%rdx
mov    $0x0,%al
call   1100 <erts_run_erl_log_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    1561 <erts_run_erl_open_fifo+0x381>
mov    -0x20(%rbp),%rdi
mov    0x2bc3(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1080 <strn_cpy@plt>
mov    -0x20(%rbp),%rdi
mov    0x2bad(%rip),%rax
mov    (%rax),%esi
lea    0xc42(%rip),%rdx
call   10e0 <strn_cat@plt>
mov    -0x20(%rbp),%rdi
mov    0x2b5c(%rip),%rax
mov    (%rax),%esi
mov    0x2b7b(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1030 <sf_open@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jl     14d2 <erts_run_erl_open_fifo+0x2f2>
mov    -0x2c(%rbp),%edi
call   10d0 <sf_close@plt>
cmpl   $0x0,-0x24(%rbp)
je     14a2 <erts_run_erl_open_fifo+0x2c2>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2b50(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%r8d
add    $0x1,%r8d
lea    0xba7(%rip),%rdx
lea    0xb94(%rip),%rcx
call   10a0 <strn_catf@plt>
jmp    1359 <erts_run_erl_open_fifo+0x179>
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x26d,%esi
lea    0xbbb(%rip),%rdx
mov    $0x0,%al
call   1100 <erts_run_erl_log_error@plt>
mov    -0x18(%rbp),%rdi
call   1040 <unlink@plt>
movl   $0x1,-0x4(%rbp)
jmp    1561 <erts_run_erl_open_fifo+0x381>
mov    -0x20(%rbp),%rdi
mov    0x2b03(%rip),%rax
mov    (%rax),%esi
mov    0x2ac2(%rip),%rax
or     (%rax),%esi
mov    0x2aa1(%rip),%rax
or     (%rax),%esi
mov    0x2ab8(%rip),%rax
or     (%rax),%esi
mov    0x2ae7(%rip),%rax
or     (%rax),%esi
mov    0x2aae(%rip),%rax
or     (%rax),%esi
call   10c0 <create_fifo@plt>
cmp    $0x0,%rax
jge    1555 <erts_run_erl_open_fifo+0x375>
mov    -0x18(%rbp),%rdi
call   1040 <unlink@plt>
mov    0x2a9d(%rip),%rax
movslq (%rax),%rcx
mov    -0x20(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edi
mov    $0x273,%esi
lea    0xb54(%rip),%rdx
mov    $0x0,%al
call   1100 <erts_run_erl_log_error@plt>
movl   $0x1,-0x4(%rbp)
jmp    1561 <erts_run_erl_open_fifo+0x381>
jmp    155a <erts_run_erl_open_fifo+0x37a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<erts_run_erl_open_fifo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x1,%r13b
xor    %r12d,%r12d
cmpb   $0x0,(%rdi)
je     1324 <erts_run_erl_open_fifo+0x144>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1324 <erts_run_erl_open_fifo+0x144>
mov    %rbx,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     12d2 <erts_run_erl_open_fifo+0xf2>
mov    %rax,%rbp
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     12f2 <erts_run_erl_open_fifo+0x112>
mov    %rax,%r13
xor    %r12d,%r12d
lea    0xddf(%rip),%rax
mov    %rbx,0x10(%rsp)
mov    %r15,0x8(%rsp)
jmp    1287 <erts_run_erl_open_fifo+0xa7>
nopl   0x0(%rax)
mov    %r14,%rbp
mov    %r15,%r14
mov    0x8(%rsp),%r15
mov    0x10(%rsp),%rbx
mov    %rbp,%rdi
call   10b0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
lea    0xda7(%rip),%rax
je     12f5 <erts_run_erl_open_fifo+0x115>
mov    %r14,%r15
mov    %rbp,%r14
mov    0x0(%r13),%rbp
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1260 <erts_run_erl_open_fifo+0x80>
mov    0x0(%r13),%rbp
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
lea    (%rax,%rbp,1),%rdi
add    $0x1,%rdi
call   10f0 <atoi@plt>
cmp    %r12d,%eax
cmovg  %eax,%r12d
jmp    1260 <erts_run_erl_open_fifo+0x80>
mov    0x2cef(%rip),%rax
movslq (%rax),%rcx
lea    0xd1d(%rip),%rdx
xor    %edi,%edi
mov    $0x243,%esi
mov    %rbx,%r8
jmp    1490 <erts_run_erl_open_fifo+0x2b0>
xor    %r12d,%r12d
mov    %rbp,%rdi
call   1090 <closedir@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%esi
lea    0x1(%r12),%r8d
lea    0xd26(%rip),%rdx
lea    0xd13(%rip),%rcx
mov    %rbx,%rdi
call   10a0 <strn_catf@plt>
xor    %r13d,%r13d
add    $0x2,%r12d
mov    0x2ca1(%rip),%rbp
nop
mov    0x0(%rbp),%esi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1080 <strn_cpy@plt>
mov    0x0(%rbp),%esi
mov    %r14,%rdi
lea    0xcf3(%rip),%rdx
call   10e0 <strn_cat@plt>
mov    0x2c51(%rip),%rax
mov    (%rax),%esi
mov    0x2c80(%rip),%rax
or     (%rax),%esi
mov    0x2c27(%rip),%rax
or     (%rax),%esi
mov    0x2c3e(%rip),%rax
or     (%rax),%esi
mov    0x2c6d(%rip),%rax
or     (%rax),%esi
mov    0x2c34(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
call   10c0 <create_fifo@plt>
test   %rax,%rax
js     1408 <erts_run_erl_open_fifo+0x228>
mov    0x0(%rbp),%esi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1080 <strn_cpy@plt>
mov    0x0(%rbp),%esi
mov    %r15,%rdi
lea    0xcc0(%rip),%rdx
call   10e0 <strn_cat@plt>
mov    0x2c06(%rip),%rax
mov    (%rax),%esi
mov    0x2bd5(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
xor    %edx,%edx
call   1030 <sf_open@plt>
test   %eax,%eax
js     1425 <erts_run_erl_open_fifo+0x245>
mov    %eax,%edi
call   10d0 <sf_close@plt>
test   %r13b,%r13b
jne    1499 <erts_run_erl_open_fifo+0x2b9>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
lea    0xc48(%rip),%rdx
lea    0xc35(%rip),%rcx
mov    %r12d,%r8d
call   10a0 <strn_catf@plt>
add    $0x1,%r12d
jmp    1330 <erts_run_erl_open_fifo+0x150>
mov    0x2bb9(%rip),%rax
movslq (%rax),%rcx
lea    0xc28(%rip),%rdx
xor    %edi,%edi
mov    $0x25a,%esi
mov    %r14,%r8
jmp    1490 <erts_run_erl_open_fifo+0x2b0>
mov    0x2b7c(%rip),%rax
mov    (%rax),%esi
mov    0x2bab(%rip),%rax
or     (%rax),%esi
mov    0x2b52(%rip),%rax
or     (%rax),%esi
mov    0x2b69(%rip),%rax
or     (%rax),%esi
mov    0x2b98(%rip),%rax
or     (%rax),%esi
mov    0x2b5f(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
call   10c0 <create_fifo@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jns    14be <erts_run_erl_open_fifo+0x2de>
mov    %r14,%rdi
call   1040 <unlink@plt>
mov    0x2b4c(%rip),%rax
movslq (%rax),%rcx
lea    0xc10(%rip),%rdx
xor    %edi,%edi
mov    $0x273,%esi
mov    %r15,%r8
xor    %eax,%eax
call   1100 <erts_run_erl_log_error@plt>
jmp    14b9 <erts_run_erl_open_fifo+0x2d9>
lea    0xbd1(%rip),%rdx
xor    %edi,%edi
mov    $0x26d,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1100 <erts_run_erl_log_error@plt>
mov    %r14,%rdi
call   1040 <unlink@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i64 }
@.str = [44 x i8] c"errno=%d\0ACan't access pipe directory '%s'.\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"erlang.pipe\00"
@BUFSIZ = global i32 0
@.str.2 = [6 x i8] c"%s.%d\00"
@.str.3 = [3 x i8] c".r\00"
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IWOTH = global i32 0
@S_IROTH = global i32 0
@S_IWGRP = global i32 0
@S_IRGRP = global i32 0
@.str.4 = [45 x i8] c"errno=%d\0ACannot create FIFO %s for writing.\0A\00"
@.str.5 = [3 x i8] c".w\00"
@O_WRONLY = global i32 0
@O_NDELAY = global i32 0
@.str.6 = [37 x i8] c"Erlang already running on pipe %s.\0A\0A\00"
@.str.7 = [45 x i8] c"errno=%d\0ACannot create FIFO %s for reading.\0A\00"
define i32 @erts_run_erl_open_fifo(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca %struct.dirent*
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 0, i32* %8
store i32 0, i32* %9
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %75
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 47
br i1 %27, label %28, label %75
28: ; preds = %18
store i32 1, i32* %8
%29 = load i8*, i8** %5
%30 = call i32* @opendir(i8* %29)
store i32* %30, i32** %11
%31 = load i32*, i32** %11
%32 = icmp ne i32* %31, null
br i1 %32, label %39, label %33
33: ; preds = %28
%34 = load i32, i32* @errno
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i8*
%37 = load i8*, i8** %5
%38 = call i32 (i32*, i32, i8*, i8*, ...) @erts_run_erl_log_error(i32* null, i32 579, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %36, i8* %37)
store i32 1, i32* %4
br label %161
39: ; preds = %28
br label %40
40: ; preds = %66, %39
%41 = load i32*, i32** %11
%42 = call %struct.dirent* @readdir(i32* %41)
store %struct.dirent* %42, %struct.dirent** %12
%43 = icmp ne %struct.dirent* %42, null
br i1 %43, label %44, label %67
44: ; preds = %40
%45 = load %struct.dirent*, %struct.dirent** %12
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i64, i64* %46
%48 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%49 = call i64 @strncmp(i64 %47, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %66
51: ; preds = %44
%52 = load %struct.dirent*, %struct.dirent** %12
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i64, i64* %53
%55 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%56 = sext i32 %55 to i64
%57 = add nsw i64 %54, %56
%58 = add nsw i64 %57, 1
%59 = call i32 @atoi(i64 %58)
store i32 %59, i32* %13
%60 = load i32, i32* %13
%61 = load i32, i32* %9
%62 = icmp sgt i32 %60, %61
br i1 %62, label %63, label %65
63: ; preds = %51
%64 = load i32, i32* %13
store i32 %64, i32* %9
br label %65
65: ; preds = %63, %51
br label %66
66: ; preds = %65, %44
br label %40
67: ; preds = %40
%68 = load i32*, i32** %11
%69 = call i32 @closedir(i32* %68)
%70 = load i8*, i8** %5
%71 = load i32, i32* @BUFSIZ
%72 = load i32, i32* %9
%73 = add nsw i32 %72, 1
%74 = call i32 @strn_catf(i8* %70, i32 %71, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %67, %18, %3
br label %76
76: ; preds = %123, %75
%77 = load i8*, i8** %6
%78 = load i32, i32* @BUFSIZ
%79 = load i8*, i8** %5
%80 = call i32 @strn_cpy(i8* %77, i32 %78, i8* %79)
%81 = load i8*, i8** %6
%82 = load i32, i32* @BUFSIZ
%83 = call i32 @strn_cat(i8* %81, i32 %82, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%84 = load i8*, i8** %6
%85 = load i32, i32* @S_IWUSR
%86 = load i32, i32* @S_IRUSR
%87 = or i32 %85, %86
%88 = load i32, i32* @S_IWOTH
%89 = or i32 %87, %88
%90 = load i32, i32* @S_IROTH
%91 = or i32 %89, %90
%92 = load i32, i32* @S_IWGRP
%93 = or i32 %91, %92
%94 = load i32, i32* @S_IRGRP
%95 = or i32 %93, %94
%96 = call i64 @create_fifo(i8* %84, i32 %95)
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %104
98: ; preds = %76
%99 = load i32, i32* @errno
%100 = sext i32 %99 to i64
%101 = inttoptr i64 %100 to i8*
%102 = load i8*, i8** %6
%103 = call i32 (i32*, i32, i8*, i8*, ...) @erts_run_erl_log_error(i32* null, i32 602, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %101, i8* %102)
store i32 1, i32* %4
br label %161
104: ; preds = %76
%105 = load i8*, i8** %7
%106 = load i32, i32* @BUFSIZ
%107 = load i8*, i8** %5
%108 = call i32 @strn_cpy(i8* %105, i32 %106, i8* %107)
%109 = load i8*, i8** %7
%110 = load i32, i32* @BUFSIZ
%111 = call i32 @strn_cat(i8* %109, i32 %110, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%112 = load i8*, i8** %7
%113 = load i32, i32* @O_WRONLY
%114 = load i32, i32* @O_NDELAY
%115 = or i32 %113, %114
%116 = call i32 @sf_open(i8* %112, i32 %115, i32 0)
store i32 %116, i32* %10
%117 = icmp sge i32 %116, 0
br i1 %117, label %118, label %136
118: ; preds = %104
%119 = load i32, i32* %10
%120 = call i32 @sf_close(i32 %119)
%121 = load i32, i32* %8
%122 = icmp ne i32 %121, 0
br i1 %122, label %123, label %131
123: ; preds = %118
%124 = load i32, i32* %9
%125 = add nsw i32 %124, 1
store i32 %125, i32* %9
%126 = load i8*, i8** %5
%127 = load i32, i32* @BUFSIZ
%128 = load i32, i32* %9
%129 = add nsw i32 %128, 1
%130 = call i32 @strn_catf(i8* %126, i32 %127, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %129)
br label %76
131: ; preds = %118
%132 = load i8*, i8** %5
%133 = call i32 (i32*, i32, i8*, i8*, ...) @erts_run_erl_log_error(i32* null, i32 621, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i8* %132)
%134 = load i8*, i8** %6
%135 = call i32 @unlink(i8* %134)
store i32 1, i32* %4
br label %161
136: ; preds = %104
%137 = load i8*, i8** %7
%138 = load i32, i32* @S_IWUSR
%139 = load i32, i32* @S_IRUSR
%140 = or i32 %138, %139
%141 = load i32, i32* @S_IWOTH
%142 = or i32 %140, %141
%143 = load i32, i32* @S_IROTH
%144 = or i32 %142, %143
%145 = load i32, i32* @S_IWGRP
%146 = or i32 %144, %145
%147 = load i32, i32* @S_IRGRP
%148 = or i32 %146, %147
%149 = call i64 @create_fifo(i8* %137, i32 %148)
%150 = icmp slt i64 %149, 0
br i1 %150, label %151, label %159
151: ; preds = %136
%152 = load i8*, i8** %6
%153 = call i32 @unlink(i8* %152)
%154 = load i32, i32* @errno
%155 = sext i32 %154 to i64
%156 = inttoptr i64 %155 to i8*
%157 = load i8*, i8** %7
%158 = call i32 (i32*, i32, i8*, i8*, ...) @erts_run_erl_log_error(i32* null, i32 627, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i8* %156, i8* %157)
store i32 1, i32* %4
br label %161
159: ; preds = %136
br label %160
160: ; preds = %159
store i32 0, i32* %4
br label %161
161: ; preds = %160, %151, %131, %98, %33
%162 = load i32, i32* %4
ret i32 %162
}

LLVM IR (-O2):
%struct.dirent = type { i64 }
@.str = [44 x i8] c"errno=%d\0ACan't access pipe directory '%s'.\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"erlang.pipe\00"
@BUFSIZ = global i32 0
@.str.2 = [6 x i8] c"%s.%d\00"
@.str.3 = [3 x i8] c".r\00"
@S_IWUSR = global i32 0
@S_IRUSR = global i32 0
@S_IWOTH = global i32 0
@S_IROTH = global i32 0
@S_IWGRP = global i32 0
@S_IRGRP = global i32 0
@.str.4 = [45 x i8] c"errno=%d\0ACannot create FIFO %s for writing.\0A\00"
@.str.5 = [3 x i8] c".w\00"
@O_WRONLY = global i32 0
@O_NDELAY = global i32 0
@.str.6 = [37 x i8] c"Erlang already running on pipe %s.\0A\0A\00"
@.str.7 = [45 x i8] c"errno=%d\0ACannot create FIFO %s for reading.\0A\00"
define i32 @erts_run_erl_open_fifo(i8* %0, i8* %1, i8* %2) {
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %51, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 47
br i1 %12, label %13, label %51
13: ; preds = %6
%14 = tail call i32* @opendir(i8* %0)
%15 = icmp eq i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = tail call %struct.dirent* @readdir(i32* %14)
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %45, label %24
19: ; preds = %13
%20 = load i32, i32* @errno
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
%23 = tail call i32 (i32*, i32, i8*, i8*, ...) @erts_run_erl_log_error(i32* null, i32 579, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %0)
br label %118
24: ; preds = %16, %41
%25 = phi %struct.dirent* [ %43, %41 ], [ %17, %16 ]
%26 = phi i32 [ %42, %41 ], [ 0, %16 ]
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i64 0, i32 0
%28 = load i64, i64* %27
%29 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i64 @strncmp(i64 %28, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %24
%33 = load i64, i64* %27
%34 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%35 = sext i32 %34 to i64
%36 = add i64 %33, 1
%37 = add i64 %36, %35
%38 = tail call i32 @atoi(i64 %37)
%39 = icmp sgt i32 %38, %26
%40 = select i1 %39, i32 %38, i32 %26
br label %41
41: ; preds = %32, %24
%42 = phi i32 [ %40, %32 ], [ %26, %24 ]
%43 = tail call %struct.dirent* @readdir(i32* %14)
%44 = icmp eq %struct.dirent* %43, null
br i1 %44, label %45, label %24
45: ; preds = %41, %16
%46 = phi i32 [ 0, %16 ], [ %42, %41 ]
%47 = tail call i32 @closedir(i32* %14)
%48 = load i32, i32* @BUFSIZ
%49 = add nsw i32 %46, 1
%50 = tail call i32 @strn_catf(i8* %0, i32 %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %45, %6, %3
%52 = phi i32 [ %46, %45 ], [ 0, %6 ], [ 0, %3 ]
%53 = phi i1 [ false, %45 ], [ true, %6 ], [ true, %3 ]
br label %54
54: ; preds = %90, %51
%55 = phi i32 [ %52, %51 ], [ %91, %90 ]
%56 = load i32, i32* @BUFSIZ
%57 = tail call i32 @strn_cpy(i8* %1, i32 %56, i8* %0)
%58 = load i32, i32* @BUFSIZ
%59 = tail call i32 @strn_cat(i8* %1, i32 %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%60 = load i32, i32* @S_IWUSR
%61 = load i32, i32* @S_IRUSR
%62 = or i32 %61, %60
%63 = load i32, i32* @S_IWOTH
%64 = or i32 %62, %63
%65 = load i32, i32* @S_IROTH
%66 = or i32 %64, %65
%67 = load i32, i32* @S_IWGRP
%68 = or i32 %66, %67
%69 = load i32, i32* @S_IRGRP
%70 = or i32 %68, %69
%71 = tail call i64 @create_fifo(i8* %1, i32 %70)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %78
73: ; preds = %54
%74 = load i32, i32* @errno
%75 = sext i32 %74 to i64
%76 = inttoptr i64 %75 to i8*
%77 = tail call i32 (i32*, i32, i8*, i8*, ...) @erts_run_erl_log_error(i32* null, i32 602, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %76, i8* %1)
br label %118
78: ; preds = %54
%79 = load i32, i32* @BUFSIZ
%80 = tail call i32 @strn_cpy(i8* %2, i32 %79, i8* %0)
%81 = load i32, i32* @BUFSIZ
%82 = tail call i32 @strn_cat(i8* %2, i32 %81, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%83 = load i32, i32* @O_WRONLY
%84 = load i32, i32* @O_NDELAY
%85 = or i32 %84, %83
%86 = tail call i32 @sf_open(i8* %2, i32 %85, i32 0)
%87 = icmp sgt i32 %86, -1
br i1 %87, label %88, label %98
88: ; preds = %78
%89 = tail call i32 @sf_close(i32 %86)
br i1 %53, label %95, label %90
90: ; preds = %88
%91 = add nsw i32 %55, 1
%92 = load i32, i32* @BUFSIZ
%93 = add nsw i32 %55, 2
%94 = tail call i32 @strn_catf(i8* %0, i32 %92, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %93)
br label %54
95: ; preds = %88
%96 = tail call i32 (i32*, i32, i8*, i8*, ...) @erts_run_erl_log_error(i32* null, i32 621, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i8* %0)
%97 = tail call i32 @unlink(i8* %1)
br label %118
98: ; preds = %78
%99 = load i32, i32* @S_IWUSR
%100 = load i32, i32* @S_IRUSR
%101 = or i32 %100, %99
%102 = load i32, i32* @S_IWOTH
%103 = or i32 %101, %102
%104 = load i32, i32* @S_IROTH
%105 = or i32 %103, %104
%106 = load i32, i32* @S_IWGRP
%107 = or i32 %105, %106
%108 = load i32, i32* @S_IRGRP
%109 = or i32 %107, %108
%110 = tail call i64 @create_fifo(i8* %2, i32 %109)
%111 = icmp slt i64 %110, 0
br i1 %111, label %112, label %118
112: ; preds = %98
%113 = tail call i32 @unlink(i8* %1)
%114 = load i32, i32* @errno
%115 = sext i32 %114 to i64
%116 = inttoptr i64 %115 to i8*
%117 = tail call i32 (i32*, i32, i8*, i8*, ...) @erts_run_erl_log_error(i32* null, i32 627, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i8* %116, i8* %2)
br label %118
118: ; preds = %19, %98, %112, %95, %73
%119 = phi i32 [ 1, %73 ], [ 1, %95 ], [ 1, %112 ], [ 0, %98 ], [ 1, %19 ]
ret i32 %119
}