#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__ ajMemFree(void **);
char *ajSysFuncStrdup(char const *);
char *ajSysFuncStrtok(char *, char const *);
scalar_t__ strcmp(char const *, char const *);
int strlen(char const *);
char *messGetFilename(const char *path) {
  static char *path_copy = NULL;
  const char *path_delim = "\\";
  char *result = NULL;
  char *tmp;
  if (path != NULL) {
    if (strcmp((path + strlen(path) - 1), path_delim) != 0) {
      if (path_copy != NULL)
        ((void)(ajMemFree((void **)&path_copy)));
      path_copy = ajSysFuncStrdup(path);
      tmp = ajSysFuncStrtok(path_copy, path_delim);
      while (tmp != NULL) {
        result = tmp;
        tmp = ajSysFuncStrtok(NULL, path_delim);
      }
    }
  }
  return (result);
}


x86 assembly (clang, -O0):
<messGetFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rax
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     121c <messGetFilename+0xcc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xffffffffffffffff,%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1217 <messGetFilename+0xc7>
cmpq   $0x0,0x2e9d(%rip)
je     11c5 <messGetFilename+0x75>
lea    0x2e90(%rip),%rdi
call   1060 <ajMemFree@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ajSysFuncStrdup@plt>
mov    %rax,0x2e7b(%rip)
mov    0x2e74(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ajSysFuncStrtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1212 <messGetFilename+0xc2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1030 <ajSysFuncStrtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11e9 <messGetFilename+0x99>
jmp    1217 <messGetFilename+0xc7>
jmp    121c <messGetFilename+0xcc>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<messGetFilename>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11d4 <messGetFilename+0x84>
mov    %rdi,%rbx
call   1050 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe8e(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11d4 <messGetFilename+0x84>
cmpq   $0x0,0x2ecc(%rip)
je     1192 <messGetFilename+0x42>
lea    0x2ec3(%rip),%rdi
call   1060 <ajMemFree@plt>
mov    %rbx,%rdi
call   1040 <ajSysFuncStrdup@plt>
mov    %rax,0x2eaf(%rip)
lea    0xe58(%rip),%rsi
mov    %rax,%rdi
call   1030 <ajSysFuncStrtok@plt>
test   %rax,%rax
je     11d4 <messGetFilename+0x84>
lea    0xe44(%rip),%r14
nopl   0x0(%rax)
mov    %rax,%rbx
xor    %edi,%edi
mov    %r14,%rsi
call   1030 <ajSysFuncStrtok@plt>
test   %rax,%rax
jne    11c0 <messGetFilename+0x70>
jmp    11d6 <messGetFilename+0x86>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@messGetFilename.path_copy = internal global i8* null
@.str = [2 x i8] c"\\\00"
define i8* @messGetFilename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* null, i8** %4
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %38
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8*, i8** %3
%16 = call i64 @strcmp(i8* %14, i8* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %8
%19 = load i8*, i8** @messGetFilename.path_copy
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i64 @ajMemFree(i8** @messGetFilename.path_copy)
br label %23
23: ; preds = %21, %18
%24 = load i8*, i8** %2
%25 = call i8* @ajSysFuncStrdup(i8* %24)
store i8* %25, i8** @messGetFilename.path_copy
%26 = load i8*, i8** @messGetFilename.path_copy
%27 = load i8*, i8** %3
%28 = call i8* @ajSysFuncStrtok(i8* %26, i8* %27)
store i8* %28, i8** %5
br label %29
29: ; preds = %32, %23
%30 = load i8*, i8** %5
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8*, i8** %5
store i8* %33, i8** %4
%34 = load i8*, i8** %3
%35 = call i8* @ajSysFuncStrtok(i8* null, i8* %34)
store i8* %35, i8** %5
br label %29
36: ; preds = %29
br label %37
37: ; preds = %36, %8
br label %38
38: ; preds = %37, %1
%39 = load i8*, i8** %4
ret i8* %39
}

LLVM IR (-O2):
@messGetFilename.path_copy = internal global i8* null
@.str = [2 x i8] c"\\\00"
define i8* @messGetFilename(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %3
%11 = load i8*, i8** @messGetFilename.path_copy
%12 = icmp eq i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i64 @ajMemFree(i8** @messGetFilename.path_copy)
br label %15
15: ; preds = %13, %10
%16 = tail call i8* @ajSysFuncStrdup(i8* %0)
store i8* %16, i8** @messGetFilename.path_copy
%17 = tail call i8* @ajSysFuncStrtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %15, %19
%20 = phi i8* [ %21, %19 ], [ %17, %15 ]
%21 = tail call i8* @ajSysFuncStrtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %19
23: ; preds = %19, %15, %3, %1
%24 = phi i8* [ null, %3 ], [ null, %1 ], [ null, %15 ], [ %20, %19 ]
ret i8* %24
}