#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 *index(char *, char);
char *rindex(char *, char);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int change_extension(char *fullfilename, char *filetype) {
  char tmp[256], *r, *s, *t;
  int i;
  if (*filetype == '.')
    filetype++;
  r = rindex(fullfilename, '/');
  if (!r)
    r = &fullfilename[strlen(fullfilename)];
  s = index(r, '.');
  if (!s) {
    strcat(fullfilename, ".");
    strcat(fullfilename, filetype);
    return 0;
  }
  tmp[0] = '\0';
  t = index(s, ';');
  if (t)
    strcpy(tmp, t);
  strcpy(s + 1, filetype);
  strcat(s, tmp);
}


x86 assembly (clang, -O0):
<change_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    117f <change_extension+0x2f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <rindex@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11ca <change_extension+0x7a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x148(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <index@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    1219 <change_extension+0xc9>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
movl   $0x0,-0x4(%rbp)
jmp    1280 <change_extension+0x130>
movb   $0x0,-0x120(%rbp)
mov    -0x130(%rbp),%rdi
mov    $0x3b,%esi
call   1050 <index@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
je     1259 <change_extension+0x109>
lea    -0x120(%rbp),%rdi
mov    -0x138(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x130(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x130(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<change_extension>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
xor    %ebx,%ebx
cmpb   $0x2e,(%rsi)
sete   %bl
mov    $0x2f,%esi
call   1060 <rindex@plt>
test   %rax,%rax
jne    1184 <change_extension+0x34>
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %r14,%rax
add    %rbx,%r15
mov    %rax,%rdi
mov    $0x2e,%esi
call   1050 <index@plt>
test   %rax,%rax
je     11d4 <change_extension+0x84>
mov    %rax,%rbx
movb   $0x0,(%rsp)
mov    %rax,%rdi
mov    $0x3b,%esi
call   1050 <index@plt>
test   %rax,%rax
je     11bd <change_extension+0x6d>
mov    %rsp,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
add    $0x1,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
jmp    11e9 <change_extension+0x99>
lea    0xe25(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i32 @change_extension(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 46
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %5
br label %18
18: ; preds = %15, %2
%19 = load i8*, i8** %4
%20 = call i8* @rindex(i8* %19, i8 signext 47)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
br i1 %22, label %28, label %23
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = load i8*, i8** %4
%26 = call i64 @strlen(i8* %25)
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8* %27, i8** %7
br label %28
28: ; preds = %23, %18
%29 = load i8*, i8** %7
%30 = call i8* @index(i8* %29, i8 signext 46)
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %39, label %33
33: ; preds = %28
%34 = load i8*, i8** %4
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%36 = load i8*, i8** %4
%37 = load i8*, i8** %5
%38 = call i32 @strcat(i8* %36, i8* %37)
store i32 0, i32* %3
br label %57
39: ; preds = %28
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
store i8 0, i8* %40
%41 = load i8*, i8** %8
%42 = call i8* @index(i8* %41, i8 signext 59)
store i8* %42, i8** %9
%43 = load i8*, i8** %9
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %49
45: ; preds = %39
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%47 = load i8*, i8** %9
%48 = call i32 @strcpy(i8* %46, i8* %47)
br label %49
49: ; preds = %45, %39
%50 = load i8*, i8** %8
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = load i8*, i8** %5
%53 = call i32 @strcpy(i8* %51, i8* %52)
%54 = load i8*, i8** %8
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%56 = call i32 @strcat(i8* %54, i8* %55)
br label %57
57: ; preds = %49, %33
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @change_extension(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 46
%7 = zext i1 %6 to i64
%8 = getelementptr i8, i8* %1, i64 %7
%9 = tail call i8* @rindex(i8* %0, i8 signext 47)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%13 = getelementptr inbounds i8, i8* %0, i64 %12
br label %14
14: ; preds = %11, %2
%15 = phi i8* [ %9, %2 ], [ %13, %11 ]
%16 = tail call i8* @index(i8* %15, i8 signext 46)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @strcat(i8* %0, i8* %8)
br label %30
21: ; preds = %14
store i8 0, i8* %4
%22 = tail call i8* @index(i8* %16, i8 signext 59)
%23 = icmp eq i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @strcpy(i8* %4, i8* %22)
br label %26
26: ; preds = %24, %21
%27 = getelementptr inbounds i8, i8* %16, i64 1
%28 = call i32 @strcpy(i8* %27, i8* %8)
%29 = call i32 @strcat(i8* %16, i8* %4)
br label %30
30: ; preds = %26, %18
ret i32 0
}