#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 udev_enumerate {
  int dummy;
};
struct udev {
  int dummy;
};
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ base;

/* Variables and functions */
int EINVAL;
scalar_t__ match_subsystem(struct udev_enumerate *, char *);
int /*<<< orphan*/ scan_dir(struct udev_enumerate *, char const *, char *,
                            char *);
int /*<<< orphan*/ scan_dir_and_add_devices(struct udev_enumerate *,
                                            char const *, int /*<<< orphan*/ *,
                                            int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
struct udev *udev_enumerate_get_udev(struct udev_enumerate *);
int /*<<< orphan*/ udev_get_sys_path(struct udev *);
int /*<<< orphan*/ udev_log_null(struct udev *, char *, char const *);
int /*<<< orphan*/ util_strscpyl(char *, int, int /*<<< orphan*/, char *,
                                 int /*<<< orphan*/ *);
__attribute__((visibility("default"))) int
udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate) {
  struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
  char base[1024];
  struct stat statbuf;
  const char *subsysdir;
  if (udev_enumerate == NULL)
    return -EINVAL;
  if (match_subsystem(udev_enumerate, "module")) {
    udev_log_null(udev, "searching '%s/modules/*' dir\n", subsysdir);
    scan_dir_and_add_devices(udev_enumerate, "module", NULL, NULL);
  }
  util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem",
                NULL);
  if (stat(base, &statbuf) == 0)
    subsysdir = "subsystem";
  else
    subsysdir = "bus";
  if (match_subsystem(udev_enumerate, "subsystem")) {
    udev_log_null(udev, "searching '%s/*' dir\n", subsysdir);
    scan_dir_and_add_devices(udev_enumerate, subsysdir, NULL, NULL);
  }
  if (match_subsystem(udev_enumerate, "drivers")) {
    udev_log_null(udev, "searching '%s/*/drivers/*' dir\n", subsysdir);
    scan_dir(udev_enumerate, subsysdir, "drivers", "drivers");
  }
  return 0;
}


