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

/* Variables and functions */
scalar_t__ asprintf(char **, char *, char const *);
scalar_t__ chdir(char *);
scalar_t__ chmod(char *, int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
scalar_t__ mkdir(char const *, int);
scalar_t__ mkdtemp(char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ rmdir(char *);
int /*<<< orphan*/ stderr;
char *strerror(int const);
int make_root(const char *root_opt) {
  if (root_opt) {
    int ret = mkdir(root_opt, 0755) < 0 ? -errno : 0;
    do {
      const int ON_ERROR_ret = (ret);
      if (ON_ERROR_ret < 0) {
        const char *ON_ERROR_message = ("mkdir(root_opt)");
        if (ON_ERROR_message) {
          fputs(ON_ERROR_message, stderr);
          fprintf(stderr, ": %s\n", strerror(-ON_ERROR_ret));
        }
        return ret;
      }
    } while (0);
    return ret;
  }
  const char *tmp = getenv("TMPDIR");
  if (!tmp)
    tmp = "/tmp";
  int ret;
  char *template;
  ret = asprintf(&template, "%s/toyoj-sandbox-XXXXXX", tmp) < 0 ? -errno : 0;
  do {
    const int ON_ERROR_ret = (ret);
    if (ON_ERROR_ret < 0) {
      const char *ON_ERROR_message = ("asprintf");
      if (ON_ERROR_message) {
        fputs(ON_ERROR_message, stderr);
        fprintf(stderr, ": %s\n", strerror(-ON_ERROR_ret));
      }
      return ret;
    }
  } while (0);
  ret = mkdtemp(template) ? 0 : -errno;
  do {
    const int ON_ERROR_ret = (ret);
    if (ON_ERROR_ret < 0) {
      const char *ON_ERROR_message = ("mkdtemp");
      if (ON_ERROR_message) {
        fputs(ON_ERROR_message, stderr);
        fprintf(stderr, ": %s\n", strerror(-ON_ERROR_ret));
      }
      goto out;
    }
  } while (0);
  ret = chmod(template, 0755) < 0 ? -errno : 0;
  do {
    const int ON_ERROR_ret = (ret);
    if (ON_ERROR_ret < 0) {
      const char *ON_ERROR_message = ("chmod");
      if (ON_ERROR_message) {
        fputs(ON_ERROR_message, stderr);
        fprintf(stderr, ": %s\n", strerror(-ON_ERROR_ret));
      }
      goto out_rmdir;
    }
  } while (0);
  ret = chdir(template) < 0 ? -errno : 0;
  do {
    const int ON_ERROR_ret = (ret);
    if (ON_ERROR_ret < 0) {
      const char *ON_ERROR_message = ("chdir");
      if (ON_ERROR_message) {
        fputs(ON_ERROR_message, stderr);
        fprintf(stderr, ": %s\n", strerror(-ON_ERROR_ret));
      }
      goto out_rmdir;
    }
  } while (0);
out:
  free(template);
  return ret;
out_rmdir:
  if (rmdir(template) < 0)
    perror("rmdir");
  goto out;
}


x86 assembly (clang, -O0):
<make_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1290 <make_root+0xd0>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
cmp    $0x0,%rax
jge    1205 <make_root+0x45>
xor    %eax,%eax
mov    0x2ddd(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x7c(%rbp)
jmp    120f <make_root+0x4f>
xor    %eax,%eax
mov    %eax,-0x7c(%rbp)
jmp    120f <make_root+0x4f>
mov    -0x7c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1280 <make_root+0xc0>
lea    0xdd4(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1275 <make_root+0xb5>
mov    -0x20(%rbp),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x80(%rbp)
xor    %edi,%edi
sub    -0x18(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0x80(%rbp),%edi
mov    %rax,%rdx
lea    0xda0(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15c0 <make_root+0x400>
jmp    1285 <make_root+0xc5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15c0 <make_root+0x400>
lea    0xd7f(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    12b6 <make_root+0xf6>
lea    0xd6b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    0xd5d(%rip),%rsi
call   10a0 <asprintf@plt>
cmp    $0x0,%rax
jge    12ea <make_root+0x12a>
xor    %eax,%eax
mov    0x2cfb(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x84(%rbp)
jmp    12f7 <make_root+0x137>
xor    %eax,%eax
mov    %eax,-0x84(%rbp)
jmp    12f7 <make_root+0x137>
mov    -0x84(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1371 <make_root+0x1b1>
lea    0xd23(%rip),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     1366 <make_root+0x1a6>
mov    -0x48(%rbp),%rdi
mov    0x2caf(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
mov    0x2ca1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
xor    %edi,%edi
sub    -0x3c(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xcaf(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15c0 <make_root+0x400>
jmp    1376 <make_root+0x1b6>
mov    -0x38(%rbp),%rdi
call   10b0 <mkdtemp@plt>
cmp    $0x0,%rax
je     1396 <make_root+0x1d6>
xor    %eax,%eax
mov    %eax,-0x8c(%rbp)
jmp    13a7 <make_root+0x1e7>
xor    %eax,%eax
mov    0x2c39(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    141b <make_root+0x25b>
lea    0xc7c(%rip),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     1416 <make_root+0x256>
mov    -0x58(%rbp),%rdi
mov    0x2bff(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
mov    0x2bf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
xor    %edi,%edi
sub    -0x4c(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0x90(%rbp),%edi
mov    %rax,%rdx
lea    0xbff(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1588 <make_root+0x3c8>
jmp    1420 <make_root+0x260>
mov    -0x38(%rbp),%rdi
mov    $0x1ed,%esi
call   10c0 <chmod@plt>
cmp    $0x0,%rax
jge    144e <make_root+0x28e>
xor    %eax,%eax
mov    0x2b97(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x94(%rbp)
jmp    145b <make_root+0x29b>
xor    %eax,%eax
mov    %eax,-0x94(%rbp)
jmp    145b <make_root+0x29b>
mov    -0x94(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    14cf <make_root+0x30f>
lea    0xbd0(%rip),%rax
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     14ca <make_root+0x30a>
mov    -0x68(%rbp),%rdi
mov    0x2b4b(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
mov    0x2b3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
xor    %edi,%edi
sub    -0x5c(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0x98(%rbp),%edi
mov    %rax,%rdx
lea    0xb4b(%rip),%rsi
call   1090 <fprintf@plt>
jmp    159c <make_root+0x3dc>
jmp    14d4 <make_root+0x314>
mov    -0x38(%rbp),%rdi
call   1070 <chdir@plt>
cmp    $0x0,%rax
jge    14fd <make_root+0x33d>
xor    %eax,%eax
mov    0x2ae8(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x9c(%rbp)
jmp    150a <make_root+0x34a>
xor    %eax,%eax
mov    %eax,-0x9c(%rbp)
jmp    150a <make_root+0x34a>
mov    -0x9c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
cmpl   $0x0,-0x6c(%rbp)
jge    157e <make_root+0x3be>
lea    0xb27(%rip),%rax
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
je     1579 <make_root+0x3b9>
mov    -0x78(%rbp),%rdi
mov    0x2a9c(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
mov    0x2a8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa0(%rbp)
xor    %edi,%edi
sub    -0x6c(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0xa0(%rbp),%edi
mov    %rax,%rdx
lea    0xa9c(%rip),%rsi
call   1090 <fprintf@plt>
jmp    159c <make_root+0x3dc>
jmp    1583 <make_root+0x3c3>
jmp    1588 <make_root+0x3c8>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15c0 <make_root+0x400>
mov    -0x38(%rbp),%rdi
call   1060 <rmdir@plt>
cmp    $0x0,%rax
jge    15bb <make_root+0x3fb>
lea    0xaa1(%rip),%rdi
call   10d0 <perror@plt>
jmp    1588 <make_root+0x3c8>
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_root>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11f7 <make_root+0x37>
mov    $0x1ed,%esi
call   1050 <mkdir@plt>
mov    %rax,%rbp
mov    0x2df8(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
sar    $0x3f,%rbp
and    %ebx,%ebp
js     12a1 <make_root+0xe1>
mov    %ebp,%ebx
jmp    137b <make_root+0x1bb>
lea    0xe18(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe10(%rip),%rdx
cmovne %rax,%rdx
lea    0xe0a(%rip),%rsi
mov    %rsp,%rdi
call   10a0 <asprintf@plt>
mov    %rax,%rbp
mov    0x2dae(%rip),%r15
xor    %r14d,%r14d
xor    %ebx,%ebx
sub    (%r15),%ebx
sar    $0x3f,%rbp
and    %ebx,%ebp
js     12b4 <make_root+0xf4>
mov    (%rsp),%rdi
call   10b0 <mkdtemp@plt>
xor    %ebx,%ebx
sub    (%r15),%ebx
test   %rax,%rax
cmove  %ebx,%r14d
test   %r14d,%r14d
js     12ed <make_root+0x12d>
mov    (%rsp),%rdi
mov    $0x1ed,%esi
call   10c0 <chmod@plt>
mov    %rax,%r14
xor    %ebp,%ebp
xor    %ebx,%ebx
sub    (%r15),%ebx
sar    $0x3f,%r14
and    %ebx,%r14d
js     1324 <make_root+0x164>
mov    (%rsp),%rdi
call   1070 <chdir@plt>
mov    %rax,%r14
sub    (%r15),%ebp
sar    $0x3f,%r14
and    %ebp,%r14d
js     132d <make_root+0x16d>
mov    %r14d,%ebx
jmp    1372 <make_root+0x1b2>
mov    0x2d38(%rip),%r14
mov    (%r14),%esi
lea    0xd4e(%rip),%rdi
jmp    12c5 <make_root+0x105>
mov    0x2d25(%rip),%r14
mov    (%r14),%esi
lea    0xd75(%rip),%rdi
call   1080 <fputs@plt>
mov    (%r14),%r14d
neg    %ebp
mov    %ebp,%edi
call   10e0 <strerror@plt>
lea    0xd33(%rip),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
jmp    137b <make_root+0x1bb>
mov    0x2cec(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xd45(%rip),%rdi
call   1080 <fputs@plt>
mov    0x0(%rbp),%ebp
neg    %r14d
mov    %r14d,%edi
call   10e0 <strerror@plt>
lea    0xcf8(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
jmp    1372 <make_root+0x1b2>
lea    0xd20(%rip),%rdi
jmp    1336 <make_root+0x176>
lea    0xd1d(%rip),%rdi
mov    %ebp,%ebx
mov    0x2ca3(%rip),%rbp
mov    0x0(%rbp),%esi
call   1080 <fputs@plt>
mov    0x0(%rbp),%ebp
neg    %r14d
mov    %r14d,%edi
call   10e0 <strerror@plt>
lea    0xcb6(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
mov    (%rsp),%rdi
call   1060 <rmdir@plt>
test   %rax,%rax
js     1388 <make_root+0x1c8>
mov    (%rsp),%rdi
call   1040 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcc8(%rip),%rdi
call   10d0 <perror@plt>
jmp    1372 <make_root+0x1b2>

LLVM IR (-O0):
@errno = global i32 0
@.str = [16 x i8] c"mkdir(root_opt)\00"
@stderr = global i32 0
@.str.1 = [6 x i8] c": %s\0A\00"
@.str.2 = [7 x i8] c"TMPDIR\00"
@.str.3 = [5 x i8] c"/tmp\00"
@.str.4 = [24 x i8] c"%s/toyoj-sandbox-XXXXXX\00"
@.str.5 = [9 x i8] c"asprintf\00"
@.str.6 = [8 x i8] c"mkdtemp\00"
@.str.7 = [6 x i8] c"chmod\00"
@.str.8 = [6 x i8] c"chdir\00"
@.str.9 = [6 x i8] c"rmdir\00"
define i32 @make_root(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i8*
store i8* %0, i8** %3
%18 = load i8*, i8** %3
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %51
20: ; preds = %1
%21 = load i8*, i8** %3
%22 = call i64 @mkdir(i8* %21, i32 493)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @errno
%26 = sub nsw i32 0, %25
br label %28
27: ; preds = %20
br label %28
28: ; preds = %27, %24
%29 = phi i32 [ %26, %24 ], [ 0, %27 ]
store i32 %29, i32* %4
br label %30
30: ; preds = %28
%31 = load i32, i32* %4
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %48
34: ; preds = %30
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %6
%35 = load i8*, i8** %6
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i8*, i8** %6
%39 = load i32, i32* @stderr
%40 = call i32 @fputs(i8* %38, i32 %39)
%41 = load i32, i32* @stderr
%42 = load i32, i32* %5
%43 = sub nsw i32 0, %42
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %37, %34
%47 = load i32, i32* %4
store i32 %47, i32* %2
br label %181
48: ; preds = %30
br label %49
49: ; preds = %48
%50 = load i32, i32* %4
store i32 %50, i32* %2
br label %181
51: ; preds = %1
%52 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %52, i8** %7
%53 = load i8*, i8** %7
%54 = icmp ne i8* %53, null
br i1 %54, label %56, label %55
55: ; preds = %51
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %56
56: ; preds = %55, %51
%57 = load i8*, i8** %7
%58 = call i64 @asprintf(i8** %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %56
%61 = load i32, i32* @errno
%62 = sub nsw i32 0, %61
br label %64
63: ; preds = %56
br label %64
64: ; preds = %63, %60
%65 = phi i32 [ %62, %60 ], [ 0, %63 ]
store i32 %65, i32* %8
br label %66
66: ; preds = %64
%67 = load i32, i32* %8
store i32 %67, i32* %10
%68 = load i32, i32* %10
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %84
70: ; preds = %66
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8** %11
%71 = load i8*, i8** %11
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %82
73: ; preds = %70
%74 = load i8*, i8** %11
%75 = load i32, i32* @stderr
%76 = call i32 @fputs(i8* %74, i32 %75)
%77 = load i32, i32* @stderr
%78 = load i32, i32* %10
%79 = sub nsw i32 0, %78
%80 = call i8* @strerror(i32 %79)
%81 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %80)
br label %82
82: ; preds = %73, %70
%83 = load i32, i32* %8
store i32 %83, i32* %2
br label %181
84: ; preds = %66
br label %85
85: ; preds = %84
%86 = load i8*, i8** %9
%87 = call i64 @mkdtemp(i8* %86)
%88 = icmp ne i64 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %85
br label %93
90: ; preds = %85
%91 = load i32, i32* @errno
%92 = sub nsw i32 0, %91
br label %93
93: ; preds = %90, %89
%94 = phi i32 [ 0, %89 ], [ %92, %90 ]
store i32 %94, i32* %8
br label %95
95: ; preds = %93
%96 = load i32, i32* %8
store i32 %96, i32* %12
%97 = load i32, i32* %12
%98 = icmp slt i32 %97, 0
br i1 %98, label %99, label %112
99: ; preds = %95
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %13
%100 = load i8*, i8** %13
%101 = icmp ne i8* %100, null
br i1 %101, label %102, label %111
102: ; preds = %99
%103 = load i8*, i8** %13
%104 = load i32, i32* @stderr
%105 = call i32 @fputs(i8* %103, i32 %104)
%106 = load i32, i32* @stderr
%107 = load i32, i32* %12
%108 = sub nsw i32 0, %107
%109 = call i8* @strerror(i32 %108)
%110 = call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %109)
br label %111
111: ; preds = %102, %99
br label %170
112: ; preds = %95
br label %113
113: ; preds = %112
%114 = load i8*, i8** %9
%115 = call i64 @chmod(i8* %114, i32 493)
%116 = icmp slt i64 %115, 0
br i1 %116, label %117, label %120
117: ; preds = %113
%118 = load i32, i32* @errno
%119 = sub nsw i32 0, %118
br label %121
120: ; preds = %113
br label %121
121: ; preds = %120, %117
%122 = phi i32 [ %119, %117 ], [ 0, %120 ]
store i32 %122, i32* %8
br label %123
123: ; preds = %121
%124 = load i32, i32* %8
store i32 %124, i32* %14
%125 = load i32, i32* %14
%126 = icmp slt i32 %125, 0
br i1 %126, label %127, label %140
127: ; preds = %123
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %15
%128 = load i8*, i8** %15
%129 = icmp ne i8* %128, null
br i1 %129, label %130, label %139
130: ; preds = %127
%131 = load i8*, i8** %15
%132 = load i32, i32* @stderr
%133 = call i32 @fputs(i8* %131, i32 %132)
%134 = load i32, i32* @stderr
%135 = load i32, i32* %14
%136 = sub nsw i32 0, %135
%137 = call i8* @strerror(i32 %136)
%138 = call i32 @fprintf(i32 %134, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %137)
br label %139
139: ; preds = %130, %127
br label %174
140: ; preds = %123
br label %141
141: ; preds = %140
%142 = load i8*, i8** %9
%143 = call i64 @chdir(i8* %142)
%144 = icmp slt i64 %143, 0
br i1 %144, label %145, label %148
145: ; preds = %141
%146 = load i32, i32* @errno
%147 = sub nsw i32 0, %146
br label %149
148: ; preds = %141
br label %149
149: ; preds = %148, %145
%150 = phi i32 [ %147, %145 ], [ 0, %148 ]
store i32 %150, i32* %8
br label %151
151: ; preds = %149
%152 = load i32, i32* %8
store i32 %152, i32* %16
%153 = load i32, i32* %16
%154 = icmp slt i32 %153, 0
br i1 %154, label %155, label %168
155: ; preds = %151
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8** %17
%156 = load i8*, i8** %17
%157 = icmp ne i8* %156, null
br i1 %157, label %158, label %167
158: ; preds = %155
%159 = load i8*, i8** %17
%160 = load i32, i32* @stderr
%161 = call i32 @fputs(i8* %159, i32 %160)
%162 = load i32, i32* @stderr
%163 = load i32, i32* %16
%164 = sub nsw i32 0, %163
%165 = call i8* @strerror(i32 %164)
%166 = call i32 @fprintf(i32 %162, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %165)
br label %167
167: ; preds = %158, %155
br label %174
168: ; preds = %151
br label %169
169: ; preds = %168
br label %170
170: ; preds = %180, %169, %111
%171 = load i8*, i8** %9
%172 = call i32 @free(i8* %171)
%173 = load i32, i32* %8
store i32 %173, i32* %2
br label %181
174: ; preds = %167, %139
%175 = load i8*, i8** %9
%176 = call i64 @rmdir(i8* %175)
%177 = icmp slt i64 %176, 0
br i1 %177, label %178, label %180
178: ; preds = %174
%179 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
br label %180
180: ; preds = %178, %174
br label %170
181: ; preds = %170, %82, %49, %46
%182 = load i32, i32* %2
ret i32 %182
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [16 x i8] c"mkdir(root_opt)\00"
@stderr = global i32 0
@.str.1 = [6 x i8] c": %s\0A\00"
@.str.2 = [7 x i8] c"TMPDIR\00"
@.str.3 = [5 x i8] c"/tmp\00"
@.str.4 = [24 x i8] c"%s/toyoj-sandbox-XXXXXX\00"
@.str.5 = [9 x i8] c"asprintf\00"
@.str.6 = [8 x i8] c"mkdtemp\00"
@.str.7 = [6 x i8] c"chmod\00"
@.str.8 = [6 x i8] c"chdir\00"
@.str.9 = [6 x i8] c"rmdir\00"
define i32 @make_root(i8* %0) {
%2 = alloca i8*
%3 = icmp eq i8* %0, null
br i1 %3, label %18, label %4
4: ; preds = %1
%5 = tail call i64 @mkdir(i8* %0, i32 493)
%6 = icmp slt i64 %5, 0
%7 = load i32, i32* @errno
%8 = sub nsw i32 0, %7
%9 = select i1 %6, i32 %8, i32 0
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %88
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fputs(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @stderr
%15 = sub nsw i32 0, %9
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %88
18: ; preds = %1
%19 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i8* %19, null
%21 = select i1 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %19
%22 = bitcast i8** %2 to i8*
%23 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%24 = icmp slt i64 %23, 0
%25 = load i32, i32* @errno
%26 = sub nsw i32 0, %25
%27 = select i1 %24, i32 %26, i32 0
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = call i32 @fputs(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @stderr
%33 = sub nsw i32 0, %27
%34 = call i8* @strerror(i32 %33)
%35 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %86
36: ; preds = %18
%37 = load i8*, i8** %2
%38 = call i64 @mkdtemp(i8* %37)
%39 = icmp eq i64 %38, 0
%40 = load i32, i32* @errno
%41 = sub nsw i32 0, %40
%42 = select i1 %39, i32 %41, i32 0
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %36
%45 = load i32, i32* @stderr
%46 = call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%47 = load i32, i32* @stderr
%48 = sub nsw i32 0, %42
%49 = call i8* @strerror(i32 %48)
%50 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %49)
br label %67
51: ; preds = %36
%52 = load i8*, i8** %2
%53 = call i64 @chmod(i8* %52, i32 493)
%54 = icmp slt i64 %53, 0
%55 = load i32, i32* @errno
%56 = sub nsw i32 0, %55
%57 = select i1 %54, i32 %56, i32 0
%58 = icmp slt i32 %57, 0
br i1 %58, label %71, label %59
59: ; preds = %51
%60 = load i8*, i8** %2
%61 = call i64 @chdir(i8* %60)
%62 = icmp slt i64 %61, 0
%63 = load i32, i32* @errno
%64 = sub nsw i32 0, %63
%65 = select i1 %62, i32 %64, i32 0
%66 = icmp slt i32 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %59, %44, %71, %84
%68 = phi i32 [ %41, %44 ], [ %74, %84 ], [ %74, %71 ], [ %65, %59 ]
%69 = load i8*, i8** %2
%70 = call i32 @free(i8* %69)
br label %86
71: ; preds = %59, %51
%72 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), %51 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), %59 ]
%73 = phi i32 [ %57, %51 ], [ %65, %59 ]
%74 = phi i32 [ %56, %51 ], [ %64, %59 ]
%75 = load i32, i32* @stderr
%76 = call i32 @fputs(i8* %72, i32 %75)
%77 = load i32, i32* @stderr
%78 = sub nsw i32 0, %73
%79 = call i8* @strerror(i32 %78)
%80 = call i32 @fprintf(i32 %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %79)
%81 = load i8*, i8** %2
%82 = call i64 @rmdir(i8* %81)
%83 = icmp slt i64 %82, 0
br i1 %83, label %84, label %67
84: ; preds = %71
%85 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
br label %67
86: ; preds = %29, %67
%87 = phi i32 [ %68, %67 ], [ %26, %29 ]
br label %88
88: ; preds = %4, %11, %86
%89 = phi i32 [ %87, %86 ], [ %8, %11 ], [ %9, %4 ]
ret i32 %89
}