#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 */
int /*<<< orphan*/ F_OK;
int PATH_MAX;
scalar_t__ access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ getcwd(char *, int);
char *makePathAbsRec(char const *, char *);
int /*<<< orphan*/ strcat(char *, char const *);
char *loggerMakePathAbs(const char *path_, char *resolved_, int mustExist_) {
  assert(resolved_ && "resolved_ must be not NULL!");
  if (!path_ || path_[0] == '\0') {
    return NULL;
  }
  if (mustExist_ && access(path_, F_OK) != 0) {
    return NULL;
  }
  if (path_[0] != '/') {
    char newPath[PATH_MAX];
    if (!getcwd(newPath, PATH_MAX)) {
      return NULL;
    }
    strcat(newPath, "/");
    strcat(newPath, path_);
    return makePathAbsRec(newPath, resolved_);
  }
  return makePathAbsRec(path_, resolved_);
}


x86 assembly (clang, -O0):
<loggerMakePathAbs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x35(%rbp)
je     117d <loggerMakePathAbs+0x2d>
mov    $0x1,%al
mov    %al,-0x35(%rbp)
jmp    117d <loggerMakePathAbs+0x2d>
mov    -0x35(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x10(%rbp)
je     11a5 <loggerMakePathAbs+0x55>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b2 <loggerMakePathAbs+0x62>
movq   $0x0,-0x8(%rbp)
jmp    129e <loggerMakePathAbs+0x14e>
cmpl   $0x0,-0x1c(%rbp)
je     11e5 <loggerMakePathAbs+0x95>
mov    -0x10(%rbp),%rdi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
je     11e5 <loggerMakePathAbs+0x95>
movq   $0x0,-0x8(%rbp)
jmp    129e <loggerMakePathAbs+0x14e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     128d <loggerMakePathAbs+0x13d>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
call   1040 <getcwd@plt>
cmp    $0x0,%eax
jne    124c <loggerMakePathAbs+0xfc>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1281 <loggerMakePathAbs+0x131>
mov    -0x40(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <makePathAbsRec@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    129e <loggerMakePathAbs+0x14e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <makePathAbsRec@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loggerMakePathAbs>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r12
xor    %edi,%edi
test   %rsi,%rsi
setne  %dil
call   1050 <assert@plt>
test   %r12,%r12
je     1198 <loggerMakePathAbs+0x48>
mov    (%r12),%al
test   %al,%al
je     1198 <loggerMakePathAbs+0x48>
test   %ebx,%ebx
je     11ab <loggerMakePathAbs+0x5b>
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    %r12,%rdi
call   1060 <access@plt>
test   %rax,%rax
je     11a7 <loggerMakePathAbs+0x57>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%al
cmp    $0x2f,%al
jne    11c6 <loggerMakePathAbs+0x76>
mov    %r12,%rdi
mov    %r14,%rsi
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <makePathAbsRec@plt>
mov    %rsp,%rbx
mov    0x2e20(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r15
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r15
mov    %r15,%rsp
mov    (%rax),%esi
mov    %r15,%rdi
call   1040 <getcwd@plt>
test   %eax,%eax
je     1218 <loggerMakePathAbs+0xc8>
lea    0xe08(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <makePathAbsRec@plt>
jmp    121a <loggerMakePathAbs+0xca>
xor    %eax,%eax
mov    %rbx,%rsp
jmp    119a <loggerMakePathAbs+0x4a>

LLVM IR (-O0):
@.str = [28 x i8] c"resolved_ must be not NULL!\00"
@F_OK = global i32 0
@PATH_MAX = global i32 0
@.str.1 = [2 x i8] c"/\00"
define i8* @loggerMakePathAbs(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
br label %14
14: ; preds = %13, %3
%15 = phi i1 [ false, %3 ], [ true, %13 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %26
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20, %14
store i8* null, i8** %4
br label %63
27: ; preds = %20
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i8*, i8** %5
%32 = load i32, i32* @F_OK
%33 = call i64 @access(i8* %31, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %30
store i8* null, i8** %4
br label %63
36: ; preds = %30, %27
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 47
br i1 %41, label %42, label %59
42: ; preds = %36
%43 = load i32, i32* @PATH_MAX
%44 = zext i32 %43 to i64
%45 = call i8* @llvm.stacksave()
store i8* %45, i8** %8
%46 = alloca i8, i64 %44
store i64 %44, i64* %9
%47 = load i32, i32* @PATH_MAX
%48 = call i32 @getcwd(i8* %46, i32 %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %51, label %50
50: ; preds = %42
store i8* null, i8** %4
store i32 1, i32* %10
br label %57
51: ; preds = %42
%52 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%53 = load i8*, i8** %5
%54 = call i32 @strcat(i8* %46, i8* %53)
%55 = load i8*, i8** %6
%56 = call i8* @makePathAbsRec(i8* %46, i8* %55)
store i8* %56, i8** %4
store i32 1, i32* %10
br label %57
57: ; preds = %51, %50
%58 = load i8*, i8** %8
br label %63
59: ; preds = %36
%60 = load i8*, i8** %5
%61 = load i8*, i8** %6
%62 = call i8* @makePathAbsRec(i8* %60, i8* %61)
store i8* %62, i8** %4
br label %63
63: ; preds = %59, %57, %35, %26
%64 = load i8*, i8** %4
ret i8* %64
}

LLVM IR (-O2):
@F_OK = global i32 0
@PATH_MAX = global i32 0
@.str.1 = [2 x i8] c"/\00"
define i8* @loggerMakePathAbs(i8* %0, i8* %1, i32 %2) {
%4 = icmp ne i8* %1, null
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp eq i8* %0, null
br i1 %7, label %38, label %8
8: ; preds = %3
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %38, label %11
11: ; preds = %8
%12 = icmp eq i32 %2, 0
br i1 %12, label %19, label %13
13: ; preds = %11
%14 = load i32, i32* @F_OK
%15 = tail call i64 @access(i8* %0, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %38
17: ; preds = %13
%18 = load i8, i8* %0
br label %19
19: ; preds = %17, %11
%20 = phi i8 [ %18, %17 ], [ %9, %11 ]
%21 = icmp eq i8 %20, 47
br i1 %21, label %36, label %22
22: ; preds = %19
%23 = load i32, i32* @PATH_MAX
%24 = zext i32 %23 to i64
%25 = tail call i8* @llvm.stacksave()
%26 = alloca i8, i64 %24
%27 = load i32, i32* @PATH_MAX
%28 = call i32 @getcwd(i8* %26, i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %22
%31 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @strcat(i8* %26, i8* %0)
%33 = call i8* @makePathAbsRec(i8* %26, i8* %1)
br label %34
34: ; preds = %22, %30
%35 = phi i8* [ %33, %30 ], [ null, %22 ]
br label %38
36: ; preds = %19
%37 = tail call i8* @makePathAbsRec(i8* %0, i8* %1)
br label %38
38: ; preds = %13, %3, %8, %36, %34
%39 = phi i8* [ %35, %34 ], [ %37, %36 ], [ null, %8 ], [ null, %3 ], [ null, %13 ]
ret i8* %39
}