#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 stat {
  int st_mode;
};

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ O_RDONLY;
scalar_t__ _sndio_issetugid();
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
scalar_t__ fstat(int, struct stat *);
char *getenv(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int mkstemp(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ random_bytes(unsigned char *, int);
int read(int, unsigned char *, int);
scalar_t__ rename(char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ unlink(char *);
scalar_t__ write(int, unsigned char *, int);
int aucat_mkcookie(unsigned char *cookie) {
  struct stat sb;
  char *home, *path = NULL, *tmp = NULL;
  size_t home_len, path_len;
  int fd, len;
  path_len = 0xdeadbeef;
  home = _sndio_issetugid() ? NULL : getenv("HOME");
  if (home == NULL)
    goto bad_gen;
  home_len = strlen(home);
  path = malloc(home_len + sizeof("/.aucat_cookie"));
  if (path == NULL)
    goto bad_gen;
  memcpy(path, home, home_len);
  memcpy(path + home_len, "/.aucat_cookie", sizeof("/.aucat_cookie"));
  path_len = home_len + sizeof("/.aucat_cookie") - 1;
  fd = open(path, O_RDONLY);
  if (fd < 0) {
    if (errno != ENOENT)
      do {
      } while (0);
    goto bad_gen;
  }
  if (fstat(fd, &sb) < 0) {
    do {
    } while (0);
    goto bad_close;
  }
  if (sb.st_mode & 0077) {
    do {
    } while (0);
    goto bad_close;
  }
  len = read(fd, cookie, 16);
  if (len < 0) {
    do {
    } while (0);
    goto bad_close;
  }
  if (len != 16) {
    do {
    } while (0);
    goto bad_close;
  }
  close(fd);
  goto done;
bad_close:
  close(fd);
bad_gen:
  if (!random_bytes(cookie, 16)) {
    if (path)
      free(path);
    return 0;
  }
  if (home == NULL)
    goto done;
  tmp = malloc(path_len + sizeof(".XXXXXXXX"));
  if (tmp == NULL)
    goto done;
  memcpy(tmp, path, path_len);
  memcpy(tmp + path_len, ".XXXXXXXX", sizeof(".XXXXXXXX"));
  fd = mkstemp(tmp);
  if (fd < 0) {
    do {
    } while (0);
    goto done;
  }
  if (write(fd, cookie, 16) < 0) {
    do {
    } while (0);
    unlink(tmp);
    close(fd);
    goto done;
  }
  close(fd);
  if (rename(tmp, path) < 0) {
    do {
    } while (0);
    unlink(tmp);
  }
done:
  free(tmp);
  free(path);
  return 1;
}


x86 assembly (clang, -O0):
<aucat_mkcookie>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    $0xdeadbeef,%eax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1090 <_sndio_issetugid@plt>
cmp    $0x0,%rax
je     1231 <aucat_mkcookie+0x41>
xor    %eax,%eax
mov    %rax,-0x50(%rbp)
jmp    1241 <aucat_mkcookie+0x51>
lea    0xdc8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1259 <aucat_mkcookie+0x69>
jmp    13b0 <aucat_mkcookie+0x1c0>
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0xf,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1289 <aucat_mkcookie+0x99>
jmp    13b0 <aucat_mkcookie+0x1c0>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
call   10b0 <memcpy@plt>
mov    -0x28(%rbp),%rdi
add    -0x38(%rbp),%rdi
lea    0xd5a(%rip),%rsi
mov    $0xf,%edx
call   10b0 <memcpy@plt>
mov    -0x38(%rbp),%rax
add    $0xf,%rax
sub    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d18(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1312 <aucat_mkcookie+0x122>
mov    0x2ced(%rip),%rax
mov    (%rax),%rax
mov    0x2cd3(%rip),%rcx
cmp    (%rcx),%rax
je     130d <aucat_mkcookie+0x11d>
jmp    1303 <aucat_mkcookie+0x113>
jmp    1308 <aucat_mkcookie+0x118>
jmp    130d <aucat_mkcookie+0x11d>
jmp    13b0 <aucat_mkcookie+0x1c0>
mov    -0x44(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1110 <fstat@plt>
cmp    $0x0,%rax
jge    1337 <aucat_mkcookie+0x147>
jmp    132d <aucat_mkcookie+0x13d>
jmp    1332 <aucat_mkcookie+0x142>
jmp    13a8 <aucat_mkcookie+0x1b8>
mov    -0x18(%rbp),%eax
and    $0x3f,%eax
cmp    $0x0,%eax
je     1355 <aucat_mkcookie+0x165>
jmp    134b <aucat_mkcookie+0x15b>
jmp    1350 <aucat_mkcookie+0x160>
jmp    13a8 <aucat_mkcookie+0x1b8>
mov    -0x44(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   10a0 <read@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    1382 <aucat_mkcookie+0x192>
jmp    1378 <aucat_mkcookie+0x188>
jmp    137d <aucat_mkcookie+0x18d>
jmp    13a8 <aucat_mkcookie+0x1b8>
cmpl   $0x10,-0x48(%rbp)
je     139b <aucat_mkcookie+0x1ab>
jmp    1391 <aucat_mkcookie+0x1a1>
jmp    1396 <aucat_mkcookie+0x1a6>
jmp    13a8 <aucat_mkcookie+0x1b8>
mov    -0x44(%rbp),%edi
call   1080 <close@plt>
jmp    14dd <aucat_mkcookie+0x2ed>
mov    -0x44(%rbp),%edi
call   1080 <close@plt>
mov    -0x10(%rbp),%rdi
mov    $0x10,%esi
call   1100 <random_bytes@plt>
cmp    $0x0,%eax
jne    13e7 <aucat_mkcookie+0x1f7>
cmpq   $0x0,-0x28(%rbp)
je     13db <aucat_mkcookie+0x1eb>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    14f6 <aucat_mkcookie+0x306>
cmpq   $0x0,-0x20(%rbp)
jne    13f7 <aucat_mkcookie+0x207>
jmp    14dd <aucat_mkcookie+0x2ed>
mov    -0x40(%rbp),%rax
add    $0xa,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    141a <aucat_mkcookie+0x22a>
jmp    14dd <aucat_mkcookie+0x2ed>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rax
mov    %eax,%edx
call   10b0 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    -0x40(%rbp),%rdi
lea    0xbd8(%rip),%rsi
mov    $0xa,%edx
call   10b0 <memcpy@plt>
mov    -0x30(%rbp),%rdi
call   10d0 <mkstemp@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    146b <aucat_mkcookie+0x27b>
jmp    1461 <aucat_mkcookie+0x271>
jmp    1466 <aucat_mkcookie+0x276>
jmp    14dd <aucat_mkcookie+0x2ed>
mov    -0x44(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1060 <write@plt>
cmp    $0x0,%rax
jge    14a6 <aucat_mkcookie+0x2b6>
jmp    148b <aucat_mkcookie+0x29b>
jmp    1490 <aucat_mkcookie+0x2a0>
mov    -0x30(%rbp),%rdi
call   1050 <unlink@plt>
mov    -0x44(%rbp),%edi
call   1080 <close@plt>
jmp    14dd <aucat_mkcookie+0x2ed>
mov    -0x44(%rbp),%edi
call   1080 <close@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10f0 <rename@plt>
cmp    $0x0,%rax
jge    14d8 <aucat_mkcookie+0x2e8>
jmp    14ca <aucat_mkcookie+0x2da>
jmp    14cf <aucat_mkcookie+0x2df>
mov    -0x30(%rbp),%rdi
call   1050 <unlink@plt>
jmp    14dd <aucat_mkcookie+0x2ed>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aucat_mkcookie>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <_sndio_issetugid@plt>
test   %rax,%rax
je     1246 <aucat_mkcookie+0x56>
mov    %r15,%rdi
mov    $0x10,%esi
call   1100 <random_bytes@plt>
test   %eax,%eax
je     1235 <aucat_mkcookie+0x45>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb3(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12f2 <aucat_mkcookie+0x102>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <strlen@plt>
mov    %rax,%r12
lea    0xf(%rax),%edi
call   10c0 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     130e <aucat_mkcookie+0x11e>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   10b0 <memcpy@plt>
lea    (%r14,%r12,1),%rdi
lea    0xd6f(%rip),%rsi
mov    $0xf,%edx
call   10b0 <memcpy@plt>
add    $0xe,%r12
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   10e0 <open@plt>
test   %eax,%eax
js     131d <aucat_mkcookie+0x12d>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
call   1110 <fstat@plt>
test   %rax,%rax
js     1316 <aucat_mkcookie+0x126>
testb  $0x3f,(%rsp)
jne    1316 <aucat_mkcookie+0x126>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   10a0 <read@plt>
cmp    $0x10,%eax
jne    1316 <aucat_mkcookie+0x126>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %ebx,%ebx
jmp    1220 <aucat_mkcookie+0x30>
mov    %r15,%rdi
mov    $0x10,%esi
call   1100 <random_bytes@plt>
xor    %ebx,%ebx
test   %eax,%eax
jne    121d <aucat_mkcookie+0x2d>
jmp    1235 <aucat_mkcookie+0x45>
mov    $0xdeadbeef,%r12d
jmp    131d <aucat_mkcookie+0x12d>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r15,%rdi
mov    $0x10,%esi
call   1100 <random_bytes@plt>
test   %eax,%eax
je     13c7 <aucat_mkcookie+0x1d7>
test   %r13,%r13
je     13c0 <aucat_mkcookie+0x1d0>
lea    0xa(%r12),%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     13c0 <aucat_mkcookie+0x1d0>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   10b0 <memcpy@plt>
add    %rbx,%r12
lea    0xcaf(%rip),%rsi
mov    %r12,%rdi
mov    $0xa,%edx
call   10b0 <memcpy@plt>
mov    %rbx,%rdi
call   10d0 <mkstemp@plt>
test   %eax,%eax
js     1220 <aucat_mkcookie+0x30>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
mov    $0x10,%edx
call   1060 <write@plt>
test   %rax,%rax
js     13dd <aucat_mkcookie+0x1ed>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10f0 <rename@plt>
test   %rax,%rax
jns    1220 <aucat_mkcookie+0x30>
mov    %rbx,%rdi
call   1050 <unlink@plt>
jmp    1220 <aucat_mkcookie+0x30>
xor    %ebx,%ebx
jmp    1220 <aucat_mkcookie+0x30>
test   %r14,%r14
je     1235 <aucat_mkcookie+0x45>
mov    %r14,%rdi
call   1040 <free@plt>
jmp    1235 <aucat_mkcookie+0x45>
mov    %rbx,%rdi
call   1050 <unlink@plt>
mov    %ebp,%edi
call   1080 <close@plt>
jmp    1220 <aucat_mkcookie+0x30>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [15 x i8] c"/.aucat_cookie\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [10 x i8] c".XXXXXXXX\00"
define i32 @aucat_mkcookie(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stat
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
store i8* null, i8** %6
store i8* null, i8** %7
store i64 3735928559, i64* %9
%12 = call i64 (...) @_sndio_issetugid()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
br label %17
15: ; preds = %1
%16 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %14
%18 = phi i8* [ null, %14 ], [ %16, %15 ]
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %17
br label %94
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = call i64 @strlen(i8* %23)
store i64 %24, i64* %8
%25 = load i64, i64* %8
%26 = add i64 %25, 15
%27 = trunc i64 %26 to i32
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %22
br label %94
32: ; preds = %22
%33 = load i8*, i8** %6
%34 = load i8*, i8** %5
%35 = load i64, i64* %8
%36 = trunc i64 %35 to i32
%37 = call i32 @memcpy(i8* %33, i8* %34, i32 %36)
%38 = load i8*, i8** %6
%39 = load i64, i64* %8
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = call i32 @memcpy(i8* %40, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 15)
%42 = load i64, i64* %8
%43 = add i64 %42, 15
%44 = sub i64 %43, 1
store i64 %44, i64* %9
%45 = load i8*, i8** %6
%46 = load i32, i32* @O_RDONLY
%47 = call i32 @open(i8* %45, i32 %46)
store i32 %47, i32* %10
%48 = load i32, i32* %10
%49 = icmp slt i32 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %32
%51 = load i64, i64* @errno
%52 = load i64, i64* @ENOENT
%53 = icmp ne i64 %51, %52
br i1 %53, label %54, label %57
54: ; preds = %50
br label %55
55: ; preds = %54
br label %56
56: ; preds = %55
br label %57
57: ; preds = %56, %50
br label %94
58: ; preds = %32
%59 = load i32, i32* %10
%60 = call i64 @fstat(i32 %59, %struct.stat* %4)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %58
br label %63
63: ; preds = %62
br label %64
64: ; preds = %63
br label %91
65: ; preds = %58
%66 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%67 = load i32, i32* %66
%68 = and i32 %67, 63
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %65
br label %71
71: ; preds = %70
br label %72
72: ; preds = %71
br label %91
73: ; preds = %65
%74 = load i32, i32* %10
%75 = load i8*, i8** %3
%76 = call i32 @read(i32 %74, i8* %75, i32 16)
store i32 %76, i32* %11
%77 = load i32, i32* %11
%78 = icmp slt i32 %77, 0
br i1 %78, label %79, label %82
79: ; preds = %73
br label %80
80: ; preds = %79
br label %81
81: ; preds = %80
br label %91
82: ; preds = %73
%83 = load i32, i32* %11
%84 = icmp ne i32 %83, 16
br i1 %84, label %85, label %88
85: ; preds = %82
br label %86
86: ; preds = %85
br label %87
87: ; preds = %86
br label %91
88: ; preds = %82
%89 = load i32, i32* %10
%90 = call i32 @close(i32 %89)
br label %159
91: ; preds = %87, %81, %72, %64
%92 = load i32, i32* %10
%93 = call i32 @close(i32 %92)
br label %94
94: ; preds = %91, %57, %31, %21
%95 = load i8*, i8** %3
%96 = call i32 @random_bytes(i8* %95, i32 16)
%97 = icmp ne i32 %96, 0
br i1 %97, label %105, label %98
98: ; preds = %94
%99 = load i8*, i8** %6
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i8*, i8** %6
%103 = call i32 @free(i8* %102)
br label %104
104: ; preds = %101, %98
store i32 0, i32* %2
br label %164
105: ; preds = %94
%106 = load i8*, i8** %5
%107 = icmp eq i8* %106, null
br i1 %107, label %108, label %109
108: ; preds = %105
br label %159
109: ; preds = %105
%110 = load i64, i64* %9
%111 = add i64 %110, 10
%112 = trunc i64 %111 to i32
%113 = call i8* @malloc(i32 %112)
store i8* %113, i8** %7
%114 = load i8*, i8** %7
%115 = icmp eq i8* %114, null
br i1 %115, label %116, label %117
116: ; preds = %109
br label %159
117: ; preds = %109
%118 = load i8*, i8** %7
%119 = load i8*, i8** %6
%120 = load i64, i64* %9
%121 = trunc i64 %120 to i32
%122 = call i32 @memcpy(i8* %118, i8* %119, i32 %121)
%123 = load i8*, i8** %7
%124 = load i64, i64* %9
%125 = getelementptr inbounds i8, i8* %123, i64 %124
%126 = call i32 @memcpy(i8* %125, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 10)
%127 = load i8*, i8** %7
%128 = call i32 @mkstemp(i8* %127)
store i32 %128, i32* %10
%129 = load i32, i32* %10
%130 = icmp slt i32 %129, 0
br i1 %130, label %131, label %134
131: ; preds = %117
br label %132
132: ; preds = %131
br label %133
133: ; preds = %132
br label %159
134: ; preds = %117
%135 = load i32, i32* %10
%136 = load i8*, i8** %3
%137 = call i64 @write(i32 %135, i8* %136, i32 16)
%138 = icmp slt i64 %137, 0
br i1 %138, label %139, label %146
139: ; preds = %134
br label %140
140: ; preds = %139
br label %141
141: ; preds = %140
%142 = load i8*, i8** %7
%143 = call i32 @unlink(i8* %142)
%144 = load i32, i32* %10
%145 = call i32 @close(i32 %144)
br label %159
146: ; preds = %134
%147 = load i32, i32* %10
%148 = call i32 @close(i32 %147)
%149 = load i8*, i8** %7
%150 = load i8*, i8** %6
%151 = call i64 @rename(i8* %149, i8* %150)
%152 = icmp slt i64 %151, 0
br i1 %152, label %153, label %158
153: ; preds = %146
br label %154
154: ; preds = %153
br label %155
155: ; preds = %154
%156 = load i8*, i8** %7
%157 = call i32 @unlink(i8* %156)
br label %158
158: ; preds = %155, %146
br label %159
159: ; preds = %158, %141, %133, %116, %108, %88
%160 = load i8*, i8** %7
%161 = call i32 @free(i8* %160)
%162 = load i8*, i8** %6
%163 = call i32 @free(i8* %162)
store i32 1, i32* %2
br label %164
164: ; preds = %159, %104
%165 = load i32, i32* %2
ret i32 %165
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [15 x i8] c"/.aucat_cookie\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.2 = [10 x i8] c".XXXXXXXX\00"
define i32 @aucat_mkcookie(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i64 (...) @_sndio_issetugid()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %45
6: ; preds = %1
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %42, label %9
9: ; preds = %6
%10 = tail call i64 @strlen(i8* %7)
%11 = trunc i64 %10 to i32
%12 = add i32 %11, 15
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %38, label %15
15: ; preds = %9
%16 = tail call i32 @memcpy(i8* %13, i8* %7, i32 %11)
%17 = getelementptr inbounds i8, i8* %13, i64 %10
%18 = tail call i32 @memcpy(i8* %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 15)
%19 = add i64 %10, 14
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 @open(i8* %13, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %38, label %23
23: ; preds = %15
%24 = call i64 @fstat(i32 %21, %struct.stat* %2)
%25 = icmp slt i64 %24, 0
br i1 %25, label %36, label %26
26: ; preds = %23
%27 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%28 = load i32, i32* %27
%29 = and i32 %28, 63
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = tail call i32 @read(i32 %21, i8* %0, i32 16)
%33 = icmp eq i32 %32, 16
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = tail call i32 @close(i32 %21)
br label %76
36: ; preds = %31, %26, %23
%37 = tail call i32 @close(i32 %21)
br label %38
38: ; preds = %15, %9, %36
%39 = phi i64 [ 3735928559, %9 ], [ %19, %36 ], [ %19, %15 ]
%40 = tail call i32 @random_bytes(i8* %0, i32 16)
%41 = icmp eq i32 %40, 0
br i1 %41, label %48, label %52
42: ; preds = %6
%43 = tail call i32 @random_bytes(i8* %0, i32 16)
%44 = icmp eq i32 %43, 0
br i1 %44, label %81, label %76
45: ; preds = %1
%46 = tail call i32 @random_bytes(i8* %0, i32 16)
%47 = icmp eq i32 %46, 0
br i1 %47, label %81, label %76
48: ; preds = %38
%49 = icmp eq i8* %13, null
br i1 %49, label %81, label %50
50: ; preds = %48
%51 = tail call i32 @free(i8* %13)
br label %81
52: ; preds = %38
br i1 %8, label %76, label %53
53: ; preds = %52
%54 = trunc i64 %39 to i32
%55 = add i32 %54, 10
%56 = tail call i8* @malloc(i32 %55)
%57 = icmp eq i8* %56, null
br i1 %57, label %76, label %58
58: ; preds = %53
%59 = tail call i32 @memcpy(i8* %56, i8* %13, i32 %54)
%60 = getelementptr inbounds i8, i8* %56, i64 %39
%61 = tail call i32 @memcpy(i8* %60, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 10)
%62 = tail call i32 @mkstemp(i8* %56)
%63 = icmp slt i32 %62, 0
br i1 %63, label %76, label %64
64: ; preds = %58
%65 = tail call i64 @write(i32 %62, i8* %0, i32 16)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = tail call i32 @unlink(i8* %56)
%69 = tail call i32 @close(i32 %62)
br label %76
70: ; preds = %64
%71 = tail call i32 @close(i32 %62)
%72 = tail call i64 @rename(i8* %56, i8* %13)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = tail call i32 @unlink(i8* %56)
br label %76
76: ; preds = %42, %45, %70, %74, %58, %53, %52, %67, %34
%77 = phi i8* [ null, %52 ], [ null, %53 ], [ %56, %58 ], [ %56, %67 ], [ %56, %74 ], [ %56, %70 ], [ null, %34 ], [ null, %45 ], [ null, %42 ]
%78 = phi i8* [ %13, %52 ], [ %13, %53 ], [ %13, %58 ], [ %13, %67 ], [ %13, %74 ], [ %13, %70 ], [ %13, %34 ], [ null, %45 ], [ null, %42 ]
%79 = tail call i32 @free(i8* %77)
%80 = tail call i32 @free(i8* %78)
br label %81
81: ; preds = %42, %45, %48, %50, %76
%82 = phi i32 [ 1, %76 ], [ 0, %50 ], [ 0, %48 ], [ 0, %45 ], [ 0, %42 ]
ret i32 %82
}