#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 */
char *loggerStrDup(char *);
char *loggerStrNDup(char const *, int);
char *strrchr(char const *, char);
char *loggerGetFileDir(const char *absPath_) {
  const char *slashPos = strrchr(absPath_, '/');
  if (slashPos == absPath_) {
    return loggerStrDup("/");
  } else if (slashPos) {
    return loggerStrNDup(absPath_, slashPos - absPath_);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<loggerGetFileDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1171 <loggerGetFileDir+0x41>
lea    0xe9d(%rip),%rdi
call   1030 <loggerStrDup@plt>
mov    %rax,-0x8(%rbp)
jmp    11a8 <loggerGetFileDir+0x78>
cmpq   $0x0,-0x18(%rbp)
je     119b <loggerGetFileDir+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1050 <loggerStrNDup@plt>
mov    %rax,-0x8(%rbp)
jmp    11a8 <loggerGetFileDir+0x78>
jmp    11a0 <loggerGetFileDir+0x70>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loggerGetFileDir>:
push   %rbx
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1040 <strrchr@plt>
cmp    %rbx,%rax
je     1155 <loggerGetFileDir+0x25>
test   %rax,%rax
je     1162 <loggerGetFileDir+0x32>
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
pop    %rbx
jmp    1050 <loggerStrNDup@plt>
lea    0xea4(%rip),%rdi
pop    %rbx
jmp    1030 <loggerStrDup@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i8* @loggerGetFileDir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strrchr(i8* %5, i8 signext 47)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = load i8*, i8** %3
%9 = icmp eq i8* %7, %8
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i8* @loggerStrDup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %2
br label %26
12: ; preds = %1
%13 = load i8*, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = load i8*, i8** %4
%18 = load i8*, i8** %3
%19 = ptrtoint i8* %17 to i64
%20 = ptrtoint i8* %18 to i64
%21 = sub i64 %19, %20
%22 = trunc i64 %21 to i32
%23 = call i8* @loggerStrNDup(i8* %16, i32 %22)
store i8* %23, i8** %2
br label %26
24: ; preds = %12
br label %25
25: ; preds = %24
store i8* null, i8** %2
br label %26
26: ; preds = %25, %15, %10
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i8* @loggerGetFileDir(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, %0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i8* @loggerStrDup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %14
6: ; preds = %1
%7 = icmp eq i8* %2, null
br i1 %7, label %14, label %8
8: ; preds = %6
%9 = ptrtoint i8* %2 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = tail call i8* @loggerStrNDup(i8* %0, i32 %12)
br label %14
14: ; preds = %6, %8, %4
%15 = phi i8* [ %5, %4 ], [ %13, %8 ], [ null, %6 ]
ret i8* %15
}