#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 *getfilename(char *);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
void truncfileext(char *path) {
  char *i = getfilename(path);
  char *ext = strrchr(i, '.');
  if (ext)
    memmove(path, ext + 1, strlen(ext + 1) + 1);
  else
    path[0] = 0;
}


x86 assembly (clang, -O0):
<truncfileext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getfilename@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b0 <truncfileext+0x70>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1060 <memmove@plt>
jmp    11b7 <truncfileext+0x77>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<truncfileext>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <getfilename@plt>
mov    %rax,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     1183 <truncfileext+0x43>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <memmove@plt>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @truncfileext(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @getfilename(i8* %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strrchr(i8* %7, i8 signext 46)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %20
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = call i32 @memmove(i8* %12, i8* %14, i64 %18)
br label %23
20: ; preds = %1
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 0
store i8 0, i8* %22
br label %23
23: ; preds = %20, %11
ret void
}

LLVM IR (-O2):
define void @truncfileext(i8* %0) {
%2 = tail call i8* @getfilename(i8* %0)
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = tail call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 1
%9 = tail call i32 @memmove(i8* %0, i8* %6, i64 %8)
br label %11
10: ; preds = %1
store i8 0, i8* %0
br label %11
11: ; preds = %10, %5
ret void
}