#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 */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int is_server_exist(char *, char *, int);
char *malloc(scalar_t__);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
char *strlwr(char *);
char *get_case_conflict_localfilename(char *localfolder, char *filename,
                                      char *serfolder, int index) {
  DIR *pDir;
  struct dirent *ent = NULL;
  pDir = opendir(localfolder);
  char *suffix = "(big-low-conflict)";
  int exist = 0;
  if (NULL == pDir) {
    return NULL;
  }
  char *tmp_name = NULL;
  while (NULL != (ent = readdir(pDir))) {
    if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
      continue;
    if (!strcmp(strlwr(ent->d_name), strlwr(filename)) &&
        strcmp(ent->d_name, filename)) {
      char *serfullname =
          malloc(strlen(serfolder) + strlen(ent->d_name) + 1 + 1);
      memset(serfullname, 0, strlen(serfolder) + strlen(ent->d_name) + 1 + 1);
      sprintf(serfullname, "%s/%s", serfolder, ent->d_name);
      exist = is_server_exist(serfolder, serfullname, index);
      free(serfullname);
      serfullname = NULL;
      ;
      if (exist) {
        tmp_name = malloc(strlen(ent->d_name) + strlen(suffix) + 1);
        memset(tmp_name, 0, strlen(ent->d_name) + strlen(suffix) + 1);
        sprintf(tmp_name, "%s", ent->d_name, suffix);
        break;
      }
    }
  }
  closedir(pDir);
  return tmp_name;
}


