#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 */
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
char *generate_new_filename(char *, char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ rename(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
void main_function(char location[], char new_prefix[], char separator[]) {
  DIR *DIRECTORY = opendir(location);
  int location_length = strlen(location);
  if (location[location_length - 1] != '\\') {
    location[location_length++] = '\\';
  }
  struct dirent *dir;
  if (DIRECTORY) {
    while ((dir = readdir(DIRECTORY)) != NULL) {
      if (dir->d_name[0] == '.')
        continue;
      int len_old_file_path = strlen(location) + strlen(dir->d_name) + 2;
      char *fullpath = (char *)calloc(len_old_file_path, sizeof(char));
      strcat(fullpath, location);
      strcat(fullpath, dir->d_name);
      int len_new_file_path = strlen(location) + strlen(new_prefix) + 3;
      char *dynrename = (char *)calloc(len_new_file_path, sizeof(char));
      strcat(dynrename, location);
      strcat(dynrename,
             generate_new_filename(dir->d_name, new_prefix, separator));
      if ((rename(fullpath, dynrename) == 0)) {
        printf("%s successfully renamed!\n", dir->d_name);
      } else {
        printf("%s not renamed!\n", dir->d_name);
      }
    }
    closedir(DIRECTORY);
  } else {
    printf("Can't open your directory!");
    return;
  }
}


x86 assembly (clang, -O0):
<main_function>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     11ed <main_function+0x5d>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
movslq %ecx,%rcx
movb   $0x5c,(%rax,%rcx,1)
cmpq   $0x0,-0x20(%rbp)
je     1340 <main_function+0x1b0>
jmp    11fd <main_function+0x6d>
mov    -0x20(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1332 <main_function+0x1a2>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    122c <main_function+0x9c>
jmp    11fd <main_function+0x6d>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x60(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   10b0 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
add    %ecx,%eax
add    $0x3,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1090 <generate_new_filename@plt>
mov    -0x58(%rbp),%rdi
mov    %rax,%rsi
call   10b0 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10a0 <rename@plt>
cmp    $0x0,%rax
jne    1318 <main_function+0x188>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    132d <main_function+0x19d>
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11fd <main_function+0x6d>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
jmp    134e <main_function+0x1be>
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main_function>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdi,%r13
call   1030 <opendir@plt>
mov    %rax,%r14
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x5c,-0x1(%rax,%r13,1)
je     11cb <main_function+0x3b>
movb   $0x5c,0x0(%r13,%rax,1)
test   %r14,%r14
je     12df <main_function+0x14f>
mov    %r14,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     12c9 <main_function+0x139>
mov    %rax,%rbx
mov    0x8(%rsp),%r12
jmp    1204 <main_function+0x74>
nop
mov    %r14,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12c9 <main_function+0x139>
mov    (%rbx),%rax
cmpb   $0x2e,(%rax)
je     11f0 <main_function+0x60>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    (%rbx),%rdi
call   1040 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x2,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r13,%rsi
call   10b0 <strcat@plt>
mov    (%rbx),%rsi
mov    %r15,%rdi
call   10b0 <strcat@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r14,%rbp
mov    %eax,%r14d
mov    %r12,%rdi
call   1040 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0x3,%edi
mov    %rbp,%r14
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
call   10b0 <strcat@plt>
mov    (%rbx),%rdi
mov    %r12,%rsi
mov    0x10(%rsp),%rdx
call   1090 <generate_new_filename@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   10b0 <strcat@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10a0 <rename@plt>
test   %rax,%rax
mov    (%rbx),%rsi
lea    0xd68(%rip),%rdi
lea    0xd47(%rip),%rax
cmove  %rax,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f0 <main_function+0x60>
mov    %r14,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <closedir@plt>
lea    0xd45(%rip),%rdi
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [26 x i8] c"%s successfully renamed!\0A\00"
@.str.1 = [17 x i8] c"%s not renamed!\0A\00"
@.str.2 = [27 x i8] c"Can't open your directory!\00"
define void @main_function(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca %struct.dirent*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%14 = load i8*, i8** %4
%15 = call i32* @opendir(i8* %14)
store i32* %15, i32** %7
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %8
%18 = load i8*, i8** %4
%19 = load i32, i32* %8
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 92
br i1 %25, label %26, label %32
26: ; preds = %3
%27 = load i8*, i8** %4
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 92, i8* %31
br label %32
32: ; preds = %26, %3
%33 = load i32*, i32** %7
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %107
35: ; preds = %32
br label %36
36: ; preds = %103, %48, %35
%37 = load i32*, i32** %7
%38 = call %struct.dirent* @readdir(i32* %37)
store %struct.dirent* %38, %struct.dirent** %9
%39 = icmp ne %struct.dirent* %38, null
br i1 %39, label %40, label %104
40: ; preds = %36
%41 = load %struct.dirent*, %struct.dirent** %9
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i32 0, i32 0
%43 = load i8*, i8** %42
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 46
br i1 %47, label %48, label %49
48: ; preds = %40
br label %36
49: ; preds = %40
%50 = load i8*, i8** %4
%51 = call i32 @strlen(i8* %50)
%52 = load %struct.dirent*, %struct.dirent** %9
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i8*, i8** %53
%55 = call i32 @strlen(i8* %54)
%56 = add nsw i32 %51, %55
%57 = add nsw i32 %56, 2
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = call i64 @calloc(i32 %58, i32 1)
%60 = inttoptr i64 %59 to i8*
store i8* %60, i8** %11
%61 = load i8*, i8** %11
%62 = load i8*, i8** %4
%63 = call i32 @strcat(i8* %61, i8* %62)
%64 = load i8*, i8** %11
%65 = load %struct.dirent*, %struct.dirent** %9
%66 = getelementptr inbounds %struct.dirent, %struct.dirent* %65, i32 0, i32 0
%67 = load i8*, i8** %66
%68 = call i32 @strcat(i8* %64, i8* %67)
%69 = load i8*, i8** %4
%70 = call i32 @strlen(i8* %69)
%71 = load i8*, i8** %5
%72 = call i32 @strlen(i8* %71)
%73 = add nsw i32 %70, %72
%74 = add nsw i32 %73, 3
store i32 %74, i32* %12
%75 = load i32, i32* %12
%76 = call i64 @calloc(i32 %75, i32 1)
%77 = inttoptr i64 %76 to i8*
store i8* %77, i8** %13
%78 = load i8*, i8** %13
%79 = load i8*, i8** %4
%80 = call i32 @strcat(i8* %78, i8* %79)
%81 = load i8*, i8** %13
%82 = load %struct.dirent*, %struct.dirent** %9
%83 = getelementptr inbounds %struct.dirent, %struct.dirent* %82, i32 0, i32 0
%84 = load i8*, i8** %83
%85 = load i8*, i8** %5
%86 = load i8*, i8** %6
%87 = call i8* @generate_new_filename(i8* %84, i8* %85, i8* %86)
%88 = call i32 @strcat(i8* %81, i8* %87)
%89 = load i8*, i8** %11
%90 = load i8*, i8** %13
%91 = call i64 @rename(i8* %89, i8* %90)
%92 = icmp eq i64 %91, 0
br i1 %92, label %93, label %98
93: ; preds = %49
%94 = load %struct.dirent*, %struct.dirent** %9
%95 = getelementptr inbounds %struct.dirent, %struct.dirent* %94, i32 0, i32 0
%96 = load i8*, i8** %95
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %96)
br label %103
98: ; preds = %49
%99 = load %struct.dirent*, %struct.dirent** %9
%100 = getelementptr inbounds %struct.dirent, %struct.dirent* %99, i32 0, i32 0
%101 = load i8*, i8** %100
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %101)
br label %103
103: ; preds = %98, %93
br label %36
104: ; preds = %36
%105 = load i32*, i32** %7
%106 = call i32 @closedir(i32* %105)
br label %109
107: ; preds = %32
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %109
109: ; preds = %107, %104
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [26 x i8] c"%s successfully renamed!\0A\00"
@.str.1 = [17 x i8] c"%s not renamed!\0A\00"
@.str.2 = [27 x i8] c"Can't open your directory!\00"
define void @main_function(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32* @opendir(i8* %0)
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 92
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = sext i32 %5 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 92, i8* %13
br label %14
14: ; preds = %11, %3
%15 = icmp eq i32* %4, null
br i1 %15, label %56, label %16
16: ; preds = %14
%17 = tail call %struct.dirent* @readdir(i32* %4)
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %54, label %19
19: ; preds = %16, %51
%20 = phi %struct.dirent* [ %52, %51 ], [ %17, %16 ]
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 46
br i1 %24, label %51, label %25
25: ; preds = %19
%26 = tail call i32 @strlen(i8* %0)
%27 = load i8*, i8** %21
%28 = tail call i32 @strlen(i8* %27)
%29 = add i32 %26, 2
%30 = add i32 %29, %28
%31 = tail call i64 @calloc(i32 %30, i32 1)
%32 = inttoptr i64 %31 to i8*
%33 = tail call i32 @strcat(i8* %32, i8* %0)
%34 = load i8*, i8** %21
%35 = tail call i32 @strcat(i8* %32, i8* %34)
%36 = tail call i32 @strlen(i8* %0)
%37 = tail call i32 @strlen(i8* %1)
%38 = add i32 %36, 3
%39 = add i32 %38, %37
%40 = tail call i64 @calloc(i32 %39, i32 1)
%41 = inttoptr i64 %40 to i8*
%42 = tail call i32 @strcat(i8* %41, i8* %0)
%43 = load i8*, i8** %21
%44 = tail call i8* @generate_new_filename(i8* %43, i8* %1, i8* %2)
%45 = tail call i32 @strcat(i8* %41, i8* %44)
%46 = tail call i64 @rename(i8* %32, i8* %41)
%47 = icmp eq i64 %46, 0
%48 = load i8*, i8** %21
%49 = select i1 %47, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0)
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %49, i8* %48)
br label %51
51: ; preds = %25, %19
%52 = tail call %struct.dirent* @readdir(i32* %4)
%53 = icmp eq %struct.dirent* %52, null
br i1 %53, label %54, label %19
54: ; preds = %51, %16
%55 = tail call i32 @closedir(i32* %4)
br label %58
56: ; preds = %14
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %54, %56
ret void
}