#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
char *changefileext(char *szPath, char *ext) {
  char *pFile = strrchr(szPath, '/');
  pFile = pFile == NULL ? szPath : pFile + 1;
  char *pExt = strrchr(pFile, '.');
  if (pExt != NULL)
    strcpy(pExt, ext);
  else
    strcat(pFile, ext);
  return pFile;
}


x86 assembly (clang, -O0):
<changefileext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116a <changefileext+0x3a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1176 <changefileext+0x46>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ad <changefileext+0x7d>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11ba <changefileext+0x8a>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changefileext>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2f,%esi
call   1040 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r15,%rbx
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     116f <changefileext+0x3f>
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    117a <changefileext+0x4a>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @changefileext(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = load i8*, i8** %3
br label %16
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 1
br label %16
16: ; preds = %13, %11
%17 = phi i8* [ %12, %11 ], [ %15, %13 ]
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = call i8* @strrchr(i8* %18, i8 signext 46)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i8*, i8** %6
%24 = load i8*, i8** %4
%25 = call i32 @strcpy(i8* %23, i8* %24)
br label %30
26: ; preds = %16
%27 = load i8*, i8** %5
%28 = load i8*, i8** %4
%29 = call i32 @strcat(i8* %27, i8* %28)
br label %30
30: ; preds = %26, %22
%31 = load i8*, i8** %5
ret i8* %31
}

LLVM IR (-O2):
define i8* @changefileext(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = icmp eq i8* %3, null
%5 = getelementptr inbounds i8, i8* %3, i64 1
%6 = select i1 %4, i8* %0, i8* %5
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %6, i8 signext 46)
%8 = icmp eq i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @strcpy(i8* %7, i8* %1)
br label %13
11: ; preds = %2
%12 = tail call i32 @strcat(i8* %6, i8* %1)
br label %13
13: ; preds = %11, %9
ret i8* %6
}