#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*/ path;

/* Variables and functions */
scalar_t__ ENOSYS;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int PATH_MAX;
int PROT_EXEC;
int PROT_READ;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ cctools_debug(long long, char *, char *, ...);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int fchmod(int, int /*<<< orphan*/);
int ftruncate(int, size_t);
size_t getpagesize();
int mkstemp(char *);
void *mmap(int /*<<< orphan*/ *, size_t, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, size_t);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
char *strerror(scalar_t__);
int unlink(char *);
int memfdexe(const char *name, const char *extradir) {
  int fd;
  errno = ENOSYS;
  fd = -1;
  if (fd == -1 && errno == ENOSYS) {
    int i;
    const char *dirs[] = {"/dev/shm", "/tmp", "/var/tmp", extradir, NULL};
    size_t pagesize = getpagesize();
    for (i = 0; dirs[i]; i++) {
      char path[PATH_MAX];
      snprintf(path, sizeof(path), "%s/%s.XXXXXX", dirs[i], name);
      cctools_debug((1LL << 3), "trying to create memfdexe '%s'", path);
      fd = mkstemp(path);
      if (fd >= 0) {
        if (unlink(path) == -1) {
          cctools_debug((1LL << 3), "could not unlink memfdexe '%s': %s", path,
                        strerror(errno));
        }
        if (fchmod(fd, S_IRWXU) == -1) {
          cctools_debug((1LL << 3), "could not set permissions on memfdexe: %s",
                        strerror(errno));
          close(fd);
          continue;
        }
        if (ftruncate(fd, pagesize) == -1) {
          cctools_debug((1LL << 3), "could not grow memfdexe: %s",
                        strerror(errno));
          close(fd);
          continue;
        }
        void *addr =
            mmap(NULL, pagesize, PROT_READ | PROT_EXEC, MAP_SHARED, fd, 0);
        if (addr == MAP_FAILED) {
          cctools_debug((1LL << 3), "failed executable mapping: %s",
                        strerror(errno));
          close(fd);
          continue;
        }
        munmap(addr, pagesize);
        ftruncate(fd, 0);
        break;
      } else {
        cctools_debug((1LL << 3), "could not create memfdexe: %s",
                      strerror(errno));
      }
    }
  }
  return fd;
}


