#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 strlen(char *);
void ChangeFileExtension(char *str, char *ext) {
  int n;
  n = strlen(str);
  while (str[n] != '.')
    n--;
  n++;
  str[n] = 0;
  strcat(str, ext);
}


x86 assembly (clang, -O0):
<ChangeFileExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     115f <ChangeFileExtension+0x3f>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    113c <ChangeFileExtension+0x1c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ChangeFileExtension>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rdx
lea    (%rbx,%rdx,1),%rcx
shl    $0x20,%rdx
movabs $0x200000000,%rax
add    %rdx,%rax
movabs $0xffffffff00000000,%rdx
ff ff ff
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %rdx,%rax
cmpb   $0x2e,(%rcx)
lea    -0x1(%rcx),%rcx
jne    1160 <ChangeFileExtension+0x40>
sar    $0x20,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <strcat@plt>

LLVM IR (-O0):
define void @ChangeFileExtension(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
br label %8
8: ; preds = %16, %2
%9 = load i8*, i8** %3
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 46
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i32, i32* %5
%18 = add nsw i32 %17, -1
store i32 %18, i32* %5
br label %8
19: ; preds = %8
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %3
%27 = load i8*, i8** %4
%28 = call i32 @strcat(i8* %26, i8* %27)
ret void
}

LLVM IR (-O2):
define void @ChangeFileExtension(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = sext i32 %3 to i64
br label %5
5: ; preds = %5, %2
%6 = phi i64 [ %10, %5 ], [ %4, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 46
%10 = add i64 %6, -1
br i1 %9, label %11, label %5
11: ; preds = %5
%12 = shl i64 %6, 32
%13 = add i64 %12, 4294967296
%14 = ashr exact i64 %13, 32
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
%16 = tail call i32 @strcat(i8* %0, i8* %1)
ret void
}