#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 *strdup(char const *);
int strlen(char *);
char *basename_ext(const char *path) {
  char *buf = strdup(path);
  int len = strlen(buf);
  int i;
  for (i = len - 1; i >= 0; i--) {
    if (buf[i] == '.') {
      buf[i] = '\0';
      break;
    }
  }
  return buf;
}


x86 assembly (clang, -O0):
<basename_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1191 <basename_ext+0x71>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    117e <basename_ext+0x5e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1191 <basename_ext+0x71>
jmp    1183 <basename_ext+0x63>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    114e <basename_ext+0x2e>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basename_ext>:
push   %rbx
call   1040 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %eax,%eax
jle    1158 <basename_ext+0x38>
lea    -0x1(%rax),%rcx
cmpb   $0x2e,-0x1(%rbx,%rax,1)
mov    %rcx,%rax
jne    1140 <basename_ext+0x20>
mov    %ecx,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @basename_ext(i8* nocapture %0) {
%2 = tail call i8* @strdup(i8* %0)
%3 = tail call i32 @strlen(i8* %2)
%4 = zext i32 %3 to i64
br label %5
5: ; preds = %10, %1
%6 = phi i64 [ %7, %10 ], [ %4, %1 ]
%7 = add nsw i64 %6, -1
%8 = trunc i64 %6 to i32
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = getelementptr inbounds i8, i8* %2, i64 %7
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 46
br i1 %13, label %14, label %5
14: ; preds = %10
%15 = and i64 %7, 4294967295
%16 = getelementptr inbounds i8, i8* %2, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %5, %14
ret i8* %2
}