x86 assembly (clang, -O0):
<get_case_conflict_localfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x30(%rbp)
lea    0xe1a(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    120a <get_case_conflict_localfilename+0x5a>
movq   $0x0,-0x8(%rbp)
jmp    1415 <get_case_conflict_localfilename+0x265>
movq   $0x0,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x38(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     1404 <get_case_conflict_localfilename+0x254>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xdd9(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1267 <get_case_conflict_localfilename+0xb7>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xdbb(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    126c <get_case_conflict_localfilename+0xbc>
jmp    1212 <get_case_conflict_localfilename+0x62>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlwr@plt>
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlwr@plt>
mov    -0x60(%rbp),%rdi
mov    %rax,%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    13ff <get_case_conflict_localfilename+0x24f>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     13ff <get_case_conflict_localfilename+0x24f>
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    -0x78(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
add    $0x1,%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x70(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    -0x70(%rbp),%rdx
mov    -0x68(%rbp),%rdi
add    %rax,%rdx
add    $0x1,%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x58(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x38(%rbp),%rax
mov    (%rax),%rcx
lea    0xcdf(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1090 <is_server_exist@plt>
mov    %eax,-0x44(%rbp)
mov    -0x58(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x58(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     13fa <get_case_conflict_localfilename+0x24a>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x90(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x90(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x88(%rbp)
mov    -0x40(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x88(%rbp),%rdx
mov    -0x80(%rbp),%rdi
add    %rax,%rdx
add    $0x1,%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    (%rax),%rdx
mov    -0x40(%rbp),%rcx
lea    0xc29(%rip),%rsi
call   10d0 <sprintf@plt>
jmp    1404 <get_case_conflict_localfilename+0x254>
jmp    13ff <get_case_conflict_localfilename+0x24f>
jmp    1212 <get_case_conflict_localfilename+0x62>
mov    -0x30(%rbp),%rdi
call   1080 <closedir@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_case_conflict_localfilename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0xc(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r13
call   1060 <opendir@plt>
test   %rax,%rax
je     1339 <get_case_conflict_localfilename+0x179>
mov    %rax,%r15
mov    %rax,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     132d <get_case_conflict_localfilename+0x16d>
mov    %rax,%rbp
lea    0xdfb(%rip),%rbx
lea    0xdf3(%rip),%r14
jmp    1224 <get_case_conflict_localfilename+0x64>
nop
mov    %r15,%rdi
call   10c0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     132d <get_case_conflict_localfilename+0x16d>
mov    0x0(%rbp),%rdi
mov    %rbx,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     1210 <get_case_conflict_localfilename+0x50>
mov    0x0(%rbp),%rdi
mov    %r14,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     1210 <get_case_conflict_localfilename+0x50>
mov    0x0(%rbp),%rdi
call   1030 <strlwr@plt>
mov    %rax,%r12
mov    %r13,%rdi
call   1030 <strlwr@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
jne    1210 <get_case_conflict_localfilename+0x50>
mov    0x0(%rbp),%rdi
mov    %r13,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     1210 <get_case_conflict_localfilename+0x50>
mov    0x10(%rsp),%r14
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %rax,%r12
mov    0x0(%rbp),%rdi
call   1070 <strlen@plt>
add    %rax,%r12
add    $0x2,%r12
mov    %r12,%rdi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1080 <memset@plt>
mov    0x0(%rbp),%rcx
mov    %rbx,%rdi
lea    0xd42(%rip),%rsi
mov    %r14,%rdx
call   10e0 <sprintf@plt>
mov    %r14,%rdi
lea    0xd2d(%rip),%r14
mov    %rbx,%rsi
mov    0xc(%rsp),%edx
call   10a0 <is_server_exist@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
lea    0xd15(%rip),%rbx
call   1040 <free@plt>
test   %r12d,%r12d
je     1210 <get_case_conflict_localfilename+0x50>
mov    0x0(%rbp),%rdi
call   1070 <strlen@plt>
lea    0x13(%rax),%r14
mov    %r14,%rdi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1080 <memset@plt>
mov    0x0(%rbp),%rsi
mov    %rbx,%rdi
call   1050 <strcpy@plt>
jmp    132f <get_case_conflict_localfilename+0x16f>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1090 <closedir@plt>
jmp    133b <get_case_conflict_localfilename+0x17b>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [19 x i8] c"(big-low-conflict)\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [3 x i8] c"%s\00"
define i8* @get_case_conflict_localfilename(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca %struct.dirent*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store %struct.dirent* null, %struct.dirent** %11
%16 = load i8*, i8** %6
%17 = call i32* @opendir(i8* %16)
store i32* %17, i32** %10
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %12
store i32 0, i32* %13
%18 = load i32*, i32** %10
%19 = icmp eq i32* null, %18
br i1 %19, label %20, label %21
20: ; preds = %4
store i8* null, i8** %5
br label %123
21: ; preds = %4
store i8* null, i8** %14
br label %22
22: ; preds = %118, %38, %21
%23 = load i32*, i32** %10
%24 = call %struct.dirent* @readdir(i32* %23)
store %struct.dirent* %24, %struct.dirent** %11
%25 = icmp ne %struct.dirent* null, %24
br i1 %25, label %26, label %119
26: ; preds = %22
%27 = load %struct.dirent*, %struct.dirent** %11
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %26
%33 = load %struct.dirent*, %struct.dirent** %11
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %32, %26
br label %22
39: ; preds = %32
%40 = load %struct.dirent*, %struct.dirent** %11
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i8* @strlwr(i8* %42)
%44 = load i8*, i8** %7
%45 = call i8* @strlwr(i8* %44)
%46 = call i64 @strcmp(i8* %43, i8* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %118, label %48
48: ; preds = %39
%49 = load %struct.dirent*, %struct.dirent** %11
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = load i8*, i8** %7
%53 = call i64 @strcmp(i8* %51, i8* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %118
55: ; preds = %48
%56 = load i8*, i8** %8
%57 = call i64 @strlen(i8* %56)
%58 = load %struct.dirent*, %struct.dirent** %11
%59 = getelementptr inbounds %struct.dirent, %struct.dirent* %58, i32 0, i32 0
%60 = load i8*, i8** %59
%61 = call i64 @strlen(i8* %60)
%62 = add nsw i64 %57, %61
%63 = add nsw i64 %62, 1
%64 = add nsw i64 %63, 1
%65 = call i8* @malloc(i64 %64)
store i8* %65, i8** %15
%66 = load i8*, i8** %15
%67 = load i8*, i8** %8
%68 = call i64 @strlen(i8* %67)
%69 = load %struct.dirent*, %struct.dirent** %11
%70 = getelementptr inbounds %struct.dirent, %struct.dirent* %69, i32 0, i32 0
%71 = load i8*, i8** %70
%72 = call i64 @strlen(i8* %71)
%73 = add nsw i64 %68, %72
%74 = add nsw i64 %73, 1
%75 = add nsw i64 %74, 1
%76 = call i32 @memset(i8* %66, i32 0, i64 %75)
%77 = load i8*, i8** %15
%78 = load i8*, i8** %8
%79 = load %struct.dirent*, %struct.dirent** %11
%80 = getelementptr inbounds %struct.dirent, %struct.dirent* %79, i32 0, i32 0
%81 = load i8*, i8** %80
%82 = call i32 @sprintf(i8* %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %78, i8* %81)
%83 = load i8*, i8** %8
%84 = load i8*, i8** %15
%85 = load i32, i32* %9
%86 = call i32 @is_server_exist(i8* %83, i8* %84, i32 %85)
store i32 %86, i32* %13
%87 = load i8*, i8** %15
%88 = call i32 @free(i8* %87)
store i8* null, i8** %15
%89 = load i32, i32* %13
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %117
91: ; preds = %55
%92 = load %struct.dirent*, %struct.dirent** %11
%93 = getelementptr inbounds %struct.dirent, %struct.dirent* %92, i32 0, i32 0
%94 = load i8*, i8** %93
%95 = call i64 @strlen(i8* %94)
%96 = load i8*, i8** %12
%97 = call i64 @strlen(i8* %96)
%98 = add nsw i64 %95, %97
%99 = add nsw i64 %98, 1
%100 = call i8* @malloc(i64 %99)
store i8* %100, i8** %14
%101 = load i8*, i8** %14
%102 = load %struct.dirent*, %struct.dirent** %11
%103 = getelementptr inbounds %struct.dirent, %struct.dirent* %102, i32 0, i32 0
%104 = load i8*, i8** %103
%105 = call i64 @strlen(i8* %104)
%106 = load i8*, i8** %12
%107 = call i64 @strlen(i8* %106)
%108 = add nsw i64 %105, %107
%109 = add nsw i64 %108, 1
%110 = call i32 @memset(i8* %101, i32 0, i64 %109)
%111 = load i8*, i8** %14
%112 = load %struct.dirent*, %struct.dirent** %11
%113 = getelementptr inbounds %struct.dirent, %struct.dirent* %112, i32 0, i32 0
%114 = load i8*, i8** %113
%115 = load i8*, i8** %12
%116 = call i32 @sprintf(i8* %111, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %114, i8* %115)
br label %119
117: ; preds = %55
br label %118
118: ; preds = %117, %48, %39
br label %22
119: ; preds = %91, %22
%120 = load i32*, i32** %10
%121 = call i32 @closedir(i32* %120)
%122 = load i8*, i8** %14
store i8* %122, i8** %5
br label %123
123: ; preds = %119, %20
%124 = load i8*, i8** %5
ret i8* %124
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [6 x i8] c"%s/%s\00"
define i8* @get_case_conflict_localfilename(i8* nocapture %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i32* @opendir(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %57, label %7
7: ; preds = %4
%8 = tail call %struct.dirent* @readdir(i32* %5)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %54, label %10
10: ; preds = %7, %20
%11 = phi %struct.dirent* [ %21, %20 ], [ %8, %7 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = load i8*, i8** %12
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %23, %29, %33, %10, %16
%21 = tail call %struct.dirent* @readdir(i32* %5)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %54, label %10
23: ; preds = %16
%24 = load i8*, i8** %12
%25 = tail call i8* @strlwr(i8* %24)
%26 = tail call i8* @strlwr(i8* %1)
%27 = tail call i64 @strcmp(i8* %25, i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %20
29: ; preds = %23
%30 = load i8*, i8** %12
%31 = tail call i64 @strcmp(i8* %30, i8* %1)
%32 = icmp eq i64 %31, 0
br i1 %32, label %20, label %33
33: ; preds = %29
%34 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%35 = load i8*, i8** %12
%36 = tail call i64 @strlen(i8* dereferenceable(1) %35)
%37 = add i64 %34, 2
%38 = add i64 %37, %36
%39 = tail call i8* @malloc(i64 %38)
%40 = tail call i32 @memset(i8* %39, i32 0, i64 %38)
%41 = load i8*, i8** %12
%42 = tail call i32 @sprintf(i8* dereferenceable(1) %39, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* %41)
%43 = tail call i32 @is_server_exist(i8* %2, i8* %39, i32 %3)
%44 = tail call i32 @free(i8* %39)
%45 = icmp eq i32 %43, 0
br i1 %45, label %20, label %46
46: ; preds = %33
%47 = load i8*, i8** %12
%48 = tail call i64 @strlen(i8* dereferenceable(1) %47)
%49 = add nsw i64 %48, 19
%50 = tail call i8* @malloc(i64 %49)
%51 = tail call i32 @memset(i8* %50, i32 0, i64 %49)
%52 = load i8*, i8** %12
%53 = tail call i8* @strcpy(i8* dereferenceable(1) %50, i8* dereferenceable(1) %52)
br label %54
54: ; preds = %20, %7, %46
%55 = phi i8* [ %50, %46 ], [ null, %7 ], [ null, %20 ]
%56 = tail call i32 @closedir(i32* %5)
br label %57
57: ; preds = %4, %54
%58 = phi i8* [ %55, %54 ], [ null, %4 ]
ret i8* %58
}