#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 *strrchr(char const *, char);
char *get_filename(const char *fname) {
  char *res, *cb, *cs;
  cb = strrchr(fname, '\\');
  cs = strrchr(fname, '/');
  if (cb == NULL)
    res = cs;
  else if (cs == NULL)
    res = cb;
  else
    res = (cs > cb) ? cs : cb;
  return (res == NULL) ? (char *)fname : ++res;
}


x86 assembly (clang, -O0):
<get_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1158 <get_filename+0x48>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11a0 <get_filename+0x90>
cmpq   $0x0,-0x20(%rbp)
jne    1170 <get_filename+0x60>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    119b <get_filename+0x8b>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    118b <get_filename+0x7b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1193 <get_filename+0x83>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11a0 <get_filename+0x90>
cmpq   $0x0,-0x10(%rbp)
jne    11b8 <get_filename+0xa8>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11c8 <get_filename+0xb8>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rbx,%rbx
je     1147 <get_filename+0x37>
test   %rax,%rax
je     1144 <get_filename+0x34>
cmp    %rbx,%rax
cmovbe %rbx,%rax
jmp    1147 <get_filename+0x37>
mov    %rbx,%rax
lea    0x1(%rax),%rcx
test   %rax,%rax
cmove  %r14,%rcx
mov    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @get_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @strrchr(i8* %6, i8 signext 92)
store i8* %7, i8** %4
%8 = load i8*, i8** %2
%9 = call i8* @strrchr(i8* %8, i8 signext 47)
store i8* %9, i8** %5
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i8*, i8** %5
store i8* %13, i8** %3
br label %30
14: ; preds = %1
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i8*, i8** %4
store i8* %18, i8** %3
br label %29
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = load i8*, i8** %4
%22 = icmp ugt i8* %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load i8*, i8** %5
br label %27
25: ; preds = %19
%26 = load i8*, i8** %4
br label %27
27: ; preds = %25, %23
%28 = phi i8* [ %24, %23 ], [ %26, %25 ]
store i8* %28, i8** %3
br label %29
29: ; preds = %27, %17
br label %30
30: ; preds = %29, %12
%31 = load i8*, i8** %3
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i8*, i8** %2
br label %38
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
br label %38
38: ; preds = %35, %33
%39 = phi i8* [ %34, %33 ], [ %37, %35 ]
ret i8* %39
}

LLVM IR (-O2):
define i8* @get_filename(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %2, null
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = icmp eq i8* %3, null
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = icmp ugt i8* %3, %2
%9 = select i1 %8, i8* %3, i8* %2
br label %10
10: ; preds = %5, %1, %7
%11 = phi i8* [ %9, %7 ], [ %3, %1 ], [ %2, %5 ]
%12 = icmp eq i8* %11, null
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = select i1 %12, i8* %0, i8* %13
ret i8* %14
}