#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 /*<<< orphan*/ free(char *);
char *strdup(char const *);
char *strrchr(char *, char);
const char *get_base_name(const char *path_org) {
  char *p;
  char *path = strdup(path_org);
  p = strrchr(path, '/');
  if (!p) {
    free(path);
    return path_org;
  }
  if (*(p + 1) == 0) {
    *p = 0;
    p--;
    while (*p != '/' && p >= path) {
      *p = 0;
      p--;
    }
    if (p < path)
      return NULL;
  }
  return p + 1;
}


x86 assembly (clang, -O0):
<get_base_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117c <get_base_name+0x4c>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1217 <get_base_name+0xe7>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    120b <get_base_name+0xdb>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x21(%rbp)
je     11c3 <get_base_name+0x93>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
setae  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11d3 <get_base_name+0xa3>
jmp    11eb <get_base_name+0xbb>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11a0 <get_base_name+0x70>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1206 <get_base_name+0xd6>
movq   $0x0,-0x8(%rbp)
jmp    1217 <get_base_name+0xe7>
jmp    120b <get_base_name+0xdb>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_base_name>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1198 <get_base_name+0x68>
cmpb   $0x0,0x1(%rax)
jne    118f <get_base_name+0x5f>
movb   $0x0,(%rax)
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
cmpb   $0x2f,-0x1(%rax)
je     1182 <get_base_name+0x52>
nopw   0x0(%rax,%rax,1)
cmp    %rbx,%rcx
jb     1182 <get_base_name+0x52>
movb   $0x0,(%rcx)
cmpb   $0x2f,-0x1(%rcx)
lea    -0x1(%rcx),%rcx
jne    1170 <get_base_name+0x40>
mov    %rcx,%rax
cmp    %rbx,%rcx
jae    118f <get_base_name+0x5f>
xor    %r14d,%r14d
jmp    11a0 <get_base_name+0x70>
add    $0x1,%rax
mov    %rax,%r14
jmp    11a0 <get_base_name+0x70>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @get_base_name(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 = call i8* @strdup(i8* %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = call i8* @strrchr(i8* %8, i8 signext 47)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = load i8*, i8** %5
%14 = call i32 @free(i8* %13)
%15 = load i8*, i8** %3
store i8* %15, i8** %2
br label %50
16: ; preds = %1
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %47
22: ; preds = %16
%23 = load i8*, i8** %4
store i8 0, i8* %23
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 -1
store i8* %25, i8** %4
br label %26
26: ; preds = %37, %22
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 47
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = icmp uge i8* %32, %33
br label %35
35: ; preds = %31, %26
%36 = phi i1 [ false, %26 ], [ %34, %31 ]
br i1 %36, label %37, label %41
37: ; preds = %35
%38 = load i8*, i8** %4
store i8 0, i8* %38
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i32 -1
store i8* %40, i8** %4
br label %26
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = load i8*, i8** %5
%44 = icmp ult i8* %42, %43
br i1 %44, label %45, label %46
45: ; preds = %41
store i8* null, i8** %2
br label %50
46: ; preds = %41
br label %47
47: ; preds = %46, %16
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i64 1
store i8* %49, i8** %2
br label %50
50: ; preds = %47, %45, %12
%51 = load i8*, i8** %2
ret i8* %51
}

LLVM IR (-O2):
define i8* @get_base_name(i8* %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @free(i8* %2)
br label %30
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %3, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %7
store i8 0, i8* %3
%12 = getelementptr inbounds i8, i8* %3, i64 -1
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 47
%15 = icmp uge i8* %12, %2
%16 = and i1 %14, %15
br i1 %16, label %17, label %24
17: ; preds = %11, %17
%18 = phi i8* [ %19, %17 ], [ %12, %11 ]
store i8 0, i8* %18
%19 = getelementptr inbounds i8, i8* %18, i64 -1
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 47
%22 = icmp uge i8* %19, %2
%23 = and i1 %21, %22
br i1 %23, label %17, label %24
24: ; preds = %17, %11
%25 = phi i8* [ %12, %11 ], [ %19, %17 ]
%26 = icmp ult i8* %25, %2
br i1 %26, label %30, label %27
27: ; preds = %24, %7
%28 = phi i8* [ %25, %24 ], [ %3, %7 ]
%29 = getelementptr inbounds i8, i8* %28, i64 1
br label %30
30: ; preds = %24, %27, %5
%31 = phi i8* [ %29, %27 ], [ %0, %5 ], [ null, %24 ]
ret i8* %31
}