#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 dummy;
};

/* Variables and functions */
scalar_t__ ENOENT;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ cctools_fatal(char *, char const *, int /*<<< orphan*/);
scalar_t__ errno;
int mkdir(char const *, int);
int /*<<< orphan*/ *realpath(char const *, char *);
int rmdir(char const *);
int stat(char const *, struct stat *);
int /*<<< orphan*/ strerror(scalar_t__);
void path_absolute(const char *src, char *dest, int exist) {
  struct stat buf;
  int created = 0;
  if (stat(src, &buf) == -1) {
    if (errno == ENOENT && !exist) {
      if (mkdir(src, S_IRUSR | S_IWUSR) == -1) {
        cctools_fatal("generating absolute path to `%s': %s", src,
                      strerror(errno));
      }
      created = 1;
    } else {
      cctools_fatal("could not resolve path `%s': %s", src, strerror(errno));
    }
  }
  if (realpath(src, dest) == NULL) {
    cctools_fatal("could not resolve path `%s': %s", src, strerror(errno));
  }
  if (created) {
    if (rmdir(src) == -1)
      cctools_fatal("could not delete temporary dir `%s': %s", src,
                    strerror(errno));
  }
}


x86 assembly (clang, -O0):
<path_absolute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    123b <path_absolute+0xdb>
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%rax
jne    120d <path_absolute+0xad>
cmpl   $0x0,-0x14(%rbp)
jne    120d <path_absolute+0xad>
mov    -0x8(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1201 <path_absolute+0xa1>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
lea    0xe04(%rip),%rdi
call   1050 <cctools_fatal@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1236 <path_absolute+0xd6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xdf4(%rip),%rdi
call   1050 <cctools_fatal@plt>
jmp    123b <path_absolute+0xdb>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <realpath@plt>
cmp    $0x0,%rax
jne    127b <path_absolute+0x11b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d77(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    0xdaf(%rip),%rdi
call   1050 <cctools_fatal@plt>
cmpl   $0x0,-0x1c(%rbp)
je     12c5 <path_absolute+0x165>
mov    -0x8(%rbp),%rdi
call   1040 <rmdir@plt>
cmp    $0xffffffff,%eax
jne    12c0 <path_absolute+0x160>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xd8a(%rip),%rdi
call   1050 <cctools_fatal@plt>
jmp    12c5 <path_absolute+0x165>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_absolute>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
mov    $0x1,%bpl
cmp    $0xffffffff,%eax
jne    11f4 <path_absolute+0x94>
mov    0x2e4a(%rip),%r12
mov    (%r12),%rdi
mov    0x2e27(%rip),%rax
cmp    (%rax),%rdi
setne  %al
test   %r15d,%r15d
setne  %bpl
or     %al,%bpl
je     11b4 <path_absolute+0x54>
lea    0xe73(%rip),%r15
jmp    11e2 <path_absolute+0x82>
mov    0x2e15(%rip),%rax
mov    0x2e26(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
je     11d7 <path_absolute+0x77>
xor    %ebp,%ebp
jmp    11f4 <path_absolute+0x94>
mov    (%r12),%rdi
lea    0xe1e(%rip),%r15
call   1080 <strerror@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <cctools_fatal@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <realpath@plt>
test   %rax,%rax
je     120b <path_absolute+0xab>
test   %bpl,%bpl
je     1230 <path_absolute+0xd0>
jmp    123d <path_absolute+0xdd>
mov    0x2dc6(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
lea    0xe04(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <cctools_fatal@plt>
test   %bpl,%bpl
jne    123d <path_absolute+0xdd>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
cmp    $0xffffffff,%eax
je     124a <path_absolute+0xea>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d87(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
lea    0xde5(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <cctools_fatal@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [37 x i8] c"generating absolute path to `%s': %s\00"
@.str.1 = [32 x i8] c"could not resolve path `%s': %s\00"
@.str.2 = [40 x i8] c"could not delete temporary dir `%s': %s\00"
define void @path_absolute(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
%9 = load i8*, i8** %4
%10 = call i32 @stat(i8* %9, %struct.stat* %7)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %38
12: ; preds = %3
%13 = load i64, i64* @errno
%14 = load i64, i64* @ENOENT
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = load i32, i32* @S_IRUSR
%22 = load i32, i32* @S_IWUSR
%23 = or i32 %21, %22
%24 = call i32 @mkdir(i8* %20, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %19
%27 = load i8*, i8** %4
%28 = load i64, i64* @errno
%29 = call i32 @strerror(i64 %28)
%30 = call i32 @cctools_fatal(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %27, i32 %29)
br label %31
31: ; preds = %26, %19
store i32 1, i32* %8
br label %37
32: ; preds = %16, %12
%33 = load i8*, i8** %4
%34 = load i64, i64* @errno
%35 = call i32 @strerror(i64 %34)
%36 = call i32 @cctools_fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %33, i32 %35)
br label %37
37: ; preds = %32, %31
br label %38
38: ; preds = %37, %3
%39 = load i8*, i8** %4
%40 = load i8*, i8** %5
%41 = call i32* @realpath(i8* %39, i8* %40)
%42 = icmp eq i32* %41, null
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load i8*, i8** %4
%45 = load i64, i64* @errno
%46 = call i32 @strerror(i64 %45)
%47 = call i32 @cctools_fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %44, i32 %46)
br label %48
48: ; preds = %43, %38
%49 = load i32, i32* %8
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %61
51: ; preds = %48
%52 = load i8*, i8** %4
%53 = call i32 @rmdir(i8* %52)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %60
55: ; preds = %51
%56 = load i8*, i8** %4
%57 = load i64, i64* @errno
%58 = call i32 @strerror(i64 %57)
%59 = call i32 @cctools_fatal(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %56, i32 %58)
br label %60
60: ; preds = %55, %51
br label %61
61: ; preds = %60, %48
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [37 x i8] c"generating absolute path to `%s': %s\00"
@.str.1 = [32 x i8] c"could not resolve path `%s': %s\00"
@.str.2 = [40 x i8] c"could not delete temporary dir `%s': %s\00"
define void @path_absolute(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = call i32 @stat(i8* %0, %struct.stat* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %27
8: ; preds = %3
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp ne i64 %9, %10
%12 = icmp ne i32 %2, 0
%13 = or i1 %12, %11
br i1 %13, label %22, label %14
14: ; preds = %8
%15 = load i32, i32* @S_IRUSR
%16 = load i32, i32* @S_IWUSR
%17 = or i32 %16, %15
%18 = tail call i32 @mkdir(i8* %0, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %27
20: ; preds = %14
%21 = load i64, i64* @errno
br label %22
22: ; preds = %8, %20
%23 = phi i64 [ %21, %20 ], [ %9, %8 ]
%24 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), %20 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), %8 ]
%25 = tail call i32 @strerror(i64 %23)
%26 = tail call i32 @cctools_fatal(i8* %24, i8* %0, i32 %25)
br label %27
27: ; preds = %22, %14, %3
%28 = phi i1 [ true, %3 ], [ false, %14 ], [ %13, %22 ]
%29 = tail call i32* @realpath(i8* %0, i8* %1)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i64, i64* @errno
%33 = tail call i32 @strerror(i64 %32)
%34 = tail call i32 @cctools_fatal(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %33)
br label %35
35: ; preds = %31, %27
br i1 %28, label %43, label %36
36: ; preds = %35
%37 = tail call i32 @rmdir(i8* %0)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i64, i64* @errno
%41 = tail call i32 @strerror(i64 %40)
%42 = tail call i32 @cctools_fatal(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %41)
br label %43
43: ; preds = %36, %39, %35
ret void
}