#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 *filename_remove_path(const char *filename_in) {
  char *filename_out = (char *)filename_in;
  if (filename_in) {
    filename_out = strrchr(filename_in, '\\');
    if (!filename_out) {
      filename_out = strrchr(filename_in, '/');
    }
    if (filename_out) {
      filename_out++;
    } else {
      filename_out = (char *)filename_in;
    }
  }
  return filename_out;
}


x86 assembly (clang, -O0):
<filename_remove_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1187 <filename_remove_path+0x77>
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115e <filename_remove_path+0x4e>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117a <filename_remove_path+0x6a>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1182 <filename_remove_path+0x72>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1187 <filename_remove_path+0x77>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename_remove_path>:
test   %rdi,%rdi
je     1145 <filename_remove_path+0x35>
push   %rbx
mov    %rdi,%rbx
mov    $0x5c,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
jne    1135 <filename_remove_path+0x25>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmove  %rbx,%rcx
pop    %rbx
mov    %rcx,%rax
ret
xor    %ecx,%ecx
mov    %rcx,%rax
ret

LLVM IR (-O0):
define i8* @filename_remove_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %24
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i8* @strrchr(i8* %8, i8 signext 92)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = load i8*, i8** %2
%14 = call i8* @strrchr(i8* %13, i8 signext 47)
store i8* %14, i8** %3
br label %15
15: ; preds = %12, %7
%16 = load i8*, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
br label %23
21: ; preds = %15
%22 = load i8*, i8** %2
store i8* %22, i8** %3
br label %23
23: ; preds = %21, %18
br label %24
24: ; preds = %23, %1
%25 = load i8*, i8** %3
ret i8* %25
}

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