#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 *UtilStrDup(char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strrchr(char *, char);
char *ReplaceExtension(const char *filename, const char *ext) {
  char *dot_pos;
  char buffer[512];
  strcpy(buffer, filename);
  dot_pos = strrchr(buffer, '.');
  if (dot_pos)
    dot_pos[1] = 0;
  else
    strcat(buffer, ".");
  strcat(buffer, ext);
  return UtilStrDup(buffer);
}


x86 assembly (clang, -O0):
<ReplaceExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x220(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1190 <ReplaceExtension+0x50>
mov    -0x18(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11a3 <ReplaceExtension+0x63>
lea    -0x220(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
lea    -0x220(%rbp),%rdi
call   1060 <UtilStrDup@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReplaceExtension>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1173 <ReplaceExtension+0x33>
movb   $0x0,0x1(%rax)
jmp    1182 <ReplaceExtension+0x42>
lea    0xe86(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcat@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1060 <UtilStrDup@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @ReplaceExtension(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [512 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @strcpy(i8* %7, i8* %8)
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%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 %17
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 0, i8* %16
br label %20
17: ; preds = %2
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %14
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %4
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%25 = call i8* @UtilStrDup(i8* %24)
ret i8* %25
}

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