#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 *, char);
char *basename(char *path) {
  char *s1;
  char *s2;
  s1 = strrchr(path, '/');
  s2 = strrchr(path, '\\');
  if (s1 && s2) {
    path = (s1 > s2 ? s1 : s2) + 1;
  } else if (s1)
    path = s1 + 1;
  else if (s2)
    path = s2 + 1;
  return path;
}


x86 assembly (clang, -O0):
<basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118a <basename+0x7a>
cmpq   $0x0,-0x18(%rbp)
je     118a <basename+0x7a>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1171 <basename+0x61>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1179 <basename+0x69>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11c7 <basename+0xb7>
cmpq   $0x0,-0x10(%rbp)
je     11a6 <basename+0x96>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <basename+0xb2>
cmpq   $0x0,-0x18(%rbp)
je     11bd <basename+0xad>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <basename+0xb2>
jmp    11c7 <basename+0xb7>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
test   %rbx,%rbx
je     1148 <basename+0x38>
test   %rax,%rax
je     1148 <basename+0x38>
cmp    %rax,%rbx
cmova  %rbx,%rax
add    $0x1,%rax
jmp    1164 <basename+0x54>
test   %rbx,%rbx
je     1156 <basename+0x46>
add    $0x1,%rbx
mov    %rbx,%rax
jmp    1164 <basename+0x54>
lea    0x1(%rax),%rcx
test   %rax,%rax
cmovne %rcx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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