#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*/ mhs_free(char *);
char *mhs_strconcat(char *, char *, char const *, int /*<<< orphan*/ *);
char *mhs_strdup(char const *);
char *strrchr(char *, char);
char *change_file_ext(const char *file_name, const char *ext) {
  char *last_period, *tmp, *new_filename;
  tmp = mhs_strdup(file_name);
  last_period = strrchr(tmp, '.');
  if (last_period)
    *last_period = '\0';
  new_filename = mhs_strconcat(tmp, ".", ext, NULL);
  do {
    if ((tmp)) {
      mhs_free((tmp));
      (tmp) = NULL;
    }
  } while (0);
  return (new_filename);
}


x86 assembly (clang, -O0):
<change_file_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <mhs_strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1181 <change_file_ext+0x41>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe70(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <mhs_strconcat@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b9 <change_file_ext+0x79>
mov    -0x20(%rbp),%rdi
call   1050 <mhs_free@plt>
movq   $0x0,-0x20(%rbp)
jmp    11be <change_file_ext+0x7e>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_file_ext>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1040 <mhs_strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2e,%esi
call   1030 <strrchr@plt>
test   %rax,%rax
je     1164 <change_file_ext+0x24>
movb   $0x0,(%rax)
lea    0xe95(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1060 <mhs_strconcat@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1188 <change_file_ext+0x48>
mov    %rbx,%rdi
call   1050 <mhs_free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @change_file_ext(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i8* @mhs_strdup(i8* %8)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i8* @strrchr(i8* %10, i8 signext 46)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = load i8*, i8** %5
store i8 0, i8* %15
br label %16
16: ; preds = %14, %2
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = call i8* @mhs_strconcat(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %18, i32* null)
store i8* %19, i8** %7
br label %20
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i8*, i8** %6
%25 = call i32 @mhs_free(i8* %24)
store i8* null, i8** %6
br label %26
26: ; preds = %23, %20
br label %27
27: ; preds = %26
%28 = load i8*, i8** %7
ret i8* %28
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @change_file_ext(i8* %0, i8* %1) {
%3 = tail call i8* @mhs_strdup(i8* %0)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %3, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %2
store i8 0, i8* %4
br label %7
7: ; preds = %6, %2
%8 = tail call i8* @mhs_strconcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %1, i32* null)
%9 = icmp eq i8* %3, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @mhs_free(i8* %3)
br label %12
12: ; preds = %10, %7
ret i8* %8
}