#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 */
int strlen(char const *);
const char *basename(const char *file) {
  const char *base;
  if (!file)
    return NULL;
  for (base = file + strlen(file); base != file; base -= 1) {
    char ch;
    ch = base[-1];
    if ((ch == '/') || (ch == '\\'))
      break;
  }
  return base;
}


x86 assembly (clang, -O0):
<basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <basename+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11aa <basename+0x9a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11a2 <basename+0x92>
mov    -0x18(%rbp),%rax
mov    -0x1(%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x2f,%eax
je     1187 <basename+0x77>
movsbl -0x19(%rbp),%eax
cmp    $0x5c,%eax
jne    118c <basename+0x7c>
jmp    11a2 <basename+0x92>
jmp    1191 <basename+0x81>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1155 <basename+0x45>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename>:
push   %rbx
test   %rdi,%rdi
je     1141 <basename+0x31>
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
test   %rax,%rax
je     1143 <basename+0x33>
movzbl -0x1(%rbx,%rax,1),%ecx
add    $0xffffffffffffffff,%rax
cmp    $0x5c,%cl
je     1138 <basename+0x28>
cmp    $0x2f,%cl
jne    1120 <basename+0x10>
add    %rax,%rbx
add    $0x1,%rbx
jmp    1143 <basename+0x33>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @basename(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, 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
br label %7
7: ; preds = %10, %3
%8 = phi i8* [ %6, %3 ], [ %11, %10 ]
%9 = icmp eq i8* %8, %0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %8, i64 -1
%12 = load i8, i8* %11
switch i8 %12, label %7 [
i8 92, label %13
i8 47, label %13
]
13: ; preds = %10, %10, %7, %1
%14 = phi i8* [ null, %1 ], [ %8, %10 ], [ %8, %10 ], [ %0, %7 ]
ret i8* %14
}