#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 /*<<< orphan*/ scan_dir(struct udev_enumerate *, char *, char *,
                            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 *);
int /*<<< orphan*/ util_strscpyl(char *, int, int /*<<< orphan*/, char *,
                                 int /*<<< orphan*/ *);
int scan_devices_all(struct udev_enumerate *udev_enumerate) {
  struct udev *udev = udev_enumerate_get_udev(udev_enumerate);
  char base[1024];
  struct stat statbuf;
  util_strscpyl(base, sizeof(base), udev_get_sys_path(udev), "/subsystem",
                NULL);
  if (stat(base, &statbuf) == 0) {
    udev_log_null(udev, "searching '/subsystem/*/devices/*' dir\n");
    scan_dir(udev_enumerate, "subsystem", "devices", NULL);
  } else {
    udev_log_null(udev, "searching '/bus/*/devices/*' dir\n");
    scan_dir(udev_enumerate, "bus", "devices", NULL);
    udev_log_null(udev, "searching '/class/*' dir\n");
    scan_dir(udev_enumerate, "class", NULL, NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<scan_devices_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <udev_enumerate_get_udev@plt>
mov    %rax,-0x10(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <udev_get_sys_path@plt>
mov    -0x420(%rbp),%rdi
mov    %eax,%edx
mov    $0x400,%esi
lea    0xe58(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <util_strscpyl@plt>
lea    -0x410(%rbp),%rdi
lea    -0x418(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jne    11ff <scan_devices_all+0x9f>
mov    -0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1050 <udev_log_null@plt>
mov    -0x8(%rbp),%rdi
lea    0xe17(%rip),%rsi
lea    0xe42(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <scan_dir@plt>
jmp    1251 <scan_devices_all+0xf1>
mov    -0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1050 <udev_log_null@plt>
mov    -0x8(%rbp),%rdi
lea    0xe43(%rip),%rsi
lea    0xe12(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <scan_dir@plt>
mov    -0x10(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1050 <udev_log_null@plt>
mov    -0x8(%rbp),%rdi
lea    0xe36(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <scan_dir@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_devices_all>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rdi,%r14
call   1070 <udev_enumerate_get_udev@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <udev_get_sys_path@plt>
lea    0xe7a(%rip),%rcx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x400,%esi
mov    %eax,%edx
xor    %r8d,%r8d
call   1080 <util_strscpyl@plt>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1060 <stat@plt>
test   %rax,%rax
je     11f3 <scan_devices_all+0x93>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1050 <udev_log_null@plt>
lea    0xe98(%rip),%rsi
lea    0xe67(%rip),%rdx
mov    %r14,%rdi
xor    %ecx,%ecx
call   1030 <scan_dir@plt>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1050 <udev_log_null@plt>
lea    0xe8f(%rip),%rsi
mov    %r14,%rdi
xor    %edx,%edx
jmp    1213 <scan_devices_all+0xb3>
lea    0xe11(%rip),%rsi
mov    %rbx,%rdi
call   1050 <udev_log_null@plt>
lea    0xdf8(%rip),%rsi
lea    0xe23(%rip),%rdx
mov    %r14,%rdi
xor    %ecx,%ecx
call   1030 <scan_dir@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.udev_enumerate = type { i32 }
%struct.udev = type { i32 }
%struct.stat = type { i32 }
@.str = [11 x i8] c"/subsystem\00"
@.str.1 = [40 x i8] c"searching '/subsystem/*/devices/*' dir\0A\00"
@.str.2 = [10 x i8] c"subsystem\00"
@.str.3 = [8 x i8] c"devices\00"
@.str.4 = [34 x i8] c"searching '/bus/*/devices/*' dir\0A\00"
@.str.5 = [4 x i8] c"bus\00"
@.str.6 = [26 x i8] c"searching '/class/*' dir\0A\00"
@.str.7 = [6 x i8] c"class\00"
define i32 @scan_devices_all(%struct.udev_enumerate* %0) {
%2 = alloca %struct.udev_enumerate*
%3 = alloca %struct.udev*
%4 = alloca [1024 x i8]
%5 = alloca %struct.stat
store %struct.udev_enumerate* %0, %struct.udev_enumerate** %2
%6 = load %struct.udev_enumerate*, %struct.udev_enumerate** %2
%7 = call %struct.udev* @udev_enumerate_get_udev(%struct.udev_enumerate* %6)
store %struct.udev* %7, %struct.udev** %3
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = load %struct.udev*, %struct.udev** %3
%10 = call i32 @udev_get_sys_path(%struct.udev* %9)
%11 = call i32 @util_strscpyl(i8* %8, i32 1024, i32 %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* null)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%13 = call i64 @stat(i8* %12, %struct.stat* %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = load %struct.udev*, %struct.udev** %3
%17 = call i32 @udev_log_null(%struct.udev* %16, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%18 = load %struct.udev_enumerate*, %struct.udev_enumerate** %2
%19 = call i32 @scan_dir(%struct.udev_enumerate* %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %29
20: ; preds = %1
%21 = load %struct.udev*, %struct.udev** %3
%22 = call i32 @udev_log_null(%struct.udev* %21, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%23 = load %struct.udev_enumerate*, %struct.udev_enumerate** %2
%24 = call i32 @scan_dir(%struct.udev_enumerate* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* null)
%25 = load %struct.udev*, %struct.udev** %3
%26 = call i32 @udev_log_null(%struct.udev* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%27 = load %struct.udev_enumerate*, %struct.udev_enumerate** %2
%28 = call i32 @scan_dir(%struct.udev_enumerate* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* null, i32* null)
br label %29
29: ; preds = %20, %15
ret i32 0
}

LLVM IR (-O2):
%struct.udev_enumerate = type { i32 }
%struct.stat = type { i32 }
%struct.udev = type { i32 }
@.str = [11 x i8] c"/subsystem\00"
@.str.1 = [40 x i8] c"searching '/subsystem/*/devices/*' dir\0A\00"
@.str.2 = [10 x i8] c"subsystem\00"
@.str.3 = [8 x i8] c"devices\00"
@.str.4 = [34 x i8] c"searching '/bus/*/devices/*' dir\0A\00"
@.str.5 = [4 x i8] c"bus\00"
@.str.6 = [26 x i8] c"searching '/class/*' dir\0A\00"
@.str.7 = [6 x i8] c"class\00"
define i32 @scan_devices_all(%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 = tail call i32 @udev_get_sys_path(%struct.udev* %4)
%8 = call i32 @util_strscpyl(i8* %5, i32 1024, i32 %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* null)
%9 = call i64 @stat(i8* %5, %struct.stat* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @udev_log_null(%struct.udev* %4, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @scan_dir(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %19
14: ; preds = %1
%15 = call i32 @udev_log_null(%struct.udev* %4, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @scan_dir(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* null)
%17 = call i32 @udev_log_null(%struct.udev* %4, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 @scan_dir(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* null, i32* null)
br label %19
19: ; preds = %14, %11
ret i32 0
}