#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 *, char, int);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
void __CT_basename(char const *path, char *dest) {
  const char *string = strrchr(path, '/');
  int longFic = 0;
  if (dest == NULL)
    return;
  if (!string) {
    string = strrchr(path, '\\');
    if (!string) {
      string = path;
    } else {
      string++;
    }
  } else {
    string++;
  }
  longFic = strlen(string);
  memset(dest, '\0', 25 + 1);
  if (longFic > 25) {
    strncpy(dest, string, 25);
  } else {
    strncpy(dest, string, longFic);
  }
}


x86 assembly (clang, -O0):
<__CT_basename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <__CT_basename+0x39>
jmp    1218 <__CT_basename+0xd8>
cmpq   $0x0,-0x18(%rbp)
jne    11bf <__CT_basename+0x7f>
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ae <__CT_basename+0x6e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ba <__CT_basename+0x7a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11cb <__CT_basename+0x8b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x1a,%edx
call   1060 <memset@plt>
cmpl   $0x19,-0x1c(%rbp)
jle    1208 <__CT_basename+0xc8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x19,%edx
call   1030 <strncpy@plt>
jmp    1218 <__CT_basename+0xd8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__CT_basename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %r14,%r14
je     116a <__CT_basename+0x2a>
mov    %rax,%rbx
test   %rax,%rax
je     1175 <__CT_basename+0x35>
add    $0x1,%rbx
jmp    118d <__CT_basename+0x4d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x1a,%edx
call   1060 <memset@plt>
cmp    $0x19,%ebp
mov    $0x19,%edx
cmovl  %ebp,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strncpy@plt>

LLVM IR (-O0):
define void @__CT_basename(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 i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %5
store i32 0, i32* %6
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
br label %45
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %26, label %15
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = call i8* @strrchr(i8* %16, i8 signext 92)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %15
%21 = load i8*, i8** %3
store i8* %21, i8** %5
br label %25
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %5
br label %25
25: ; preds = %22, %20
br label %29
26: ; preds = %12
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
br label %29
29: ; preds = %26, %25
%30 = load i8*, i8** %5
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %6
%32 = load i8*, i8** %4
%33 = call i32 @memset(i8* %32, i8 signext 0, i32 26)
%34 = load i32, i32* %6
%35 = icmp sgt i32 %34, 25
br i1 %35, label %36, label %40
36: ; preds = %29
%37 = load i8*, i8** %4
%38 = load i8*, i8** %5
%39 = call i32 @strncpy(i8* %37, i8* %38, i32 25)
br label %45
40: ; preds = %29
%41 = load i8*, i8** %4
%42 = load i8*, i8** %5
%43 = load i32, i32* %6
%44 = call i32 @strncpy(i8* %41, i8* %42, i32 %43)
br label %45
45: ; preds = %11, %40, %36
ret void
}

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