#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;
  scalar_t__ d_type;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_LNK;
scalar_t__ closedir(int /*<<< orphan*/ *);
char *create_full_path(char const *, struct dirent *);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
scalar_t__ is_numeric_string(char const *);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char const *);
int match_proc_files(const char *path, const char *dir_path, bool *matches) {
  int ret = 0;
  DIR *dir = NULL;
  struct dirent *entry = NULL;
  *matches = false;
  if ((dir = opendir(dir_path)) == NULL) {
    ret = -1;
    goto out;
  }
  while ((entry = readdir(dir)) != NULL && !*matches) {
    const char *filename = entry->d_name;
    if (entry->d_type == DT_LNK && is_numeric_string(filename)) {
      char *absolute_path = NULL;
      if ((absolute_path = create_full_path(dir_path, entry)) != NULL) {
        if (strcmp(absolute_path, path) == 0) {
          *matches = true;
        }
        free(absolute_path);
      }
    }
  }
  if (errno != 0) {
    ret = -1;
    goto out;
  }
out:
  if (dir && closedir(dir) != 0) {
    ret = -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<match_proc_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11c8 <match_proc_files+0x58>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12ba <match_proc_files+0x14a>
jmp    11cd <match_proc_files+0x5d>
mov    -0x28(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x41(%rbp)
je     11fb <match_proc_files+0x8b>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
setne  %al
xor    $0xff,%al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    120b <match_proc_files+0x9b>
jmp    1298 <match_proc_files+0x128>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2db3(%rip),%rcx
cmp    (%rcx),%rax
jne    1293 <match_proc_files+0x123>
mov    -0x38(%rbp),%rdi
call   1040 <is_numeric_string@plt>
cmp    $0x0,%rax
je     1293 <match_proc_files+0x123>
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <create_full_path@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     128e <match_proc_files+0x11e>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1285 <match_proc_files+0x115>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    1293 <match_proc_files+0x123>
jmp    11cd <match_proc_files+0x5d>
mov    0x2d41(%rip),%rax
cmpq   $0x0,(%rax)
je     12b5 <match_proc_files+0x145>
movl   $0xffffffff,-0x1c(%rbp)
jmp    12ba <match_proc_files+0x14a>
jmp    12ba <match_proc_files+0x14a>
cmpq   $0x0,-0x28(%rbp)
je     12df <match_proc_files+0x16f>
mov    -0x28(%rbp),%rdi
call   1060 <closedir@plt>
cmp    $0x0,%rax
je     12df <match_proc_files+0x16f>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_proc_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x0,(%rdx)
mov    %rsi,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     123c <match_proc_files+0xcc>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     121b <match_proc_files+0xab>
mov    %rax,%rbx
mov    0x2e23(%rip),%rbp
jmp    11d0 <match_proc_files+0x60>
mov    %rbx,%rdi
call   1030 <free@plt>
nop
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     121b <match_proc_files+0xab>
cmpl   $0x0,(%r12)
jne    121b <match_proc_files+0xab>
mov    0x8(%rbx),%rax
cmp    0x0(%rbp),%rax
jne    11c0 <match_proc_files+0x50>
mov    (%rbx),%rdi
call   1040 <is_numeric_string@plt>
test   %rax,%rax
je     11c0 <match_proc_files+0x50>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <create_full_path@plt>
test   %rax,%rax
je     11c0 <match_proc_files+0x50>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    11b7 <match_proc_files+0x47>
movl   $0x1,(%r12)
jmp    11b7 <match_proc_files+0x47>
mov    0x2dbe(%rip),%rax
mov    (%rax),%rbx
mov    %r13,%rdi
call   1060 <closedir@plt>
mov    %rax,%rcx
xor    %eax,%eax
or     %rbx,%rcx
setne  %al
neg    %eax
jmp    1241 <match_proc_files+0xd1>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8*, i64 }
@DT_LNK = global i64 0
@errno = global i64 0
define i32 @match_proc_files(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca %struct.dirent*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 0, i32* %7
store i32* null, i32** %8
store %struct.dirent* null, %struct.dirent** %9
%12 = load i32*, i32** %6
store i32 0, i32* %12
%13 = load i8*, i8** %5
%14 = call i32* @opendir(i8* %13)
store i32* %14, i32** %8
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %7
br label %64
17: ; preds = %3
br label %18
18: ; preds = %58, %17
%19 = load i32*, i32** %8
%20 = call %struct.dirent* @readdir(i32* %19)
store %struct.dirent* %20, %struct.dirent** %9
%21 = icmp ne %struct.dirent* %20, null
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32*, i32** %6
%24 = load i32, i32* %23
%25 = icmp ne i32 %24, 0
%26 = xor i1 %25, true
br label %27
27: ; preds = %22, %18
%28 = phi i1 [ false, %18 ], [ %26, %22 ]
br i1 %28, label %29, label %59
29: ; preds = %27
%30 = load %struct.dirent*, %struct.dirent** %9
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i8*, i8** %31
store i8* %32, i8** %10
%33 = load %struct.dirent*, %struct.dirent** %9
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 1
%35 = load i64, i64* %34
%36 = load i64, i64* @DT_LNK
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %58
38: ; preds = %29
%39 = load i8*, i8** %10
%40 = call i64 @is_numeric_string(i8* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %58
42: ; preds = %38
store i8* null, i8** %11
%43 = load i8*, i8** %5
%44 = load %struct.dirent*, %struct.dirent** %9
%45 = call i8* @create_full_path(i8* %43, %struct.dirent* %44)
store i8* %45, i8** %11
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %57
47: ; preds = %42
%48 = load i8*, i8** %11
%49 = load i8*, i8** %4
%50 = call i64 @strcmp(i8* %48, i8* %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = load i32*, i32** %6
store i32 1, i32* %53
br label %54
54: ; preds = %52, %47
%55 = load i8*, i8** %11
%56 = call i32 @free(i8* %55)
br label %57
57: ; preds = %54, %42
br label %58
58: ; preds = %57, %38, %29
br label %18
59: ; preds = %27
%60 = load i64, i64* @errno
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
store i32 -1, i32* %7
br label %64
63: ; preds = %59
br label %64
64: ; preds = %63, %62, %16
%65 = load i32*, i32** %8
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %72
67: ; preds = %64
%68 = load i32*, i32** %8
%69 = call i64 @closedir(i32* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %67
store i32 -1, i32* %7
br label %72
72: ; preds = %71, %67, %64
%73 = load i32, i32* %7
ret i32 %73
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i64 }
@DT_LNK = global i64 0
@errno = global i64 0
define i32 @match_proc_files(i8* %0, i8* %1, i32* nocapture %2) {
store i32 0, i32* %2
%4 = tail call i32* @opendir(i8* %1)
%5 = icmp eq i32* %4, null
br i1 %5, label %42, label %6
6: ; preds = %3
%7 = tail call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %35, label %9
9: ; preds = %6, %32
%10 = phi %struct.dirent* [ %33, %32 ], [ %7, %6 ]
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %9
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 1
%15 = load i64, i64* %14
%16 = load i64, i64* @DT_LNK
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %13
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = tail call i64 @is_numeric_string(i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %18
%24 = tail call i8* @create_full_path(i8* %1, %struct.dirent* %10)
%25 = icmp eq i8* %24, null
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = tail call i64 @strcmp(i8* %24, i8* %0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 1, i32* %2
br label %30
30: ; preds = %29, %26
%31 = tail call i32 @free(i8* %24)
br label %32
32: ; preds = %23, %30, %18, %13
%33 = tail call %struct.dirent* @readdir(i32* %4)
%34 = icmp eq %struct.dirent* %33, null
br i1 %34, label %35, label %9
35: ; preds = %9, %32, %6
%36 = load i64, i64* @errno
%37 = icmp ne i64 %36, 0
%38 = tail call i64 @closedir(i32* %4)
%39 = icmp ne i64 %38, 0
%40 = select i1 %39, i1 true, i1 %37
%41 = sext i1 %40 to i32
br label %42
42: ; preds = %3, %35
%43 = phi i32 [ %41, %35 ], [ -1, %3 ]
ret i32 %43
}