#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 *strchr(char *, int /*<<< orphan*/);
char *strrchr(char *, char);
void opt_basename(char *fn, char sep) {
  char *loc;
  if (!sep)
    sep = '/';
  loc = strrchr(fn, sep);
  if (!loc)
    return;
  if (!loc[1]) {
    *loc = 0;
    loc = strrchr(fn, sep);
    *strchr(fn, 0) = sep;
    if (!loc)
      return;
  }
  while ((*fn++ = *++loc))
    ;
}


x86 assembly (clang, -O0):
<opt_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
cmpb   $0x0,-0x9(%rbp)
jne    1140 <opt_basename+0x20>
movb   $0x2f,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1161 <opt_basename+0x41>
jmp    11e7 <opt_basename+0xc7>
mov    -0x18(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    11b2 <opt_basename+0x92>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
movsbl -0x9(%rbp),%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x9(%rbp),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
mov    -0x19(%rbp),%cl
mov    %cl,(%rax)
cmpq   $0x0,-0x18(%rbp)
jne    11ad <opt_basename+0x8d>
jmp    11e7 <opt_basename+0xc7>
jmp    11b2 <opt_basename+0x92>
jmp    11b7 <opt_basename+0x97>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    0x1(%rax),%al
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     11e7 <opt_basename+0xc7>
jmp    11b7 <opt_basename+0x97>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_basename>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
test   %sil,%sil
mov    $0x2f,%ebp
cmovne %esi,%ebp
mov    %ebp,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1181 <opt_basename+0x61>
mov    %rax,%rbx
cmpb   $0x0,0x1(%rax)
jne    116c <opt_basename+0x4c>
movb   $0x0,(%rbx)
movsbl %bpl,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <strrchr@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %bpl,(%r14,%rax,1)
test   %rbx,%rbx
je     1181 <opt_basename+0x61>
xor    %eax,%eax
xchg   %ax,%ax
movzbl 0x1(%rbx,%rax,1),%ecx
mov    %cl,(%r14,%rax,1)
add    $0x1,%rax
test   %cl,%cl
jne    1170 <opt_basename+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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