x86 assembly (clang, -O0):
<memfdexe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%rcx
mov    0x2ddc(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    14be <memfdexe+0x30e>
mov    0x2dc1(%rip),%rax
mov    (%rax),%rax
mov    0x2dcf(%rip),%rcx
cmp    (%rcx),%rax
jne    14be <memfdexe+0x30e>
lea    0xdf7(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xdf9(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xdea(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   10c0 <getpagesize@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmpq   $0x0,-0x40(%rbp,%rax,8)
je     14b9 <memfdexe+0x309>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x58(%rbp)
mov    %eax,%esi
movslq -0x18(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rcx
mov    -0x8(%rbp),%r8
lea    0xd7b(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x70(%rbp),%rdx
mov    $0x8,%edi
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1080 <cctools_debug@plt>
mov    -0x70(%rbp),%rdi
call   1090 <mkstemp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     144a <memfdexe+0x29a>
mov    -0x70(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    1304 <memfdexe+0x154>
mov    0x2cce(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
mov    $0x8,%edi
lea    0xd41(%rip),%rsi
mov    $0x0,%al
call   1080 <cctools_debug@plt>
mov    -0x14(%rbp),%edi
mov    0x2cc2(%rip),%rax
mov    (%rax),%esi
call   10b0 <fchmod@plt>
cmp    $0xffffffff,%eax
jne    1357 <memfdexe+0x1a7>
mov    0x2c8b(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    %rax,%rdx
mov    $0x8,%edi
lea    0xd25(%rip),%rsi
mov    $0x0,%al
call   1080 <cctools_debug@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x4,-0x5c(%rbp)
jmp    1476 <memfdexe+0x2c6>
mov    -0x14(%rbp),%edi
mov    -0x48(%rbp),%rsi
call   1060 <ftruncate@plt>
cmp    $0xffffffff,%eax
jne    13a5 <memfdexe+0x1f5>
mov    0x2c3d(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    %rax,%rdx
mov    $0x8,%edi
lea    0xd01(%rip),%rsi
mov    $0x0,%al
call   1080 <cctools_debug@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x4,-0x5c(%rbp)
jmp    1476 <memfdexe+0x2c6>
mov    -0x48(%rbp),%rsi
mov    0x2c48(%rip),%rax
mov    (%rax),%edx
mov    0x2c07(%rip),%rax
or     (%rax),%edx
mov    0x2c1e(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    0x2bc5(%rip),%rcx
cmp    (%rcx),%rax
jne    1425 <memfdexe+0x275>
mov    0x2bbd(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    %rax,%rdx
mov    $0x8,%edi
lea    0xc9d(%rip),%rsi
mov    $0x0,%al
call   1080 <cctools_debug@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x4,-0x5c(%rbp)
jmp    1476 <memfdexe+0x2c6>
mov    -0x68(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10a0 <munmap@plt>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <ftruncate@plt>
movl   $0x2,-0x5c(%rbp)
jmp    1476 <memfdexe+0x2c6>
mov    0x2b5f(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    %rax,%rdx
mov    $0x8,%edi
lea    0xc5d(%rip),%rsi
mov    $0x0,%al
call   1080 <cctools_debug@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    -0x5c(%rbp),%eax
mov    %eax,-0x74(%rbp)
test   %eax,%eax
je     14a6 <memfdexe+0x2f6>
jmp    1490 <memfdexe+0x2e0>
mov    -0x74(%rbp),%eax
sub    $0x2,%eax
je     14b9 <memfdexe+0x309>
jmp    14a1 <memfdexe+0x2f1>
jmp    14ab <memfdexe+0x2fb>
jmp    14ab <memfdexe+0x2fb>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1245 <memfdexe+0x95>
jmp    14be <memfdexe+0x30e>
mov    -0x14(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memfdexe>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,-0x38(%rbp)
mov    0x2dfc(%rip),%rax
mov    (%rax),%rax
mov    0x2dda(%rip),%rcx
mov    %rax,(%rcx)
lea    0xe20(%rip),%r15
mov    %r15,-0x60(%rbp)
lea    -0x58(%rbp),%r14
lea    0xe1e(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe0f(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    %rsi,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
xor    %eax,%eax
call   10c0 <getpagesize@plt>
mov    %rax,-0x30(%rbp)
jmp    1263 <memfdexe+0xb3>
nopw   0x0(%rax,%rax,1)
mov    0x2d89(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    $0x8,%edi
lea    0xe26(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <cctools_debug@plt>
mov    %r13d,%edi
call   1070 <close@plt>
mov    %r15,%rbx
mov    %rbx,%rsp
mov    (%r14),%r15
add    $0x8,%r14
test   %r15,%r15
je     13f2 <memfdexe+0x242>
mov    %rsp,%rbx
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r12
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
lea    0xd85(%rip),%rdx
mov    %r15,%rcx
mov    -0x38(%rbp),%r8
call   1050 <snprintf@plt>
mov    $0x8,%edi
lea    0xd7a(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <cctools_debug@plt>
mov    %r12,%rdi
call   1090 <mkstemp@plt>
mov    %eax,%r13d
test   %eax,%eax
js     1390 <memfdexe+0x1e0>
mov    %rbx,%r15
mov    %r12,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    12fa <memfdexe+0x14a>
mov    0x2cd7(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    $0x8,%edi
lea    0xd51(%rip),%rsi
mov    %r12,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <cctools_debug@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
call   10b0 <fchmod@plt>
cmp    $0xffffffff,%eax
mov    -0x30(%rbp),%rbx
je     1220 <memfdexe+0x70>
mov    %r13d,%edi
mov    %rbx,%rsi
call   1060 <ftruncate@plt>
cmp    $0xffffffff,%eax
je     13ba <memfdexe+0x20a>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edx
mov    0x2cbc(%rip),%rax
or     (%rax),%edx
mov    0x2c9b(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    %r13d,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    0x2c4a(%rip),%rcx
cmp    (%rcx),%rax
jne    13da <memfdexe+0x22a>
mov    0x2c46(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    $0x8,%edi
lea    0xd29(%rip),%rsi
jmp    123b <memfdexe+0x8b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x2c19(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    $0x8,%edi
lea    0xd1a(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <cctools_debug@plt>
jmp    1250 <memfdexe+0xa0>
mov    0x2bef(%rip),%rax
mov    (%rax),%rdi
call   10d0 <strerror@plt>
mov    $0x8,%edi
lea    0xcb6(%rip),%rsi
jmp    123b <memfdexe+0x8b>
mov    %rax,%rdi
mov    %rbx,%rsi
call   10a0 <munmap@plt>
mov    %r13d,%edi
xor    %esi,%esi
call   1060 <ftruncate@plt>
mov    %r15,%rsp
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ENOSYS = global i64 0
@errno = global i64 0
@.str = [9 x i8] c"/dev/shm\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [9 x i8] c"/var/tmp\00"
@PATH_MAX = global i32 0
@.str.3 = [13 x i8] c"%s/%s.XXXXXX\00"
@.str.4 = [31 x i8] c"trying to create memfdexe '%s'\00"
@.str.5 = [35 x i8] c"could not unlink memfdexe '%s': %s\00"
@S_IRWXU = global i32 0
@.str.6 = [42 x i8] c"could not set permissions on memfdexe: %s\00"
@.str.7 = [28 x i8] c"could not grow memfdexe: %s\00"
@PROT_READ = global i32 0
@PROT_EXEC = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.8 = [30 x i8] c"failed executable mapping: %s\00"
@.str.9 = [30 x i8] c"could not create memfdexe: %s\00"
define i32 @memfdexe(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [5 x i8*]
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%13 = load i64, i64* @ENOSYS
store i64 %13, i64* @errno
store i32 -1, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %115
16: ; preds = %2
%17 = load i64, i64* @errno
%18 = load i64, i64* @ENOSYS
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %115
20: ; preds = %16
%21 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %22
%23 = getelementptr inbounds i8*, i8** %22, i64 1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %23
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %4
store i8* %25, i8** %24
%26 = getelementptr inbounds i8*, i8** %24, i64 1
store i8* null, i8** %26
%27 = call i64 (...) @getpagesize()
store i64 %27, i64* %8
store i32 0, i32* %6
br label %28
28: ; preds = %111, %20
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %114
34: ; preds = %28
%35 = load i32, i32* @PATH_MAX
%36 = zext i32 %35 to i64
%37 = call i8* @llvm.stacksave()
store i8* %37, i8** %9
%38 = alloca i8, i64 %36
store i64 %36, i64* %10
%39 = trunc i64 %36 to i32
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i64 0, i64 %41
%43 = load i8*, i8** %42
%44 = load i8*, i8** %3
%45 = call i32 @snprintf(i8* %38, i32 %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %43, i8* %44)
%46 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %38)
%47 = call i32 @mkstemp(i8* %38)
store i32 %47, i32* %5
%48 = load i32, i32* %5
%49 = icmp sge i32 %48, 0
br i1 %49, label %50, label %102
50: ; preds = %34
%51 = call i32 @unlink(i8* %38)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = load i64, i64* @errno
%55 = call i8* @strerror(i64 %54)
%56 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %38, i8* %55)
br label %57
57: ; preds = %53, %50
%58 = load i32, i32* %5
%59 = load i32, i32* @S_IRWXU
%60 = call i32 @fchmod(i32 %58, i32 %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %68
62: ; preds = %57
%63 = load i64, i64* @errno
%64 = call i8* @strerror(i64 %63)
%65 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %64)
%66 = load i32, i32* %5
%67 = call i32 @close(i32 %66)
store i32 4, i32* %11
br label %107
68: ; preds = %57
%69 = load i32, i32* %5
%70 = load i64, i64* %8
%71 = call i32 @ftruncate(i32 %69, i64 %70)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %79
73: ; preds = %68
%74 = load i64, i64* @errno
%75 = call i8* @strerror(i64 %74)
%76 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %75)
%77 = load i32, i32* %5
%78 = call i32 @close(i32 %77)
store i32 4, i32* %11
br label %107
79: ; preds = %68
%80 = load i64, i64* %8
%81 = load i32, i32* @PROT_READ
%82 = load i32, i32* @PROT_EXEC
%83 = or i32 %81, %82
%84 = load i32, i32* @MAP_SHARED
%85 = load i32, i32* %5
%86 = call i8* @mmap(i32* null, i64 %80, i32 %83, i32 %84, i32 %85, i32 0)
store i8* %86, i8** %12
%87 = load i8*, i8** %12
%88 = load i8*, i8** @MAP_FAILED
%89 = icmp eq i8* %87, %88
br i1 %89, label %90, label %96
90: ; preds = %79
%91 = load i64, i64* @errno
%92 = call i8* @strerror(i64 %91)
%93 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %92)
%94 = load i32, i32* %5
%95 = call i32 @close(i32 %94)
store i32 4, i32* %11
br label %107
96: ; preds = %79
%97 = load i8*, i8** %12
%98 = load i64, i64* %8
%99 = call i32 @munmap(i8* %97, i64 %98)
%100 = load i32, i32* %5
%101 = call i32 @ftruncate(i32 %100, i64 0)
store i32 2, i32* %11
br label %107
102: ; preds = %34
%103 = load i64, i64* @errno
%104 = call i8* @strerror(i64 %103)
%105 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %104)
br label %106
106: ; preds = %102
store i32 0, i32* %11
br label %107
107: ; preds = %106, %96, %90, %73, %62
%108 = load i8*, i8** %9
%109 = load i32, i32* %11
switch i32 %109, label %117 [
i32 0, label %110
i32 4, label %111
i32 2, label %114
]
110: ; preds = %107
br label %111
111: ; preds = %110, %107
%112 = load i32, i32* %6
%113 = add nsw i32 %112, 1
store i32 %113, i32* %6
br label %28
114: ; preds = %107, %28
br label %115
115: ; preds = %114, %16, %2
%116 = load i32, i32* %5
ret i32 %116
117: ; preds = %107
unreachable
}

LLVM IR (-O2):
@ENOSYS = global i64 0
@errno = global i64 0
@.str = [9 x i8] c"/dev/shm\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [9 x i8] c"/var/tmp\00"
@PATH_MAX = global i32 0
@.str.3 = [13 x i8] c"%s/%s.XXXXXX\00"
@.str.4 = [31 x i8] c"trying to create memfdexe '%s'\00"
@.str.5 = [35 x i8] c"could not unlink memfdexe '%s': %s\00"
@S_IRWXU = global i32 0
@.str.6 = [42 x i8] c"could not set permissions on memfdexe: %s\00"
@.str.7 = [28 x i8] c"could not grow memfdexe: %s\00"
@PROT_READ = global i32 0
@PROT_EXEC = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.8 = [30 x i8] c"failed executable mapping: %s\00"
@.str.9 = [30 x i8] c"could not create memfdexe: %s\00"
define i32 @memfdexe(i8* %0, i8* %1) {
%3 = alloca [5 x i8*]
%4 = load i64, i64* @ENOSYS
store i64 %4, i64* @errno
%5 = bitcast [5 x i8*]* %3 to i8*
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
store i8* %1, i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 4
store i8* null, i8** %10
%11 = tail call i64 (...) @getpagesize()
br label %12
12: ; preds = %2, %67
%13 = phi i64 [ 0, %2 ], [ %68, %67 ]
%14 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %2 ], [ %70, %67 ]
%15 = load i32, i32* @PATH_MAX
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
%18 = alloca i8, i64 %16
%19 = call i32 @snprintf(i8* %18, i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %14, i8* %0)
%20 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%21 = call i32 @mkstemp(i8* %18)
%22 = icmp sgt i32 %21, -1
br i1 %22, label %23, label %60
23: ; preds = %12
%24 = call i32 @unlink(i8* %18)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i64, i64* @errno
%28 = call i8* @strerror(i64 %27)
%29 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* %18, i8* %28)
br label %30
30: ; preds = %26, %23
%31 = load i32, i32* @S_IRWXU
%32 = call i32 @fchmod(i32 %21, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i64, i64* @errno
%36 = call i8* @strerror(i64 %35)
%37 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %36)
%38 = call i32 @close(i32 %21)
br label %67
39: ; preds = %30
%40 = call i32 @ftruncate(i32 %21, i64 %11)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i64, i64* @errno
%44 = call i8* @strerror(i64 %43)
%45 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %44)
%46 = call i32 @close(i32 %21)
br label %67
47: ; preds = %39
%48 = load i32, i32* @PROT_READ
%49 = load i32, i32* @PROT_EXEC
%50 = or i32 %49, %48
%51 = load i32, i32* @MAP_SHARED
%52 = call i8* @mmap(i32* null, i64 %11, i32 %50, i32 %51, i32 %21, i32 0)
%53 = load i8*, i8** @MAP_FAILED
%54 = icmp eq i8* %52, %53
br i1 %54, label %55, label %64
55: ; preds = %47
%56 = load i64, i64* @errno
%57 = call i8* @strerror(i64 %56)
%58 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i8* %57)
%59 = call i32 @close(i32 %21)
br label %67
60: ; preds = %12
%61 = load i64, i64* @errno
%62 = call i8* @strerror(i64 %61)
%63 = call i32 (i64, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.9, i64 0, i64 0), i8* %62)
br label %67
64: ; preds = %47
%65 = call i32 @munmap(i8* %52, i64 %11)
%66 = call i32 @ftruncate(i32 %21, i64 0)
br label %72
67: ; preds = %34, %42, %60, %55
%68 = add nuw i64 %13, 1
%69 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 %68
%70 = load i8*, i8** %69
%71 = icmp eq i8* %70, null
br i1 %71, label %72, label %12
72: ; preds = %67, %64
ret i32 %21
}