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

/* Variables and functions */
scalar_t__ dtree_iserror();
scalar_t__ path_is_file(struct stack **, char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewinddir(int /*<<< orphan*/ *);
scalar_t__ strcmp(int /*<<< orphan*/, char const *);
int dir_has_file(DIR *curr, struct stack **path, const char *fname) {
  rewinddir(curr);
  struct dirent *d;
  while ((d = readdir(curr)) != NULL) {
    if (strcmp(d->d_name, fname))
      continue;
    if (path_is_file(path, fname))
      return 1;
    if (dtree_iserror())
      return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<dir_has_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <rewinddir@plt>
mov    -0x10(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11e7 <dir_has_file+0x97>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11a2 <dir_has_file+0x52>
jmp    116d <dir_has_file+0x1d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <path_is_file@plt>
cmp    $0x0,%rax
je     11c5 <dir_has_file+0x75>
movl   $0x1,-0x4(%rbp)
jmp    11ee <dir_has_file+0x9e>
mov    $0x0,%al
call   1060 <dtree_iserror@plt>
cmp    $0x0,%rax
je     11e2 <dir_has_file+0x92>
movl   $0x0,-0x4(%rbp)
jmp    11ee <dir_has_file+0x9e>
jmp    116d <dir_has_file+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_has_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <rewinddir@plt>
mov    %r15,%rdi
call   1050 <readdir@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    118d <dir_has_file+0x3d>
jmp    11c3 <dir_has_file+0x73>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     11ba <dir_has_file+0x6a>
mov    (%rax),%edi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1180 <dir_has_file+0x30>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <path_is_file@plt>
test   %rax,%rax
jne    11be <dir_has_file+0x6e>
xor    %eax,%eax
call   1060 <dtree_iserror@plt>
test   %rax,%rax
je     1180 <dir_has_file+0x30>
jmp    11c3 <dir_has_file+0x73>
xor    %ebp,%ebp
jmp    11c3 <dir_has_file+0x73>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stack = type { i32 }
%struct.dirent = type { i32 }
define i32 @dir_has_file(i32* %0, %struct.stack** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.stack**
%7 = alloca i8*
%8 = alloca %struct.dirent*
store i32* %0, i32** %5
store %struct.stack** %1, %struct.stack*** %6
store i8* %2, i8** %7
%9 = load i32*, i32** %5
%10 = call i32 @rewinddir(i32* %9)
br label %11
11: ; preds = %33, %22, %3
%12 = load i32*, i32** %5
%13 = call %struct.dirent* @readdir(i32* %12)
store %struct.dirent* %13, %struct.dirent** %8
%14 = icmp ne %struct.dirent* %13, null
br i1 %14, label %15, label %34
15: ; preds = %11
%16 = load %struct.dirent*, %struct.dirent** %8
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i8*, i8** %7
%20 = call i64 @strcmp(i32 %18, i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
br label %11
23: ; preds = %15
%24 = load %struct.stack**, %struct.stack*** %6
%25 = load i8*, i8** %7
%26 = call i64 @path_is_file(%struct.stack** %24, i8* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i32 1, i32* %4
br label %35
29: ; preds = %23
%30 = call i64 (...) @dtree_iserror()
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 0, i32* %4
br label %35
33: ; preds = %29
br label %11
34: ; preds = %11
store i32 0, i32* %4
br label %35
35: ; preds = %34, %32, %28
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
%struct.stack = type { i32 }
%struct.dirent = type { i32 }
define i32 @dir_has_file(i32* %0, %struct.stack** %1, i8* %2) {
%4 = tail call i32 @rewinddir(i32* %0)
%5 = tail call %struct.dirent* @readdir(i32* %0)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %22, label %7
7: ; preds = %3, %13
%8 = phi %struct.dirent* [ %14, %13 ], [ %5, %3 ]
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i64 @strcmp(i32 %10, i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7, %19
%14 = tail call %struct.dirent* @readdir(i32* %0)
%15 = icmp eq %struct.dirent* %14, null
br i1 %15, label %22, label %7
16: ; preds = %7
%17 = tail call i64 @path_is_file(%struct.stack** %1, i8* %2)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i64 (...) @dtree_iserror()
%21 = icmp eq i64 %20, 0
br i1 %21, label %13, label %22
22: ; preds = %16, %19, %13, %3
%23 = phi i32 [ 0, %3 ], [ 0, %13 ], [ 0, %19 ], [ 1, %16 ]
ret i32 %23
}