#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 const *);
char *loggerStrNDup(char const *, int);
char *strrchr(char const *, char);
char *loggerGetFileName(const char *absPath_, int withoutExt_) {
  const char *fileName = strrchr(absPath_, '/');
  if (!fileName || fileName[1] == 0) {
    return NULL;
  }
  ++fileName;
  if (withoutExt_) {
    const char *extpos = strrchr(fileName, '.');
    if (extpos) {
      return loggerStrNDup(fileName, extpos - fileName);
    }
  }
  return loggerStrDup(fileName);
}


x86 assembly (clang, -O0):
<loggerGetFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     116d <loggerGetFileName+0x3d>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    117a <loggerGetFileName+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    11de <loggerGetFileName+0xae>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d1 <loggerGetFileName+0xa1>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cc <loggerGetFileName+0x9c>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1050 <loggerStrNDup@plt>
mov    %rax,-0x8(%rbp)
jmp    11de <loggerGetFileName+0xae>
jmp    11d1 <loggerGetFileName+0xa1>
mov    -0x20(%rbp),%rdi
call   1030 <loggerStrDup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loggerGetFileName>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1179 <loggerGetFileName+0x49>
mov    %rax,%rbx
cmpb   $0x0,0x1(%rax)
je     1179 <loggerGetFileName+0x49>
add    $0x1,%rbx
test   %ebp,%ebp
je     1182 <loggerGetFileName+0x52>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1182 <loggerGetFileName+0x52>
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <loggerStrNDup@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <loggerStrDup@plt>

LLVM IR (-O0):
define i8* @loggerGetFileName(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = call i8* @strrchr(i8* %8, i8 signext 47)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12, %2
store i8* null, i8** %3
br label %42
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %39
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = call i8* @strrchr(i8* %25, i8 signext 46)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %38
29: ; preds = %24
%30 = load i8*, i8** %6
%31 = load i8*, i8** %7
%32 = load i8*, i8** %6
%33 = ptrtoint i8* %31 to i64
%34 = ptrtoint i8* %32 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
%37 = call i8* @loggerStrNDup(i8* %30, i32 %36)
store i8* %37, i8** %3
br label %42
38: ; preds = %24
br label %39
39: ; preds = %38, %19
%40 = load i8*, i8** %6
%41 = call i8* @loggerStrDup(i8* %40)
store i8* %41, i8** %3
br label %42
42: ; preds = %39, %29, %18
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
define i8* @loggerGetFileName(i8* %0, i32 %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %5
%10 = icmp eq i32 %1, 0
br i1 %10, label %20, label %11
11: ; preds = %9
%12 = tail call i8* @strrchr(i8* %6, i8 signext 46)
%13 = icmp eq i8* %12, null
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = ptrtoint i8* %12 to i64
%16 = ptrtoint i8* %6 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = tail call i8* @loggerStrNDup(i8* %6, i32 %18)
br label %22
20: ; preds = %11, %9
%21 = tail call i8* @loggerStrDup(i8* %6)
br label %22
22: ; preds = %14, %2, %5, %20
%23 = phi i8* [ %21, %20 ], [ %19, %14 ], [ null, %5 ], [ null, %2 ]
ret i8* %23
}