#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 const *);
int strlen(char *);
int /*<<< orphan*/ substr(char *, char *, int /*<<< orphan*/, int);
void change_extension(char *name, const char *ext) {
  int n, m;
  m = strlen(name);
  n = m;
  do
    n--;
  while (name[n] != '.');
  substr(name, name, 0, n);
  strcat(name, ext);
}


x86 assembly (clang, -O0):
<change_extension>:
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,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1152 <change_extension+0x22>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%ecx
xor    %edx,%edx
call   1040 <substr@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_extension>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%rcx
add    %rbx,%rcx
add    $0xffffffffffffffff,%rcx
nopl   0x0(%rax)
add    $0xffffffff,%eax
cmpb   $0x2e,(%rcx)
lea    -0x1(%rcx),%rcx
jne    1150 <change_extension+0x20>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %eax,%ecx
call   1040 <substr@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <strcat@plt>

LLVM IR (-O0):
define void @change_extension(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
store i32 %9, i32* %5
br label %10
10: ; preds = %13, %2
%11 = load i32, i32* %5
%12 = add nsw i32 %11, -1
store i32 %12, i32* %5
br label %13
13: ; preds = %10
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 46
br i1 %20, label %10, label %21
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = load i32, i32* %5
%25 = call i32 @substr(i8* %22, i8* %23, i32 0, i32 %24)
%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 @change_extension(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 [ %7, %5 ], [ %4, %2 ]
%7 = add i64 %6, -1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 46
br i1 %10, label %11, label %5
11: ; preds = %5
%12 = trunc i64 %7 to i32
%13 = tail call i32 @substr(i8* %0, i8* %0, i32 0, i32 %12)
%14 = tail call i32 @strcat(i8* %0, i8* %1)
ret void
}