#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 /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ pci_scan_node(char *, char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int dir_scan_for_subdir_files(char *location, int lvl, char *bus, char *node) {
  DIR *dir1 = NULL;
  struct dirent *dirent1 = NULL;
  char PathName[256];
  dir1 = opendir(location);
  if (dir1 == NULL)
    return 0;
  for (dirent1 = readdir(dir1); dirent1 != NULL; dirent1 = readdir(dir1)) {
    if (dirent1->d_name[0] == '.')
      continue;
    if (dirent1->d_name[0] == 'd')
      continue;
    snprintf(PathName, 256, "%s/%s", location, dirent1->d_name);
    if (lvl == 0)
      dir_scan_for_subdir_files(PathName, 1, dirent1->d_name, node);
    else
      pci_scan_node(PathName, bus, dirent1->d_name);
  }
  return !0;
}


x86 assembly (clang, -O0):
<dir_scan_for_subdir_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119e <dir_scan_for_subdir_files+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    1269 <dir_scan_for_subdir_files+0x119>
mov    -0x30(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1262 <dir_scan_for_subdir_files+0x112>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ce <dir_scan_for_subdir_files+0x7e>
jmp    1250 <dir_scan_for_subdir_files+0x100>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x64,%eax
jne    11e6 <dir_scan_for_subdir_files+0x96>
jmp    1250 <dir_scan_for_subdir_files+0x100>
lea    -0x140(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    (%rax),%r8
mov    $0x100,%esi
lea    0xdfc(%rip),%rdx
call   1040 <snprintf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1234 <dir_scan_for_subdir_files+0xe4>
lea    -0x140(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    (%rax),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1050 <dir_scan_for_subdir_files@plt>
jmp    124b <dir_scan_for_subdir_files+0xfb>
lea    -0x140(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    (%rax),%rdx
call   1060 <pci_scan_node@plt>
jmp    1250 <dir_scan_for_subdir_files+0x100>
mov    -0x30(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x38(%rbp)
jmp    11ab <dir_scan_for_subdir_files+0x5b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_scan_for_subdir_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rdx,%r13
mov    %esi,0xc(%rsp)
mov    %rdi,0x18(%rsp)
call   1030 <opendir@plt>
test   %rax,%rax
je     1270 <dir_scan_for_subdir_files+0x130>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbx
mov    $0x1,%eax
test   %rbx,%rbx
je     1279 <dir_scan_for_subdir_files+0x139>
lea    0x20(%rsp),%r12
lea    0x120(%rsp),%r14
mov    %r13,0x10(%rsp)
jmp    11c2 <dir_scan_for_subdir_files+0x82>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1050 <pci_scan_node@plt>
mov    %rbp,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1274 <dir_scan_for_subdir_files+0x134>
mov    (%rbx),%r8
mov    (%r8),%al
cmp    $0x2e,%al
je     11ae <dir_scan_for_subdir_files+0x6e>
cmp    $0x64,%al
je     11ae <dir_scan_for_subdir_files+0x6e>
mov    %r12,%rdi
mov    $0x100,%esi
lea    0xe21(%rip),%rdx
mov    0x18(%rsp),%rcx
call   1040 <snprintf@plt>
mov    (%rbx),%r15
cmpl   $0x0,0xc(%rsp)
jne    11a0 <dir_scan_for_subdir_files+0x60>
mov    %r12,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1266 <dir_scan_for_subdir_files+0x126>
mov    %rax,%r13
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     1266 <dir_scan_for_subdir_files+0x126>
mov    %rax,%rbx
jmp    1230 <dir_scan_for_subdir_files+0xf0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1266 <dir_scan_for_subdir_files+0x126>
mov    (%rbx),%r8
movzbl (%r8),%eax
cmp    $0x2e,%al
je     1220 <dir_scan_for_subdir_files+0xe0>
cmp    $0x64,%al
je     1220 <dir_scan_for_subdir_files+0xe0>
mov    %r14,%rdi
mov    $0x100,%esi
lea    0xdb2(%rip),%rdx
mov    %r12,%rcx
call   1040 <snprintf@plt>
mov    (%rbx),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <pci_scan_node@plt>
jmp    1220 <dir_scan_for_subdir_files+0xe0>
mov    0x10(%rsp),%r13
jmp    11ae <dir_scan_for_subdir_files+0x6e>
xor    %eax,%eax
jmp    1279 <dir_scan_for_subdir_files+0x139>
mov    $0x1,%eax
add    $0x228,%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"%s/%s\00"
define i32 @dir_scan_for_subdir_files(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca %struct.dirent*
%12 = alloca [256 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32* null, i32** %10
store %struct.dirent* null, %struct.dirent** %11
%13 = load i8*, i8** %6
%14 = call i32* @opendir(i8* %13)
store i32* %14, i32** %10
%15 = load i32*, i32** %10
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 0, i32* %5
br label %70
18: ; preds = %4
%19 = load i32*, i32** %10
%20 = call %struct.dirent* @readdir(i32* %19)
store %struct.dirent* %20, %struct.dirent** %11
br label %21
21: ; preds = %66, %18
%22 = load %struct.dirent*, %struct.dirent** %11
%23 = icmp ne %struct.dirent* %22, null
br i1 %23, label %24, label %69
24: ; preds = %21
%25 = load %struct.dirent*, %struct.dirent** %11
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 46
br i1 %31, label %32, label %33
32: ; preds = %24
br label %66
33: ; preds = %24
%34 = load %struct.dirent*, %struct.dirent** %11
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 100
br i1 %40, label %41, label %42
41: ; preds = %33
br label %66
42: ; preds = %33
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%44 = load i8*, i8** %6
%45 = load %struct.dirent*, %struct.dirent** %11
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = call i32 @snprintf(i8* %43, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %44, i8* %47)
%49 = load i32, i32* %7
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %58
51: ; preds = %42
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%53 = load %struct.dirent*, %struct.dirent** %11
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %53, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = load i8*, i8** %9
%57 = call i32 @dir_scan_for_subdir_files(i8* %52, i32 1, i8* %55, i8* %56)
br label %65
58: ; preds = %42
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%60 = load i8*, i8** %8
%61 = load %struct.dirent*, %struct.dirent** %11
%62 = getelementptr inbounds %struct.dirent, %struct.dirent* %61, i32 0, i32 0
%63 = load i8*, i8** %62
%64 = call i32 @pci_scan_node(i8* %59, i8* %60, i8* %63)
br label %65
65: ; preds = %58, %51
br label %66
66: ; preds = %65, %41, %32
%67 = load i32*, i32** %10
%68 = call %struct.dirent* @readdir(i32* %67)
store %struct.dirent* %68, %struct.dirent** %11
br label %21
69: ; preds = %21
store i32 1, i32* %5
br label %70
70: ; preds = %69, %17
%71 = load i32, i32* %5
ret i32 %71
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"%s/%s\00"
define i32 @dir_scan_for_subdir_files(i8* %0, i32 %1, i8* %2, i8* nocapture readnone %3) {
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%8 = tail call i32* @opendir(i8* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %48, label %10
10: ; preds = %4
%11 = tail call %struct.dirent* @readdir(i32* %8)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %48, label %13
13: ; preds = %10
%14 = icmp eq i32 %1, 0
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
br label %16
16: ; preds = %13, %45
%17 = phi %struct.dirent* [ %11, %13 ], [ %46, %45 ]
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
switch i8 %20, label %21 [
i8 46, label %45
i8 100, label %45
]
21: ; preds = %16
%22 = call i32 @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %19)
%23 = load i8*, i8** %18
br i1 %14, label %24, label %43
24: ; preds = %21
%25 = call i32* @opendir(i8* %7)
%26 = icmp eq i32* %25, null
br i1 %26, label %42, label %27
27: ; preds = %24
%28 = call %struct.dirent* @readdir(i32* %25)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %42, label %30
30: ; preds = %27, %39
%31 = phi %struct.dirent* [ %40, %39 ], [ %28, %27 ]
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i64 0, i32 0
%33 = load i8*, i8** %32
%34 = load i8, i8* %33
switch i8 %34, label %35 [
i8 46, label %39
i8 100, label %39
]
35: ; preds = %30
%36 = call i32 @snprintf(i8* %15, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %33)
%37 = load i8*, i8** %32
%38 = call i32 @pci_scan_node(i8* %15, i8* %23, i8* %37)
br label %39
39: ; preds = %35, %30, %30
%40 = call %struct.dirent* @readdir(i32* %25)
%41 = icmp eq %struct.dirent* %40, null
br i1 %41, label %42, label %30
42: ; preds = %39, %27, %24
br label %45
43: ; preds = %21
%44 = call i32 @pci_scan_node(i8* %7, i8* %2, i8* %23)
br label %45
45: ; preds = %16, %16, %42, %43
%46 = call %struct.dirent* @readdir(i32* %8)
%47 = icmp eq %struct.dirent* %46, null
br i1 %47, label %48, label %16
48: ; preds = %45, %10, %4
%49 = phi i32 [ 0, %4 ], [ 1, %10 ], [ 1, %45 ]
ret i32 %49
}