#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*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *stripext(char *dst, const char *filename) {
  const char *p = filename + strlen(filename) - 1;
  for (; p > filename; --p) {
    if (*p == '.') {
      size_t size = p - filename;
      memcpy(dst, filename, size - 1);
      dst[size - 1] = 0;
      return dst;
    }
  }
  strcpy(dst, filename);
  return dst;
}


x86 assembly (clang, -O0):
<stripext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11da <stripext+0xaa>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11c4 <stripext+0x94>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ef <stripext+0xbf>
jmp    11c9 <stripext+0x99>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    1165 <stripext+0x35>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripext>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
add    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rax
cmp    %r15,%rax
jbe    1177 <stripext+0x47>
add    $0xffffffffffffffff,%rbx
cmpb   $0x2e,(%rax)
jne    1150 <stripext+0x20>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
movb   $0x0,(%r14,%rbx,1)
jmp    1182 <stripext+0x52>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @stripext(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strlen(i8* %9)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %8, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
store i8* %13, i8** %6
br label %14
14: ; preds = %40, %2
%15 = load i8*, i8** %6
%16 = load i8*, i8** %5
%17 = icmp ugt i8* %15, %16
br i1 %17, label %18, label %43
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 46
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = load i8*, i8** %6
%25 = load i8*, i8** %5
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
store i64 %28, i64* %7
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = load i64, i64* %7
%32 = sub i64 %31, 1
%33 = call i32 @memcpy(i8* %29, i8* %30, i64 %32)
%34 = load i8*, i8** %4
%35 = load i64, i64* %7
%36 = sub i64 %35, 1
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %4
store i8* %38, i8** %3
br label %48
39: ; preds = %18
br label %40
40: ; preds = %39
%41 = load i8*, i8** %6
%42 = getelementptr inbounds i8, i8* %41, i32 -1
store i8* %42, i8** %6
br label %14
43: ; preds = %14
%44 = load i8*, i8** %4
%45 = load i8*, i8** %5
%46 = call i32 @strcpy(i8* %44, i8* %45)
%47 = load i8*, i8** %4
store i8* %47, i8** %3
br label %48
48: ; preds = %43, %23
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
define i8* @stripext(i8* returned %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %1, i64 %4
br label %6
6: ; preds = %10, %2
%7 = phi i8* [ %5, %2 ], [ %8, %10 ]
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = icmp ugt i8* %8, %1
br i1 %9, label %10, label %20
10: ; preds = %6
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 46
br i1 %12, label %13, label %6
13: ; preds = %10
%14 = ptrtoint i8* %8 to i64
%15 = ptrtoint i8* %1 to i64
%16 = xor i64 %15, -1
%17 = add i64 %14, %16
%18 = tail call i32 @memcpy(i8* %0, i8* %1, i64 %17)
%19 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 0, i8* %19
br label %22
20: ; preds = %6
%21 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %22
22: ; preds = %20, %13
ret i8* %0
}