#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*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
void ChangeExtension(char *path, char *ext) {
  int i;
  for (i = 0; path[i] != 0; i++)
    ;
  for (; i >= 0; i--) {
    if ((path[i] == '.') || (path[i] == '\\') || (path[i] == '/'))
      break;
  }
  if (i >= 0) {
    if (path[i] == '.') {
      path[i + 1] = 0;
      strcat(path, ext);
    } else {
      printf("ERROR: Filename '%s' must have an extension\n", path);
      exit(1);
    }
  } else {
    printf("ERROR: Empty filename\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<ChangeExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     116f <ChangeExtension+0x3f>
jmp    1161 <ChangeExtension+0x31>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1147 <ChangeExtension+0x17>
jmp    1174 <ChangeExtension+0x44>
cmpl   $0x0,-0x14(%rbp)
jl     11d5 <ChangeExtension+0xa5>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     11bd <ChangeExtension+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     11bd <ChangeExtension+0x8d>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11c2 <ChangeExtension+0x92>
jmp    11d5 <ChangeExtension+0xa5>
jmp    11c7 <ChangeExtension+0x97>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1174 <ChangeExtension+0x44>
cmpl   $0x0,-0x14(%rbp)
jl     1238 <ChangeExtension+0x108>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1217 <ChangeExtension+0xe7>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcat@plt>
jmp    1233 <ChangeExtension+0x103>
mov    -0x8(%rbp),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    1250 <ChangeExtension+0x120>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ChangeExtension>:
push   %rax
mov    %rdi,%rax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x0,(%rax,%rcx,1)
lea    0x1(%rcx),%rcx
jne    1150 <ChangeExtension+0x10>
add    $0xffffffff,%ecx
add    $0x1,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rax,%rcx,1),%edx
cmp    $0x2e,%dl
je     11a2 <ChangeExtension+0x62>
cmp    $0x2f,%dl
je     11b1 <ChangeExtension+0x71>
cmp    $0x5c,%dl
je     11b1 <ChangeExtension+0x71>
add    $0xffffffffffffffff,%rcx
test   %ecx,%ecx
jg     1170 <ChangeExtension+0x30>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    %rax,%rdi
pop    %rax
jmp    1050 <strcat@plt>
lea    0xe48(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"ERROR: Filename '%s' must have an extension\0A\00"
@.str.1 = [23 x i8] c"ERROR: Empty filename\0A\00"
define void @ChangeExtension(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
br label %6
6: ; preds = %15, %2
%7 = load i8*, i8** %3
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %6
br label %15
15: ; preds = %14
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
store i32 %17, i32* %5
br label %6
18: ; preds = %6
br label %19
19: ; preds = %48, %18
%20 = load i32, i32* %5
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %51
22: ; preds = %19
%23 = load i8*, i8** %3
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 46
br i1 %29, label %46, label %30
30: ; preds = %22
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 92
br i1 %37, label %46, label %38
38: ; preds = %30
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 47
br i1 %45, label %46, label %47
46: ; preds = %38, %30, %22
br label %51
47: ; preds = %38
br label %48
48: ; preds = %47
%49 = load i32, i32* %5
%50 = add nsw i32 %49, -1
store i32 %50, i32* %5
br label %19
51: ; preds = %46, %19
%52 = load i32, i32* %5
%53 = icmp sge i32 %52, 0
br i1 %53, label %54, label %76
54: ; preds = %51
%55 = load i8*, i8** %3
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 46
br i1 %61, label %62, label %71
62: ; preds = %54
%63 = load i8*, i8** %3
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
store i8 0, i8* %67
%68 = load i8*, i8** %3
%69 = load i8*, i8** %4
%70 = call i32 @strcat(i8* %68, i8* %69)
br label %75
71: ; preds = %54
%72 = load i8*, i8** %3
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %72)
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %62
br label %79
76: ; preds = %51
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %75
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"ERROR: Filename '%s' must have an extension\0A\00"
@str = [22 x i8] c"ERROR: Empty filename\00"
define void @ChangeExtension(i8* %0, i8* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ %8, %3 ], [ 0, %2 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = add nuw i64 %4, 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = and i64 %4, 4294967295
br label %11
11: ; preds = %9, %15
%12 = phi i64 [ %10, %9 ], [ %16, %15 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
switch i8 %14, label %15 [
i8 46, label %19
i8 47, label %24
i8 92, label %24
]
15: ; preds = %11
%16 = add nsw i64 %12, -1
%17 = trunc i64 %12 to i32
%18 = icmp sgt i32 %17, 0
br i1 %18, label %11, label %27
19: ; preds = %11
%20 = add nsw i64 %12, 1
%21 = and i64 %20, 4294967295
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 0, i8* %22
%23 = tail call i32 @strcat(i8* %0, i8* %1)
ret void
24: ; preds = %11, %11
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %0)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %15
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
}