#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strrchr(char const *, char);
char *stripFilename(const char *filename, const char *newext) {
  char *last1 = strrchr(filename, '/');
  char *last2 = strrchr(filename, '\\');
  const char *pos = filename;
  char *name;
  char *dot;
  if (last1 > pos)
    pos = last1 + 1;
  if (last2 > pos)
    pos = last2 + 1;
  name = (char *)malloc(strlen(pos) + 2 + (newext ? strlen(newext) : 3));
  strcpy(name, pos);
  dot = strrchr(name, '.');
  if (dot) {
    *dot = 0;
  }
  if (newext)
    strcat(name, newext);
  return name;
}


x86 assembly (clang, -O0):
<stripFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    11a6 <stripFilename+0x56>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    11c0 <stripFilename+0x70>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11eb <stripFilename+0x9b>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
jmp    11f8 <stripFilename+0xa8>
mov    $0x3,%eax
mov    %eax,-0x40(%rbp)
jmp    11f8 <stripFilename+0xa8>
mov    -0x3c(%rbp),%edi
mov    -0x40(%rbp),%eax
add    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x30(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     123a <stripFilename+0xea>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     1252 <stripFilename+0x102>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stripFilename>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1050 <strrchr@plt>
lea    0x1(%r15),%rcx
cmp    %rbx,%r15
cmovbe %rbx,%rcx
lea    0x1(%rax),%r15
cmp    %rcx,%rax
cmovbe %rcx,%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
add    $0x2,%ebx
test   %r14,%r14
je     11a7 <stripFilename+0x57>
mov    %r14,%rdi
call   1040 <strlen@plt>
jmp    11ac <stripFilename+0x5c>
mov    $0x3,%eax
add    %eax,%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11d8 <stripFilename+0x88>
movb   $0x0,(%rax)
test   %r14,%r14
je     11e8 <stripFilename+0x98>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @stripFilename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = load i8*, i8** %3
%11 = call i8* @strrchr(i8* %10, i8 signext 47)
store i8* %11, i8** %5
%12 = load i8*, i8** %3
%13 = call i8* @strrchr(i8* %12, i8 signext 92)
store i8* %13, i8** %6
%14 = load i8*, i8** %3
store i8* %14, i8** %7
%15 = load i8*, i8** %5
%16 = load i8*, i8** %7
%17 = icmp ugt i8* %15, %16
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8* %20, i8** %7
br label %21
21: ; preds = %18, %2
%22 = load i8*, i8** %6
%23 = load i8*, i8** %7
%24 = icmp ugt i8* %22, %23
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 1
store i8* %27, i8** %7
br label %28
28: ; preds = %25, %21
%29 = load i8*, i8** %7
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %30, 2
%32 = load i8*, i8** %4
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i8*, i8** %4
%36 = call i32 @strlen(i8* %35)
br label %38
37: ; preds = %28
br label %38
38: ; preds = %37, %34
%39 = phi i32 [ %36, %34 ], [ 3, %37 ]
%40 = add nsw i32 %31, %39
%41 = call i64 @malloc(i32 %40)
%42 = inttoptr i64 %41 to i8*
store i8* %42, i8** %8
%43 = load i8*, i8** %8
%44 = load i8*, i8** %7
%45 = call i32 @strcpy(i8* %43, i8* %44)
%46 = load i8*, i8** %8
%47 = call i8* @strrchr(i8* %46, i8 signext 46)
store i8* %47, i8** %9
%48 = load i8*, i8** %9
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %38
%51 = load i8*, i8** %9
store i8 0, i8* %51
br label %52
52: ; preds = %50, %38
%53 = load i8*, i8** %4
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = load i8*, i8** %8
%57 = load i8*, i8** %4
%58 = call i32 @strcat(i8* %56, i8* %57)
br label %59
59: ; preds = %55, %52
%60 = load i8*, i8** %8
ret i8* %60
}

LLVM IR (-O2):
define i8* @stripFilename(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
%5 = icmp ugt i8* %3, %0
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = select i1 %5, i8* %6, i8* %0
%8 = icmp ugt i8* %4, %7
%9 = getelementptr inbounds i8, i8* %4, i64 1
%10 = select i1 %8, i8* %9, i8* %7
%11 = tail call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 2
%13 = icmp eq i8* %1, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = tail call i32 @strlen(i8* %1)
br label %16
16: ; preds = %2, %14
%17 = phi i32 [ %15, %14 ], [ 3, %2 ]
%18 = add nsw i32 %12, %17
%19 = tail call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = tail call i32 @strcpy(i8* %20, i8* %10)
%22 = tail call i8* @strrchr(i8* dereferenceable(1) %20, i8 signext 46)
%23 = icmp eq i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %16
store i8 0, i8* %22
br label %25
25: ; preds = %24, %16
br i1 %13, label %28, label %26
26: ; preds = %25
%27 = tail call i32 @strcat(i8* %20, i8* %1)
br label %28
28: ; preds = %26, %25
ret i8* %20
}