#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 *malloc(int);
int /*<<< orphan*/ strcat(char *, char *const);
int strlen(char *const);
int /*<<< orphan*/ strncpy(char *, char *const, int);
char *strrchr(char *const, char);
char *change_extension(char *const filePath, char *const newEstension) {
  char *dest;
  char *temp = strrchr(filePath, '.');
  if (temp) {
    dest = malloc(strlen(filePath) + strlen(newEstension) - strlen(temp));
    strncpy(dest, filePath, temp - filePath);
  } else {
    dest = malloc(strlen(filePath) + strlen(newEstension));
    strncpy(dest, filePath, strlen(filePath));
  }
  strcat(dest, newEstension);
  return dest;
}


x86 assembly (clang, -O0):
<change_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d2 <change_extension+0x82>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
sub    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
jmp    121d <change_extension+0xcd>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
add    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_extension>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    %r12d,%ebp
test   %rbx,%rbx
je     11a9 <change_extension+0x59>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
sub    %r15d,%ebx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
jmp    11c3 <change_extension+0x73>
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @change_extension(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 46)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %30
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
%19 = sub nsw i32 %16, %18
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = load i8*, i8** %3
%23 = load i8*, i8** %6
%24 = load i8*, i8** %3
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = trunc i64 %27 to i32
%29 = call i32 @strncpy(i8* %21, i8* %22, i32 %28)
br label %42
30: ; preds = %2
%31 = load i8*, i8** %3
%32 = call i32 @strlen(i8* %31)
%33 = load i8*, i8** %4
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %32, %34
%36 = call i8* @malloc(i32 %35)
store i8* %36, i8** %5
%37 = load i8*, i8** %5
%38 = load i8*, i8** %3
%39 = load i8*, i8** %3
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @strncpy(i8* %37, i8* %38, i32 %40)
br label %42
42: ; preds = %30, %11
%43 = load i8*, i8** %5
%44 = load i8*, i8** %4
%45 = call i32 @strcat(i8* %43, i8* %44)
%46 = load i8*, i8** %5
ret i8* %46
}

LLVM IR (-O2):
define i8* @change_extension(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 @strlen(i8* %1)
%7 = add nsw i32 %6, %5
br i1 %4, label %17, label %8
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %3)
%10 = sub i32 %7, %9
%11 = tail call i8* @malloc(i32 %10)
%12 = ptrtoint i8* %3 to i64
%13 = ptrtoint i8* %0 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = tail call i32 @strncpy(i8* %11, i8* %0, i32 %15)
br label %21
17: ; preds = %2
%18 = tail call i8* @malloc(i32 %7)
%19 = tail call i32 @strlen(i8* %0)
%20 = tail call i32 @strncpy(i8* %18, i8* %0, i32 %19)
br label %21
21: ; preds = %17, %8
%22 = phi i8* [ %11, %8 ], [ %18, %17 ]
%23 = tail call i32 @strcat(i8* %22, i8* %1)
ret i8* %22
}