#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 */
typedef int /*<<< orphan*/ base;

/* Variables and functions */
char const *base_name(char const *);
scalar_t__ strcmp(char *, char const *);
size_t strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
const char *base_name_sans(const char *name, const char *suffix) {
  static char base[256];
  size_t blen, slen;
  if (!name)
    return NULL;
  if (!suffix)
    return base_name(name);
  (strncpy((base), (base_name(name)), (sizeof(base) - 1)));
  blen = strlen(base);
  slen = strlen(suffix);
  if (blen >= slen && strcmp(base + blen - slen, suffix) == 0)
    base[blen - slen] = '\0';
  return base;
}


x86 assembly (clang, -O0):
<base_name_sans>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1168 <base_name_sans+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1212 <base_name_sans+0xd2>
cmpq   $0x0,-0x18(%rbp)
jne    1185 <base_name_sans+0x45>
mov    -0x10(%rbp),%rdi
call   1050 <base_name@plt>
mov    %rax,-0x8(%rbp)
jmp    1212 <base_name_sans+0xd2>
mov    -0x10(%rbp),%rdi
call   1050 <base_name@plt>
mov    %rax,%rsi
lea    0x2eb8(%rip),%rdi
mov    $0xff,%edx
call   1030 <strncpy@plt>
lea    0x2ea7(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     1207 <base_name_sans+0xc7>
lea    0x2e7c(%rip),%rdi
add    -0x20(%rbp),%rdi
xor    %eax,%eax
sub    -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1207 <base_name_sans+0xc7>
mov    -0x20(%rbp),%rcx
sub    -0x28(%rbp),%rcx
lea    0x2e4d(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e42(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base_name_sans>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     11bf <base_name_sans+0x7f>
mov    %rsi,%r14
call   1050 <base_name@plt>
mov    %rax,%rbx
test   %r14,%r14
je     11c1 <base_name_sans+0x81>
lea    0x2eeb(%rip),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0xff,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r15,%r13
mov    %r12,%rbx
sub    %rax,%r13
jb     11c1 <base_name_sans+0x81>
lea    0x2eb6(%rip),%rbx
add    %rbx,%r15
sub    %rax,%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11c1 <base_name_sans+0x81>
lea    0x2e99(%rip),%rbx
movb   $0x0,0x0(%r13,%rbx,1)
jmp    11c1 <base_name_sans+0x81>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@base_name_sans.base = internal global [256 x i8] zeroinitializer
define i8* @base_name_sans(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %2
store i8* null, i8** %3
br label %42
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = call i8* @base_name(i8* %15)
store i8* %16, i8** %3
br label %42
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i8* @base_name(i8* %18)
%20 = call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 0), i8* %19, i32 255)
%21 = call i64 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 0))
store i64 %21, i64* %6
%22 = load i8*, i8** %5
%23 = call i64 @strlen(i8* %22)
store i64 %23, i64* %7
%24 = load i64, i64* %6
%25 = load i64, i64* %7
%26 = icmp uge i64 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %17
%28 = load i64, i64* %6
%29 = getelementptr inbounds i8, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 0), i64 %28
%30 = load i64, i64* %7
%31 = sub i64 0, %30
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8*, i8** %5
%34 = call i64 @strcmp(i8* %32, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %27
%37 = load i64, i64* %6
%38 = load i64, i64* %7
%39 = sub i64 %37, %38
%40 = getelementptr inbounds [256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %36, %27, %17
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 0), i8** %3
br label %42
42: ; preds = %41, %14, %10
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@base_name_sans.base = internal global [256 x i8] zeroinitializer
define i8* @base_name_sans(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %21, label %4
4: ; preds = %2
%5 = icmp eq i8* %1, null
%6 = tail call i8* @base_name(i8* %0)
br i1 %5, label %21, label %7
7: ; preds = %4
%8 = tail call i32 @strncpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 0), i8* %6, i32 255)
%9 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 0))
%10 = tail call i64 @strlen(i8* %1)
%11 = icmp ult i64 %9, %10
br i1 %11, label %21, label %12
12: ; preds = %7
%13 = getelementptr inbounds [256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 %9
%14 = sub i64 0, %10
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = tail call i64 @strcmp(i8* %15, i8* %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = sub i64 %9, %10
%20 = getelementptr inbounds [256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %4, %7, %12, %18, %2
%22 = phi i8* [ null, %2 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 0), %18 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 0), %12 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @base_name_sans.base, i64 0, i64 0), %7 ], [ %6, %4 ]
ret i8* %22
}