#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 *simple_basename(const char *name) {
  const char *p;
  p = name + strlen(name) - 1;
  while (*p == '/') {
    if (p == name)
      return name;
    p--;
  }
  while (p != name) {
    if (*p == '/')
      return p + 1;
    p--;
  }
  return name;
}


x86 assembly (clang, -O0):
<simple_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    117d <simple_basename+0x6d>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    116c <simple_basename+0x5c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ca <simple_basename+0xba>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1141 <simple_basename+0x31>
jmp    1182 <simple_basename+0x72>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11c2 <simple_basename+0xb2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    11b1 <simple_basename+0xa1>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11ca <simple_basename+0xba>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1182 <simple_basename+0x72>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<simple_basename>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rbx,%rax,1),%ecx
cmp    $0x2f,%cl
jne    1132 <simple_basename+0x22>
add    $0xffffffffffffffff,%rax
jne    1120 <simple_basename+0x10>
jmp    1167 <simple_basename+0x57>
cmp    $0x1,%rax
je     1167 <simple_basename+0x57>
cmp    $0x2f,%cl
jne    1150 <simple_basename+0x40>
add    %rax,%rbx
jmp    1167 <simple_basename+0x57>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x2,%rax
je     1167 <simple_basename+0x57>
lea    -0x1(%rax),%rcx
cmpb   $0x2f,-0x2(%rbx,%rax,1)
mov    %rcx,%rax
jne    1150 <simple_basename+0x40>
add    %rcx,%rbx
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @simple_basename(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
br label %5
5: ; preds = %14, %1
%6 = phi i8* [ %4, %1 ], [ %7, %14 ]
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
%10 = icmp eq i8* %7, %0
br i1 %9, label %14, label %11
11: ; preds = %5
br i1 %10, label %22, label %12
12: ; preds = %11
%13 = icmp eq i8 %8, 47
br i1 %13, label %22, label %15
14: ; preds = %5
br i1 %10, label %22, label %5
15: ; preds = %12, %19
%16 = phi i8* [ %17, %19 ], [ %7, %12 ]
%17 = getelementptr inbounds i8, i8* %16, i64 -1
%18 = icmp eq i8* %17, %0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i8, i8* %17
%21 = icmp eq i8 %20, 47
br i1 %21, label %22, label %15
22: ; preds = %14, %15, %19, %12, %11
%23 = phi i8* [ %0, %11 ], [ %6, %12 ], [ %0, %15 ], [ %16, %19 ], [ %0, %14 ]
ret i8* %23
}