#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 stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ scan_dir(struct udev_enumerate *, char *, char *,
                            int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
int scan_devices_all(struct udev_enumerate *udev_enumerate) {
  struct stat statbuf;
  if (stat("/sys/subsystem", &statbuf) == 0) {
    scan_dir(udev_enumerate, "subsystem", "devices", NULL);
  } else {
    scan_dir(udev_enumerate, "bus", "devices", NULL);
    scan_dir(udev_enumerate, "class", NULL, NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<scan_devices_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jne    1166 <scan_devices_all+0x46>
mov    -0x8(%rbp),%rdi
lea    0xeb4(%rip),%rsi
lea    0xeb7(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <scan_dir@plt>
jmp    1198 <scan_devices_all+0x78>
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
lea    0xe97(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <scan_dir@plt>
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <scan_dir@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_devices_all>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xed1(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
je     1164 <scan_devices_all+0x44>
lea    0xed2(%rip),%rsi
lea    0xec3(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
call   1030 <scan_dir@plt>
lea    0xebe(%rip),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
jmp    1175 <scan_devices_all+0x55>
lea    0xe9a(%rip),%rsi
lea    0xe9d(%rip),%rdx
mov    %rbx,%rdi
xor    %ecx,%ecx
call   1030 <scan_dir@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.udev_enumerate = type { i32 }
%struct.stat = type { i32 }
@.str = [15 x i8] c"/sys/subsystem\00"
@.str.1 = [10 x i8] c"subsystem\00"
@.str.2 = [8 x i8] c"devices\00"
@.str.3 = [4 x i8] c"bus\00"
@.str.4 = [6 x i8] c"class\00"
define i32 @scan_devices_all(%struct.udev_enumerate* %0) {
%2 = alloca %struct.udev_enumerate*
%3 = alloca %struct.stat
store %struct.udev_enumerate* %0, %struct.udev_enumerate** %2
%4 = call i64 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load %struct.udev_enumerate*, %struct.udev_enumerate** %2
%8 = call i32 @scan_dir(%struct.udev_enumerate* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %14
9: ; preds = %1
%10 = load %struct.udev_enumerate*, %struct.udev_enumerate** %2
%11 = call i32 @scan_dir(%struct.udev_enumerate* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
%12 = load %struct.udev_enumerate*, %struct.udev_enumerate** %2
%13 = call i32 @scan_dir(%struct.udev_enumerate* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* null, i32* null)
br label %14
14: ; preds = %9, %6
ret i32 0
}

LLVM IR (-O2):
%struct.udev_enumerate = type { i32 }
%struct.stat = type { i32 }
@.str = [15 x i8] c"/sys/subsystem\00"
@.str.1 = [10 x i8] c"subsystem\00"
@.str.2 = [8 x i8] c"devices\00"
@.str.3 = [4 x i8] c"bus\00"
@.str.4 = [6 x i8] c"class\00"
define i32 @scan_devices_all(%struct.udev_enumerate* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = call i64 @stat(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.stat* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @scan_dir(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
br label %11
8: ; preds = %1
%9 = call i32 @scan_dir(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* null)
%10 = call i32 @scan_dir(%struct.udev_enumerate* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* null, i32* null)
br label %11
11: ; preds = %8, %6
ret i32 0
}