#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ rename(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void fixCompressExtension(char pathFile[]) {
  char *originalName = (char *)malloc(100 * sizeof(char));
  strcpy(originalName, pathFile);
  int endOfName = strlen(pathFile);
  int i = endOfName, j;
  j = 5;
  char dotHuff[6] = {'.', 'h', 'u', 'f', 'f', '\0'};
  while (i >= 0 && pathFile[i] == dotHuff[j]) {
    i--;
    j--;
    if (j == -1)
      j = 4;
  }
  pathFile[i + (5 - j)] = '\0';
  strcat(pathFile, ".huff");
  if (strcmp(originalName, pathFile) != 0)
    remove(pathFile);
  rename(originalName, pathFile);
  free(originalName);
}


x86 assembly (clang, -O0):
<fixCompressExtension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x5,-0x1c(%rbp)
mov    0xe3a(%rip),%eax
mov    %eax,-0x22(%rbp)
mov    0xe34(%rip),%ax
mov    %ax,-0x1e(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x23(%rbp)
jl     1200 <fixCompressExtension+0x80>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movslq -0x1c(%rbp),%rcx
movsbl -0x22(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x23(%rbp)
mov    -0x23(%rbp),%al
test   $0x1,%al
jne    1210 <fixCompressExtension+0x90>
jmp    1238 <fixCompressExtension+0xb8>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1233 <fixCompressExtension+0xb3>
movl   $0x4,-0x1c(%rbp)
jmp    11d4 <fixCompressExtension+0x54>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    $0x5,%edx
sub    -0x1c(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1280 <fixCompressExtension+0x100>
mov    -0x8(%rbp),%rdi
call   1040 <remove@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <rename@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fixCompressExtension>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    $0x5,%ecx
test   %eax,%eax
js     11e3 <fixCompressExtension+0x63>
lea    0xe49(%rip),%rsi
mov    $0x4,%r8d
nopl   (%rax)
mov    %eax,%edi
movzbl (%rbx,%rdi,1),%edx
movslq %ecx,%rdi
cmp    (%rdi,%rsi,1),%dl
jne    11e3 <fixCompressExtension+0x63>
lea    -0x1(%rax),%edx
sub    $0x1,%ecx
cmovb  %r8d,%ecx
test   %eax,%eax
mov    %edx,%eax
jg     11c0 <fixCompressExtension+0x40>
mov    $0xffffffff,%eax
sub    %ecx,%eax
add    $0x5,%eax
cltq
movb   $0x0,(%rbx,%rax,1)
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1215 <fixCompressExtension+0x95>
mov    %rbx,%rdi
call   1040 <remove@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <rename@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@__const.fixCompressExtension.dotHuff = [6 x i8] c".huff\00"
@.str = [6 x i8] c".huff\00"
define void @fixCompressExtension(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [6 x i8]
store i8* %0, i8** %2
%8 = call i64 @malloc(i32 100)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %4
store i32 %15, i32* %5
store i32 5, i32* %6
%16 = bitcast [6 x i8]* %7 to i8*
br label %17
17: ; preds = %43, %1
%18 = load i32, i32* %5
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %17
%21 = load i8*, i8** %2
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %7, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %26, %31
br label %33
33: ; preds = %20, %17
%34 = phi i1 [ false, %17 ], [ %32, %20 ]
br i1 %34, label %35, label %44
35: ; preds = %33
%36 = load i32, i32* %5
%37 = add nsw i32 %36, -1
store i32 %37, i32* %5
%38 = load i32, i32* %6
%39 = add nsw i32 %38, -1
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %43
42: ; preds = %35
store i32 4, i32* %6
br label %43
43: ; preds = %42, %35
br label %17
44: ; preds = %33
%45 = load i8*, i8** %2
%46 = load i32, i32* %5
%47 = load i32, i32* %6
%48 = sub nsw i32 5, %47
%49 = add nsw i32 %46, %48
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %45, i64 %50
store i8 0, i8* %51
%52 = load i8*, i8** %2
%53 = call i32 @strcat(i8* %52, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%54 = load i8*, i8** %3
%55 = load i8*, i8** %2
%56 = call i64 @strcmp(i8* %54, i8* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %44
%59 = load i8*, i8** %2
%60 = call i32 @remove(i8* %59)
br label %61
61: ; preds = %58, %44
%62 = load i8*, i8** %3
%63 = load i8*, i8** %2
%64 = call i32 @rename(i8* %62, i8* %63)
%65 = load i8*, i8** %3
%66 = call i32 @free(i8* %65)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c".huff\00"
define void @fixCompressExtension(i8* %0) {
%2 = tail call i64 @malloc(i32 100)
%3 = inttoptr i64 %2 to i8*
%4 = tail call i32 @strcpy(i8* %3, i8* %0)
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %23
7: ; preds = %1, %17
%8 = phi i32 [ %21, %17 ], [ 5, %1 ]
%9 = phi i32 [ %18, %17 ], [ %5, %1 ]
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = sext i32 %8 to i64
%14 = getelementptr inbounds [6 x i8], [6 x i8]* @.str, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %12, %15
br i1 %16, label %17, label %23
17: ; preds = %7
%18 = add nsw i32 %9, -1
%19 = add nsw i32 %8, -1
%20 = icmp eq i32 %8, 0
%21 = select i1 %20, i32 4, i32 %19
%22 = icmp sgt i32 %9, 0
br i1 %22, label %7, label %23
23: ; preds = %7, %17, %1
%24 = phi i32 [ %5, %1 ], [ -1, %17 ], [ %9, %7 ]
%25 = phi i32 [ 5, %1 ], [ %21, %17 ], [ %8, %7 ]
%26 = add i32 %24, 5
%27 = sub i32 %26, %25
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 0, i8* %29
%30 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%31 = tail call i64 @strcmp(i8* %3, i8* %0)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %23
%34 = tail call i32 @remove(i8* %0)
br label %35
35: ; preds = %33, %23
%36 = tail call i32 @rename(i8* %3, i8* %0)
%37 = tail call i32 @free(i8* %3)
ret void
}