#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 *basename(char *);
size_t strlen(char *);
const char *strip_name(char *path) {
  char *name = basename(path);
  size_t len = strlen(name);
  if (len > 2 && name[len - 1] == 'c' && name[len - 2] == '.')
    name[len - 2] = '\0';
  return name;
}


x86 assembly (clang, -O0):
<strip_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <basename@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x2,-0x18(%rbp)
jbe    1193 <strip_name+0x73>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x63,%eax
jne    1193 <strip_name+0x73>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x2,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1193 <strip_name+0x73>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x2,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_name>:
push   %rbx
call   1040 <basename@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
cmp    $0x3,%rax
jb     114a <strip_name+0x2a>
cmpb   $0x63,-0x1(%rax,%rbx,1)
jne    114a <strip_name+0x2a>
cmpb   $0x2e,-0x2(%rax,%rbx,1)
jne    114a <strip_name+0x2a>
movb   $0x0,-0x2(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @strip_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @basename(i8* %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = icmp ugt i64 %9, 2
br i1 %10, label %11, label %32
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = sub i64 %13, 1
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 99
br i1 %18, label %19, label %32
19: ; preds = %11
%20 = load i8*, i8** %3
%21 = load i64, i64* %4
%22 = sub i64 %21, 2
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 46
br i1 %26, label %27, label %32
27: ; preds = %19
%28 = load i8*, i8** %3
%29 = load i64, i64* %4
%30 = sub i64 %29, 2
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %27, %19, %11, %1
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
define i8* @strip_name(i8* %0) {
%2 = tail call i8* @basename(i8* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%4 = icmp ugt i64 %3, 2
br i1 %4, label %5, label %16
5: ; preds = %1
%6 = add i64 %3, -1
%7 = getelementptr inbounds i8, i8* %2, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 99
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = add i64 %3, -2
%12 = getelementptr inbounds i8, i8* %2, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 46
br i1 %14, label %15, label %16
15: ; preds = %10
store i8 0, i8* %12
br label %16
16: ; preds = %15, %10, %5, %1
ret i8* %2
}