#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 */
size_t FILENAME_MAX;
size_t strnlen(char const *, size_t);
const char *basename(const char *file) {
  const char *base;
  size_t len;
  if (!file)
    return NULL;
  len = strnlen(file, FILENAME_MAX);
  if (FILENAME_MAX <= len)
    return NULL;
  for (base = file + len; 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    11cd <basename+0xbd>
mov    -0x10(%rbp),%rdi
mov    0x2ea9(%rip),%rax
mov    (%rax),%rsi
call   1030 <strnlen@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
ja     116c <basename+0x5c>
movq   $0x0,-0x8(%rbp)
jmp    11cd <basename+0xbd>
mov    -0x10(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11c5 <basename+0xb5>
mov    -0x18(%rbp),%rax
mov    -0x1(%rax),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x2f,%eax
je     11aa <basename+0x9a>
movsbl -0x21(%rbp),%eax
cmp    $0x5c,%eax
jne    11af <basename+0x9f>
jmp    11c5 <basename+0xb5>
jmp    11b4 <basename+0xa4>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1178 <basename+0x68>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1161 <basename+0x51>
mov    %rdi,%rbx
mov    0x2ec5(%rip),%rax
mov    (%rax),%r14
mov    %r14,%rsi
call   1030 <strnlen@plt>
cmp    %rax,%r14
jbe    1161 <basename+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %rax,%rax
je     1163 <basename+0x53>
movzbl -0x1(%rbx,%rax,1),%ecx
add    $0xffffffffffffffff,%rax
cmp    $0x5c,%cl
je     1158 <basename+0x48>
cmp    $0x2f,%cl
jne    1140 <basename+0x30>
add    %rax,%rbx
add    $0x1,%rbx
jmp    1163 <basename+0x53>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@FILENAME_MAX = global i64 0
define i8* @basename(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = load i64, i64* @FILENAME_MAX
%5 = tail call i64 @strnlen(i8* %0, i64 %4)
%6 = icmp ugt i64 %4, %5
br i1 %6, label %7, label %15
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %0, i64 %5
br label %9
9: ; preds = %12, %7
%10 = phi i8* [ %8, %7 ], [ %13, %12 ]
%11 = icmp eq i8* %10, %0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %10, i64 -1
%14 = load i8, i8* %13
switch i8 %14, label %9 [
i8 92, label %15
i8 47, label %15
]
15: ; preds = %12, %12, %9, %3, %1
%16 = phi i8* [ null, %1 ], [ null, %3 ], [ %10, %12 ], [ %10, %12 ], [ %0, %9 ]
ret i8* %16
}