x86 assembly (clang, -O0):
<udev_enumerate_scan_subsystems>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <udev_enumerate_get_udev@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ba <udev_enumerate_scan_subsystems+0x3a>
xor    %eax,%eax
mov    0x2e30(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1310 <udev_enumerate_scan_subsystems+0x190>
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   10a0 <match_subsystem@plt>
cmp    $0x0,%rax
je     1202 <udev_enumerate_scan_subsystems+0x82>
mov    -0x18(%rbp),%rdi
mov    -0x430(%rbp),%rdx
lea    0xe21(%rip),%rsi
call   1050 <udev_log_null@plt>
mov    -0x10(%rbp),%rdi
lea    0xe0a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1070 <scan_dir_and_add_devices@plt>
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <udev_get_sys_path@plt>
mov    -0x438(%rbp),%rdi
mov    %eax,%edx
mov    $0x400,%esi
lea    0xdf7(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1090 <util_strscpyl@plt>
lea    -0x420(%rbp),%rdi
lea    -0x428(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    1268 <udev_enumerate_scan_subsystems+0xe8>
lea    0xdca(%rip),%rax
mov    %rax,-0x430(%rbp)
jmp    1276 <udev_enumerate_scan_subsystems+0xf6>
lea    0xdc1(%rip),%rax
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xda5(%rip),%rsi
call   10a0 <match_subsystem@plt>
cmp    $0x0,%rax
je     12be <udev_enumerate_scan_subsystems+0x13e>
mov    -0x18(%rbp),%rdi
mov    -0x430(%rbp),%rdx
lea    0xd92(%rip),%rsi
call   1050 <udev_log_null@plt>
mov    -0x10(%rbp),%rdi
mov    -0x430(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1070 <scan_dir_and_add_devices@plt>
mov    -0x10(%rbp),%rdi
lea    0xd81(%rip),%rsi
call   10a0 <match_subsystem@plt>
cmp    $0x0,%rax
je     1309 <udev_enumerate_scan_subsystems+0x189>
mov    -0x18(%rbp),%rdi
mov    -0x430(%rbp),%rdx
lea    0xd68(%rip),%rsi
call   1050 <udev_log_null@plt>
mov    -0x10(%rbp),%rdi
mov    -0x430(%rbp),%rsi
lea    0xd49(%rip),%rcx
mov    %rcx,%rdx
call   1030 <scan_dir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udev_enumerate_scan_subsystems>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%r12
call   1080 <udev_enumerate_get_udev@plt>
test   %r12,%r12
je     128e <udev_enumerate_scan_subsystems+0x10e>
mov    %rax,%r14
lea    0xe57(%rip),%rsi
mov    %r12,%rdi
call   10a0 <match_subsystem@plt>
test   %rax,%rax
je     11d8 <udev_enumerate_scan_subsystems+0x58>
lea    0xe4a(%rip),%rsi
mov    %r14,%rdi
call   1050 <udev_log_null@plt>
lea    0xe34(%rip),%rsi
mov    %r12,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <scan_dir_and_add_devices@plt>
mov    %r14,%rdi
call   1040 <udev_get_sys_path@plt>
lea    0xe3e(%rip),%rcx
xor    %r15d,%r15d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %eax,%edx
xor    %r8d,%r8d
call   1090 <util_strscpyl@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
test   %rax,%rax
lea    0xe0e(%rip),%rsi
lea    0xe11(%rip),%rbx
cmove  %rsi,%rbx
mov    %r12,%rdi
call   10a0 <match_subsystem@plt>
test   %rax,%rax
je     1251 <udev_enumerate_scan_subsystems+0xd1>
lea    0xdfd(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <udev_log_null@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <scan_dir_and_add_devices@plt>
lea    0xdf2(%rip),%rsi
mov    %r12,%rdi
call   10a0 <match_subsystem@plt>
test   %rax,%rax
je     129b <udev_enumerate_scan_subsystems+0x11b>
lea    0xde6(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <udev_log_null@plt>
lea    0xdcc(%rip),%rcx
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %rcx,%rdx
call   1030 <scan_dir@plt>
jmp    129b <udev_enumerate_scan_subsystems+0x11b>
mov    0x2d4b(%rip),%rax
xor    %r15d,%r15d
sub    (%rax),%r15d
mov    %r15d,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev_enumerate = type { i32 }
%struct.udev = type { i32 }
%struct.stat = type { i32 }
@EINVAL = global i32 0
@.str = [7 x i8] c"module\00"
@.str.1 = [30 x i8] c"searching '%s/modules/*' dir\0A\00"
@.str.2 = [11 x i8] c"/subsystem\00"
@.str.3 = [10 x i8] c"subsystem\00"
@.str.4 = [4 x i8] c"bus\00"
@.str.5 = [22 x i8] c"searching '%s/*' dir\0A\00"
@.str.6 = [8 x i8] c"drivers\00"
@.str.7 = [32 x i8] c"searching '%s/*/drivers/*' dir\0A\00"
define i32 @udev_enumerate_scan_subsystems(%struct.udev_enumerate* %0) {
%2 = alloca i32
%3 = alloca %struct.udev_enumerate*
%4 = alloca %struct.udev*
%5 = alloca [1024 x i8]
%6 = alloca %struct.stat
%7 = alloca i8*
store %struct.udev_enumerate* %0, %struct.udev_enumerate** %3
%8 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%9 = call %struct.udev* @udev_enumerate_get_udev(%struct.udev_enumerate* %8)
store %struct.udev* %9, %struct.udev** %4
%10 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%11 = icmp eq %struct.udev_enumerate* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* @EINVAL
%14 = sub nsw i32 0, %13
store i32 %14, i32* %2
br label %58
15: ; preds = %1
%16 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%17 = call i64 @match_subsystem(%struct.udev_enumerate* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load %struct.udev*, %struct.udev** %4
%21 = load i8*, i8** %7
%22 = call i32 @udev_log_null(%struct.udev* %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%24 = call i32 @scan_dir_and_add_devices(%struct.udev_enumerate* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* null, i32* null)
br label %25
25: ; preds = %19, %15
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%27 = load %struct.udev*, %struct.udev** %4
%28 = call i32 @udev_get_sys_path(%struct.udev* %27)
%29 = call i32 @util_strscpyl(i8* %26, i32 1024, i32 %28, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32* null)
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%31 = call i64 @stat(i8* %30, %struct.stat* %6)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %25
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %35
34: ; preds = %25
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %35
35: ; preds = %34, %33
%36 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%37 = call i64 @match_subsystem(%struct.udev_enumerate* %36, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = load %struct.udev*, %struct.udev** %4
%41 = load i8*, i8** %7
%42 = call i32 @udev_log_null(%struct.udev* %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%44 = load i8*, i8** %7
%45 = call i32 @scan_dir_and_add_devices(%struct.udev_enumerate* %43, i8* %44, i32* null, i32* null)
br label %46
46: ; preds = %39, %35
%47 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%48 = call i64 @match_subsystem(%struct.udev_enumerate* %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %46
%51 = load %struct.udev*, %struct.udev** %4
%52 = load i8*, i8** %7
%53 = call i32 @udev_log_null(%struct.udev* %51, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %52)
%54 = load %struct.udev_enumerate*, %struct.udev_enumerate** %3
%55 = load i8*, i8** %7
%56 = call i32 @scan_dir(%struct.udev_enumerate* %54, i8* %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %57
57: ; preds = %50, %46
store i32 0, i32* %2
br label %58
58: ; preds = %57, %12
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
%struct.udev_enumerate = type { i32 }
%struct.stat = type { i32 }
%struct.udev = type { i32 }
@EINVAL = global i32 0
@.str = [7 x i8] c"module\00"
@.str.1 = [30 x i8] c"searching '%s/modules/*' dir\0A\00"
@.str.2 = [11 x i8] c"/subsystem\00"
@.str.3 = [10 x i8] c"subsystem\00"
@.str.4 = [4 x i8] c"bus\00"
@.str.5 = [22 x i8] c"searching '%s/*' dir\0A\00"
@.str.6 = [8 x i8] c"drivers\00"
@.str.7 = [32 x i8] c"searching '%s/*/drivers/*' dir\0A\00"
define i32 @udev_enumerate_scan_subsystems(%struct.udev_enumerate* %0) {
%2 = alloca [1024 x i8]
%3 = alloca %struct.stat
%4 = tail call %struct.udev* @udev_enumerate_get_udev(%struct.udev_enumerate* %0)
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = bitcast %struct.stat* %3 to i8*
%7 = icmp eq %struct.udev_enumerate* %0, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @EINVAL
%10 = sub nsw i32 0, %9
br label %34
11: ; preds = %1
%12 = tail call i64 @match_subsystem(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @udev_log_null(%struct.udev* %4, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* undef)
%16 = tail call i32 @scan_dir_and_add_devices(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* null, i32* null)
br label %17
17: ; preds = %14, %11
%18 = tail call i32 @udev_get_sys_path(%struct.udev* %4)
%19 = call i32 @util_strscpyl(i8* %5, i32 1024, i32 %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32* null)
%20 = call i64 @stat(i8* %5, %struct.stat* %3)
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0)
%23 = call i64 @match_subsystem(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %17
%26 = call i32 @udev_log_null(%struct.udev* %4, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %22)
%27 = call i32 @scan_dir_and_add_devices(%struct.udev_enumerate* %0, i8* %22, i32* null, i32* null)
br label %28
28: ; preds = %25, %17
%29 = call i64 @match_subsystem(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = call i32 @udev_log_null(%struct.udev* %4, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i8* %22)
%33 = call i32 @scan_dir(%struct.udev_enumerate* %0, i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %34
34: ; preds = %28, %31, %8
%35 = phi i32 [ %10, %8 ], [ 0, %31 ], [ 0, %28 ]
ret i32 %35
}