#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 *);
int strlen(char *);
int find_file(char *path, char *file) {
  int flag, len;
  DIR *dirp;
  struct dirent *dp;
  flag = 0;
  if (strcmp(path, "") != 0) {
    len = strlen(file);
    dirp = opendir(path);
    for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
      if ((strlen(dp->d_name) == len) && !strcmp(dp->d_name, file)) {
        flag = 1;
      }
    }
    closedir(dirp);
  }
  if (flag == 1)
    return (1);
  else
    return (0);
}


x86 assembly (clang, -O0):
<find_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1208 <find_file+0xb8>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ff <find_file+0xaf>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
cmp    -0x20(%rbp),%eax
jne    11e8 <find_file+0x98>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11e8 <find_file+0x98>
movl   $0x1,-0x1c(%rbp)
jmp    11ed <find_file+0x9d>
mov    -0x28(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x30(%rbp)
jmp    11a7 <find_file+0x57>
mov    -0x28(%rbp),%rdi
call   1050 <closedir@plt>
cmpl   $0x1,-0x1c(%rbp)
jne    121e <find_file+0xce>
movl   $0x1,-0x4(%rbp)
jmp    1225 <find_file+0xd5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe98(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e3 <find_file+0x93>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <opendir@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11e7 <find_file+0x97>
mov    %rax,%rbp
xor    %ebx,%ebx
mov    $0x1,%r13d
jmp    11c0 <find_file+0x70>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11e9 <find_file+0x99>
mov    0x0(%rbp),%rdi
call   1040 <strlen@plt>
cmp    %r15d,%eax
jne    11b0 <find_file+0x60>
mov    0x0(%rbp),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
cmove  %r13d,%ebx
jmp    11b0 <find_file+0x60>
xor    %eax,%eax
jmp    11f9 <find_file+0xa9>
xor    %ebx,%ebx
mov    %r12,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
cmp    $0x1,%ebx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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