#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 /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void changeext(char *pathname) {
  int l = strlen(pathname);
  int i = l - 1;
  while (pathname[i] != '/' && i >= 0) {
    if (pathname[i--] == '.') {
      strcpy(pathname + i + 1, ".xsm");
      return;
    }
  }
  strcat(pathname, ".xsm");
}


x86 assembly (clang, -O0):
<changeext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2f,%ecx
mov    %al,-0x11(%rbp)
je     1175 <changeext+0x45>
cmpl   $0x0,-0x10(%rbp)
setge  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1185 <changeext+0x55>
jmp    11c9 <changeext+0x99>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    11c4 <changeext+0x94>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d9 <changeext+0xa9>
jmp    1151 <changeext+0x21>
mov    -0x8(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1050 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeext>:
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
add    $0xffffffff,%eax
movslq %eax,%rcx
mov    %rcx,%rax
shl    $0x20,%rax
movabs $0xffffffff00000000,%rsi
ff ff ff
movzbl (%rbx,%rcx,1),%edx
cmp    $0x2f,%dl
je     1183 <changeext+0x53>
test   %rcx,%rcx
js     1183 <changeext+0x53>
add    $0xffffffffffffffff,%rcx
add    %rsi,%rax
cmp    $0x2e,%dl
jne    1150 <changeext+0x20>
sar    $0x20,%rax
lea    (%rbx,%rax,1),%rdi
add    $0x1,%rdi
lea    0xe83(%rip),%rsi
pop    %rbx
jmp    1030 <strcpy@plt>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <strcat@plt>

LLVM IR (-O0):
@.str = [5 x i8] c".xsm\00"
define void @changeext(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = sub nsw i32 %7, 1
store i32 %8, i32* %4
br label %9
9: ; preds = %38, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 47
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = load i32, i32* %4
%19 = icmp sge i32 %18, 0
br label %20
20: ; preds = %17, %9
%21 = phi i1 [ false, %9 ], [ %19, %17 ]
br i1 %21, label %22, label %39
22: ; preds = %20
%23 = load i8*, i8** %2
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 46
br i1 %30, label %31, label %38
31: ; preds = %22
%32 = load i8*, i8** %2
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %42
38: ; preds = %22
br label %9
39: ; preds = %20
%40 = load i8*, i8** %2
%41 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %39, %31
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".xsm\00"
define void @changeext(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add i32 %2, -1
%4 = sext i32 %3 to i64
br label %5
5: ; preds = %12, %1
%6 = phi i64 [ %13, %12 ], [ %4, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 47
%10 = icmp sgt i64 %6, -1
%11 = select i1 %9, i1 %10, i1 false
br i1 %11, label %12, label %21
12: ; preds = %5
%13 = add nsw i64 %6, -1
%14 = icmp eq i8 %8, 46
br i1 %14, label %15, label %5
15: ; preds = %12
%16 = shl i64 %13, 32
%17 = ashr exact i64 %16, 32
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = tail call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %23
21: ; preds = %5
%22 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %15
ret void
}