#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
char *strrchr(char const *, char);
void get_base_name(char dst[16], const char *src) {
  const char *tmp;
  int ii;
  memset(dst, 0, 16);
  tmp = strrchr(src, '/');
  if (!tmp) {
    tmp = strrchr(src, '\\');
  }
  if (tmp) {
    tmp++;
  } else {
    tmp = src;
  }
  sprintf(dst, "%.16s", tmp);
  tmp = strrchr(dst, '.');
  if (tmp) {
    for (ii = tmp - dst; ii < 16; ii++) {
      dst[ii] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<get_base_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <get_base_name+0x4f>
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119b <get_base_name+0x6b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a3 <get_base_name+0x73>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe4e(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     120b <get_base_name+0xdb>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    1206 <get_base_name+0xd6>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e2 <get_base_name+0xb2>
jmp    120b <get_base_name+0xdb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_base_name>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
jne    1165 <get_base_name+0x35>
mov    %r14,%rdi
mov    $0x5c,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%rdx
test   %rax,%rax
cmove  %r14,%rdx
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     11b5 <get_base_name+0x85>
mov    %rax,%rcx
sub    %rbx,%rcx
cmp    $0xf,%ecx
jg     11b5 <get_base_name+0x85>
movslq %ecx,%rdi
add    %rbx,%rdi
sub    %eax,%ebx
add    $0xf,%ebx
add    $0x1,%rbx
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <memset@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%.16s\00"
define void @get_base_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @memset(i8* %7, i32 0, i32 16)
%9 = load i8*, i8** %4
%10 = call i8* @strrchr(i8* %9, i8 signext 47)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i8* @strrchr(i8* %14, i8 signext 92)
store i8* %15, i8** %5
br label %16
16: ; preds = %13, %2
%17 = load i8*, i8** %5
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
br label %24
22: ; preds = %16
%23 = load i8*, i8** %4
store i8* %23, i8** %5
br label %24
24: ; preds = %22, %19
%25 = load i8*, i8** %3
%26 = load i8*, i8** %5
%27 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %3
%29 = call i8* @strrchr(i8* %28, i8 signext 46)
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %51
32: ; preds = %24
%33 = load i8*, i8** %5
%34 = load i8*, i8** %3
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %6
br label %39
39: ; preds = %47, %32
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 16
br i1 %41, label %42, label %50
42: ; preds = %39
%43 = load i8*, i8** %3
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 0, i8* %46
br label %47
47: ; preds = %42
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %39
50: ; preds = %39
br label %51
51: ; preds = %50, %24
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%.16s\00"
define void @get_base_name(i8* %0, i8* %1) {
%3 = tail call i32 @memset(i8* %0, i32 0, i32 16)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i8 signext 92)
br label %8
8: ; preds = %6, %2
%9 = phi i8* [ %4, %2 ], [ %7, %6 ]
%10 = icmp eq i8* %9, null
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = select i1 %10, i8* %1, i8* %11
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%15 = icmp ne i8* %14, null
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %0 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = icmp slt i32 %19, 16
%21 = select i1 %15, i1 %20, i1 false
br i1 %21, label %22, label %30
22: ; preds = %8
%23 = shl i64 %18, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr i8, i8* %0, i64 %24
%26 = add i64 %17, 15
%27 = sub i64 %26, %16
%28 = and i64 %27, 4294967295
%29 = add nuw nsw i64 %28, 1
br label %30
30: ; preds = %22, %8
ret void
}