#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*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
char *strlwr(char *);
int is_local_exist(char *folder, char *filename) {
  DIR *pDir;
  struct dirent *ent = NULL;
  pDir = opendir(folder);
  if (NULL == pDir) {
    return 0;
  }
  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)) {
      return 1;
    }
    closedir(pDir);
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_local_exist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
jne    118d <is_local_exist+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1256 <is_local_exist+0x106>
jmp    1192 <is_local_exist+0x42>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     124f <is_local_exist+0xff>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xe46(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11e7 <is_local_exist+0x97>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
lea    0xe28(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11ec <is_local_exist+0x9c>
jmp    1192 <is_local_exist+0x42>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlwr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlwr@plt>
mov    -0x30(%rbp),%rdi
mov    %rax,%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1241 <is_local_exist+0xf1>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1241 <is_local_exist+0xf1>
movl   $0x1,-0x4(%rbp)
jmp    1256 <is_local_exist+0x106>
mov    -0x20(%rbp),%rdi
call   1050 <closedir@plt>
jmp    1192 <is_local_exist+0x42>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_local_exist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
call   1040 <opendir@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1216 <is_local_exist+0xc6>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1216 <is_local_exist+0xc6>
mov    %rax,%rbx
lea    0xe74(%rip),%r13
lea    0xe6c(%rip),%r12
jmp    11b8 <is_local_exist+0x68>
cs nopw 0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1050 <closedir@plt>
mov    %rbp,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1213 <is_local_exist+0xc3>
mov    (%rbx),%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a8 <is_local_exist+0x58>
mov    (%rbx),%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a8 <is_local_exist+0x58>
mov    (%rbx),%rdi
call   1030 <strlwr@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlwr@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11a0 <is_local_exist+0x50>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <is_local_exist+0x50>
mov    $0x1,%r14d
jmp    1216 <is_local_exist+0xc6>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i32 @is_local_exist(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.dirent*
store i8* %0, i8** %4
store i8* %1, i8** %5
store %struct.dirent* null, %struct.dirent** %7
%8 = load i8*, i8** %4
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* null, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %52
13: ; preds = %2
br label %14
14: ; preds = %48, %30, %13
%15 = load i32*, i32** %6
%16 = call %struct.dirent* @readdir(i32* %15)
store %struct.dirent* %16, %struct.dirent** %7
%17 = icmp ne %struct.dirent* null, %16
br i1 %17, label %18, label %51
18: ; preds = %14
%19 = load %struct.dirent*, %struct.dirent** %7
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %18
%25 = load %struct.dirent*, %struct.dirent** %7
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %24, %18
br label %14
31: ; preds = %24
%32 = load %struct.dirent*, %struct.dirent** %7
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = call i8* @strlwr(i8* %34)
%36 = load i8*, i8** %5
%37 = call i8* @strlwr(i8* %36)
%38 = call i64 @strcmp(i8* %35, i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %48, label %40
40: ; preds = %31
%41 = load %struct.dirent*, %struct.dirent** %7
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i32 0, i32 0
%43 = load i8*, i8** %42
%44 = load i8*, i8** %5
%45 = call i64 @strcmp(i8* %43, i8* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %40
store i32 1, i32* %3
br label %52
48: ; preds = %40, %31
%49 = load i32*, i32** %6
%50 = call i32 @closedir(i32* %49)
br label %14
51: ; preds = %14
store i32 0, i32* %3
br label %52
52: ; preds = %51, %47, %12
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define i32 @is_local_exist(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @opendir(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %33, label %5
5: ; preds = %2
%6 = tail call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %33, label %8
8: ; preds = %5, %18
%9 = phi %struct.dirent* [ %19, %18 ], [ %6, %5 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %8
%15 = load i8*, i8** %10
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %8, %14, %31
%19 = tail call %struct.dirent* @readdir(i32* %3)
%20 = icmp eq %struct.dirent* %19, null
br i1 %20, label %33, label %8
21: ; preds = %14
%22 = load i8*, i8** %10
%23 = tail call i8* @strlwr(i8* %22)
%24 = tail call i8* @strlwr(i8* %1)
%25 = tail call i64 @strcmp(i8* %23, i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i8*, i8** %10
%29 = tail call i64 @strcmp(i8* %28, i8* %1)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27, %21
%32 = tail call i32 @closedir(i32* %3)
br label %18
33: ; preds = %27, %18, %5, %2
%34 = phi i32 [ 0, %2 ], [ 0, %5 ], [ 1, %27 ], [ 0, %18 ]
ret i32 %34
}