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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int pow(int, size_t);
struct dirent *readdir(int /*<<< orphan*/ *);
int readlink(char *, char *, int);
scalar_t__ *realloc(scalar_t__ *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int /*<<< orphan*/ strncmp(char *, char *, int);
unsigned long long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
pid_t *find_handlers() {
  DIR *d, *d1;
  struct dirent *entry, *e1;
  pid_t *res, cur_pid;
  char path_buffer[255], link_buffer[(17 + 1)];
  ssize_t link_size;
  size_t pid_size;
  unsigned long long pid_mask;
  int found;
  d = opendir("/proc");
  if (!d)
    return NULL;
  pid_size = sizeof(pid_t);
  pid_mask = pow(2, (pid_size * 8)) - 1;
  found = 0;
  res = NULL;
  while ((entry = readdir(d))) {
    if ((cur_pid = (pid_t)(strtoul(entry->d_name, NULL, 0) & pid_mask)) == 0)
      continue;
    snprintf(path_buffer, 255, "/proc/%s/fd/", entry->d_name);
    if (!(d1 = opendir(path_buffer)))
      continue;
    while ((e1 = readdir(d1))) {
      snprintf(path_buffer, 255, "/proc/%s/fd/%s", entry->d_name, e1->d_name);
      link_size = readlink(path_buffer, link_buffer, (17 + 1));
      if ((link_size == 17 && !strncmp("/proc/fs/fuse/dev", link_buffer, 17)) ||
          (link_size == 9 && !strncmp("/dev/fuse", link_buffer, 9))) {
        res = realloc(res, ((found + 1) * pid_size));
        *(res + found) = cur_pid;
        found++;
        break;
      }
    }
    closedir(d1);
  }
  closedir(d);
  if (res)
    *(res + found + 1) = 0;
  return res;
}


x86 assembly (clang, -O0):
<find_handlers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
lea    0xe5e(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c3 <find_handlers+0x33>
movq   $0x0,-0x8(%rbp)
jmp    13ce <find_handlers+0x23e>
movq   $0x8,-0x170(%rbp)
mov    -0x170(%rbp),%rsi
shl    $0x3,%rsi
mov    $0x2,%edi
call   10a0 <pow@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x178(%rbp)
movl   $0x0,-0x17c(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     139e <find_handlers+0x20e>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
and    -0x178(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1244 <find_handlers+0xb4>
jmp    1201 <find_handlers+0x71>
lea    -0x140(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    $0xff,%esi
lea    0xda8(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x140(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1284 <find_handlers+0xf4>
jmp    1201 <find_handlers+0x71>
jmp    1289 <find_handlers+0xf9>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1390 <find_handlers+0x200>
lea    -0x140(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%rax
mov    (%rax),%r8
mov    $0xff,%esi
lea    0xd52(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x140(%rbp),%rdi
lea    -0x160(%rbp),%rsi
mov    $0x12,%edx
call   1040 <readlink@plt>
mov    %eax,-0x164(%rbp)
cmpl   $0x11,-0x164(%rbp)
jne    1314 <find_handlers+0x184>
lea    -0x160(%rbp),%rsi
lea    0xd21(%rip),%rdi
mov    $0x11,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     1342 <find_handlers+0x1b2>
cmpl   $0x9,-0x164(%rbp)
jne    138b <find_handlers+0x1fb>
lea    -0x160(%rbp),%rsi
lea    0xd05(%rip),%rdi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    138b <find_handlers+0x1fb>
mov    -0x30(%rbp),%rdi
mov    -0x17c(%rbp),%eax
add    $0x1,%eax
cltq
imul   -0x170(%rbp),%rax
ff
mov    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rax
movslq -0x17c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x17c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x17c(%rbp)
jmp    1390 <find_handlers+0x200>
jmp    1289 <find_handlers+0xf9>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
jmp    1201 <find_handlers+0x71>
mov    -0x10(%rbp),%rdi
call   1070 <closedir@plt>
cmpq   $0x0,-0x30(%rbp)
je     13c6 <find_handlers+0x236>
mov    -0x30(%rbp),%rax
movslq -0x17c(%rbp),%rcx
movq   $0x0,0x8(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_handlers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
lea    0xe58(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1378 <find_handlers+0x1e8>
mov    %rax,%r15
mov    $0x40,%esi
mov    $0x2,%edi
call   10a0 <pow@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11f5 <find_handlers+0x65>
mov    %rax,%r13
add    $0xffffffff,%ebp
movslq %ebp,%r12
lea    0x40(%rsp),%rbx
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
mov    %rax,0x10(%rsp)
jmp    1264 <find_handlers+0xd4>
mov    %r15,%rdi
call   1070 <closedir@plt>
jmp    1378 <find_handlers+0x1e8>
mov    0x8(%rsp),%r13
lea    0x1(%r13),%ebx
lea    0x8(,%r13,8),%esi
mov    0x10(%rsp),%rdi
call   1090 <realloc@plt>
movslq %r13d,%rdx
mov    %rax,%rcx
mov    %rax,0x10(%rsp)
mov    %rbp,(%rax,%rdx,8)
mov    %ebx,%eax
mov    %rax,0x8(%rsp)
lea    0x40(%rsp),%rbx
mov    0x18(%rsp),%r15
mov    %r14,%rdi
call   1070 <closedir@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1080 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1356 <find_handlers+0x1c6>
mov    0x0(%r13),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %rax,%rbp
and    %r12,%rbp
je     1250 <find_handlers+0xc0>
mov    0x0(%r13),%rcx
mov    %rbx,%rdi
mov    $0xff,%esi
lea    0xd7a(%rip),%rdx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1250 <find_handlers+0xc0>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     123d <find_handlers+0xad>
mov    %r15,0x18(%rsp)
jmp    12f5 <find_handlers+0x165>
nopw   0x0(%rax,%rax,1)
lea    0xd6d(%rip),%rdi
mov    %r12,%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
mov    %r15,%r12
je     1202 <find_handlers+0x72>
mov    %r14,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
lea    0x40(%rsp),%rbx
je     1238 <find_handlers+0xa8>
mov    %r12,%r15
mov    0x0(%r13),%rcx
mov    (%rax),%r8
mov    %rbx,%rdi
mov    $0xff,%esi
lea    0xd05(%rip),%rdx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %rbx,%rdi
lea    0x20(%rsp),%r12
mov    %r12,%rsi
mov    $0x12,%edx
call   1040 <readlink@plt>
cmp    $0x9,%eax
je     12c0 <find_handlers+0x130>
cmp    $0x11,%eax
mov    %r15,%r12
jne    12df <find_handlers+0x14f>
lea    0xce4(%rip),%rdi
lea    0x20(%rsp),%rsi
mov    $0x11,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    12df <find_handlers+0x14f>
jmp    1202 <find_handlers+0x72>
mov    %r15,%rdi
call   1070 <closedir@plt>
mov    0x10(%rsp),%rax
test   %rax,%rax
je     1378 <find_handlers+0x1e8>
movslq 0x8(%rsp),%rcx
movq   $0x0,0x8(%rax,%rcx,8)
jmp    137a <find_handlers+0x1ea>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [13 x i8] c"/proc/%s/fd/\00"
@.str.2 = [15 x i8] c"/proc/%s/fd/%s\00"
@.str.3 = [18 x i8] c"/proc/fs/fuse/dev\00"
@.str.4 = [10 x i8] c"/dev/fuse\00"
define i64* @find_handlers() {
%1 = alloca i64*
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca %struct.dirent*
%6 = alloca i64*
%7 = alloca i64
%8 = alloca [255 x i8]
%9 = alloca [18 x i8]
%10 = alloca i32
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %2
%15 = load i32*, i32** %2
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %0
store i64* null, i64** %1
br label %110
18: ; preds = %0
store i64 8, i64* %11
%19 = load i64, i64* %11
%20 = mul i64 %19, 8
%21 = call i32 @pow(i32 2, i64 %20)
%22 = sub nsw i32 %21, 1
%23 = sext i32 %22 to i64
store i64 %23, i64* %12
store i32 0, i32* %13
store i64* null, i64** %6
br label %24
24: ; preds = %94, %46, %36, %18
%25 = load i32*, i32** %2
%26 = call %struct.dirent* @readdir(i32* %25)
store %struct.dirent* %26, %struct.dirent** %4
%27 = icmp ne %struct.dirent* %26, null
br i1 %27, label %28, label %97
28: ; preds = %24
%29 = load %struct.dirent*, %struct.dirent** %4
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i64 @strtoul(i8* %31, i32* null, i32 0)
%33 = load i64, i64* %12
%34 = and i64 %32, %33
store i64 %34, i64* %7
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %28
br label %24
37: ; preds = %28
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%39 = load %struct.dirent*, %struct.dirent** %4
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %38, i32 255, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%44 = call i32* @opendir(i8* %43)
store i32* %44, i32** %3
%45 = icmp ne i32* %44, null
br i1 %45, label %47, label %46
46: ; preds = %37
br label %24
47: ; preds = %37
br label %48
48: ; preds = %93, %47
%49 = load i32*, i32** %3
%50 = call %struct.dirent* @readdir(i32* %49)
store %struct.dirent* %50, %struct.dirent** %5
%51 = icmp ne %struct.dirent* %50, null
br i1 %51, label %52, label %94
52: ; preds = %48
%53 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%54 = load %struct.dirent*, %struct.dirent** %4
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = load %struct.dirent*, %struct.dirent** %5
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %53, i32 255, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %56, i8* %59)
%61 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%62 = getelementptr inbounds [18 x i8], [18 x i8]* %9, i64 0, i64 0
%63 = call i32 @readlink(i8* %61, i8* %62, i32 18)
store i32 %63, i32* %10
%64 = load i32, i32* %10
%65 = icmp eq i32 %64, 17
br i1 %65, label %66, label %70
66: ; preds = %52
%67 = getelementptr inbounds [18 x i8], [18 x i8]* %9, i64 0, i64 0
%68 = call i32 @strncmp(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %67, i32 17)
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %77
70: ; preds = %66, %52
%71 = load i32, i32* %10
%72 = icmp eq i32 %71, 9
br i1 %72, label %73, label %93
73: ; preds = %70
%74 = getelementptr inbounds [18 x i8], [18 x i8]* %9, i64 0, i64 0
%75 = call i32 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %74, i32 9)
%76 = icmp ne i32 %75, 0
br i1 %76, label %93, label %77
77: ; preds = %73, %66
%78 = load i64*, i64** %6
%79 = load i32, i32* %13
%80 = add nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = load i64, i64* %11
%83 = mul i64 %81, %82
%84 = trunc i64 %83 to i32
%85 = call i64* @realloc(i64* %78, i32 %84)
store i64* %85, i64** %6
%86 = load i64, i64* %7
%87 = load i64*, i64** %6
%88 = load i32, i32* %13
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i64, i64* %87, i64 %89
store i64 %86, i64* %90
%91 = load i32, i32* %13
%92 = add nsw i32 %91, 1
store i32 %92, i32* %13
br label %94
93: ; preds = %73, %70
br label %48
94: ; preds = %77, %48
%95 = load i32*, i32** %3
%96 = call i32 @closedir(i32* %95)
br label %24
97: ; preds = %24
%98 = load i32*, i32** %2
%99 = call i32 @closedir(i32* %98)
%100 = load i64*, i64** %6
%101 = icmp ne i64* %100, null
br i1 %101, label %102, label %108
102: ; preds = %97
%103 = load i64*, i64** %6
%104 = load i32, i32* %13
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i64, i64* %103, i64 %105
%107 = getelementptr inbounds i64, i64* %106, i64 1
store i64 0, i64* %107
br label %108
108: ; preds = %102, %97
%109 = load i64*, i64** %6
store i64* %109, i64** %1
br label %110
110: ; preds = %108, %17
%111 = load i64*, i64** %1
ret i64* %111
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [13 x i8] c"/proc/%s/fd/\00"
@.str.2 = [15 x i8] c"/proc/%s/fd/%s\00"
@.str.3 = [18 x i8] c"/proc/fs/fuse/dev\00"
@.str.4 = [10 x i8] c"/dev/fuse\00"
define i64* @find_handlers() {
%1 = alloca [255 x i8]
%2 = alloca [18 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [18 x i8], [18 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %74, label %7
7: ; preds = %0
%8 = tail call i32 @pow(i32 2, i64 64)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = call %struct.dirent* @readdir(i32* %5)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = call i32 @closedir(i32* %5)
br label %74
15: ; preds = %7, %59
%16 = phi %struct.dirent* [ %63, %59 ], [ %11, %7 ]
%17 = phi i32 [ %61, %59 ], [ 0, %7 ]
%18 = phi i64* [ %60, %59 ], [ null, %7 ]
br label %19
19: ; preds = %15, %26
%20 = phi %struct.dirent* [ %16, %15 ], [ %27, %26 ]
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = call i64 @strtoul(i8* nocapture %22, i32* null, i32 0)
%24 = and i64 %23, %10
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %19, %29
%27 = call %struct.dirent* @readdir(i32* %5)
%28 = icmp eq %struct.dirent* %27, null
br i1 %28, label %65, label %19
29: ; preds = %19
%30 = load i8*, i8** %21
%31 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %3, i32 255, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32* @opendir(i8* %3)
%33 = icmp eq i32* %32, null
br i1 %33, label %26, label %34
34: ; preds = %29
%35 = call %struct.dirent* @readdir(i32* %32)
%36 = icmp eq %struct.dirent* %35, null
br i1 %36, label %59, label %37
37: ; preds = %34, %56
%38 = phi %struct.dirent* [ %57, %56 ], [ %35, %34 ]
%39 = load i8*, i8** %21
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i64 0, i32 0
%41 = load i8*, i8** %40
%42 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %3, i32 255, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %39, i8* %41)
%43 = call i32 @readlink(i8* %3, i8* %4, i32 18)
switch i32 %43, label %56 [
i32 17, label %44
i32 9, label %47
]
44: ; preds = %37
%45 = call i32 @strncmp(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 17)
%46 = icmp eq i32 %45, 0
br i1 %46, label %50, label %56
47: ; preds = %37
%48 = call i32 @strncmp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %4, i32 9)
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %47, %44
%51 = add nsw i32 %17, 1
%52 = shl i32 %51, 3
%53 = call i64* @realloc(i64* %18, i32 %52)
%54 = sext i32 %17 to i64
%55 = getelementptr inbounds i64, i64* %53, i64 %54
store i64 %24, i64* %55
br label %59
56: ; preds = %44, %37, %47
%57 = call %struct.dirent* @readdir(i32* %32)
%58 = icmp eq %struct.dirent* %57, null
br i1 %58, label %59, label %37
59: ; preds = %56, %34, %50
%60 = phi i64* [ %53, %50 ], [ %18, %34 ], [ %18, %56 ]
%61 = phi i32 [ %51, %50 ], [ %17, %34 ], [ %17, %56 ]
%62 = call i32 @closedir(i32* %32)
%63 = call %struct.dirent* @readdir(i32* %5)
%64 = icmp eq %struct.dirent* %63, null
br i1 %64, label %65, label %15
65: ; preds = %59, %26
%66 = phi i64* [ %18, %26 ], [ %60, %59 ]
%67 = phi i32 [ %17, %26 ], [ %61, %59 ]
%68 = call i32 @closedir(i32* %5)
%69 = icmp eq i64* %66, null
br i1 %69, label %74, label %70
70: ; preds = %65
%71 = sext i32 %67 to i64
%72 = getelementptr inbounds i64, i64* %66, i64 %71
%73 = getelementptr inbounds i64, i64* %72, i64 1
store i64 0, i64* %73
br label %74
74: ; preds = %13, %65, %70, %0
%75 = phi i64* [ null, %0 ], [ %66, %70 ], [ null, %65 ], [ null, %13 ]
ret i64* %75
}