#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*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ read_sysfs_file_stat(int, char *, char *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
void read_sysfs_dlist_part_stat(int curr, char *dev_name) {
  DIR *dir;
  struct dirent *drd;
  char dfile[1024], filename[1024];
  snprintf(dfile, 1024, "%s/%s", "/sys/block", dev_name);
  dfile[1024 - 1] = '\0';
  if ((dir = opendir(dfile)) == NULL)
    return;
  while ((drd = readdir(dir)) != NULL) {
    if (!strcmp(drd->d_name, ".") || !strcmp(drd->d_name, ".."))
      continue;
    snprintf(filename, 1024, "%s/%s/%s", dfile, drd->d_name, "stat");
    filename[1024 - 1] = '\0';
    read_sysfs_file_stat(curr, filename, drd->d_name, 1);
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<read_sysfs_dlist_part_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%r8
mov    $0x400,%esi
lea    0xe88(%rip),%rdx
lea    0xe70(%rip),%rcx
mov    $0x0,%al
call   1050 <snprintf@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ba <read_sysfs_dlist_part_stat+0x5a>
jmp    1272 <read_sysfs_dlist_part_stat+0x112>
jmp    11bf <read_sysfs_dlist_part_stat+0x5f>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1269 <read_sysfs_dlist_part_stat+0x109>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe28(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     120e <read_sysfs_dlist_part_stat+0xae>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe0b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1213 <read_sysfs_dlist_part_stat+0xb3>
jmp    11bf <read_sysfs_dlist_part_stat+0x5f>
lea    -0x820(%rbp),%rdi
lea    -0x420(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8
mov    $0x400,%esi
lea    0xdda(%rip),%rdx
lea    0xddc(%rip),%r9
mov    $0x0,%al
call   1050 <snprintf@plt>
movb   $0x0,-0x421(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%ecx
call   1030 <read_sysfs_file_stat@plt>
jmp    11bf <read_sysfs_dlist_part_stat+0x5f>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_sysfs_dlist_part_stat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%r8
mov    %edi,0xc(%rsp)
lea    0xe92(%rip),%rdx
lea    0xe7a(%rip),%rcx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
movb   $0x0,0x40f(%rsp)
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     126e <read_sysfs_dlist_part_stat+0x10e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1266 <read_sysfs_dlist_part_stat+0x106>
mov    %rax,%r13
lea    0xe3b(%rip),%rbp
lea    0xe33(%rip),%r15
lea    0x410(%rsp),%r12
jmp    1200 <read_sysfs_dlist_part_stat+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1080 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1266 <read_sysfs_dlist_part_stat+0x106>
mov    0x0(%r13),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11f0 <read_sysfs_dlist_part_stat+0x90>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11f0 <read_sysfs_dlist_part_stat+0x90>
mov    %r12,%rdi
mov    $0x400,%esi
lea    0xddd(%rip),%rdx
lea    0x10(%rsp),%rcx
mov    %r14,%r8
lea    0xdd7(%rip),%r9
xor    %eax,%eax
call   1050 <snprintf@plt>
movb   $0x0,0x80f(%rsp)
mov    0x0(%r13),%rdx
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    $0x1,%ecx
call   1030 <read_sysfs_file_stat@plt>
jmp    11f0 <read_sysfs_dlist_part_stat+0x90>
mov    %rbx,%rdi
call   1060 <closedir@plt>
add    $0x818,%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"
@.str.1 = [11 x i8] c"/sys/block\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [9 x i8] c"%s/%s/%s\00"
@.str.5 = [5 x i8] c"stat\00"
define void @read_sysfs_dlist_part_stat(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%10 = load i8*, i8** %4
%11 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %9, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 1023
store i8 0, i8* %12
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%14 = call i32* @opendir(i8* %13)
store i32* %14, i32** %5
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
br label %52
17: ; preds = %2
br label %18
18: ; preds = %35, %34, %17
%19 = load i32*, i32** %5
%20 = call %struct.dirent* @readdir(i32* %19)
store %struct.dirent* %20, %struct.dirent** %6
%21 = icmp ne %struct.dirent* %20, null
br i1 %21, label %22, label %49
22: ; preds = %18
%23 = load %struct.dirent*, %struct.dirent** %6
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load %struct.dirent*, %struct.dirent** %6
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %28, %22
br label %18
35: ; preds = %28
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = load %struct.dirent*, %struct.dirent** %6
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %36, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %37, i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 1023
store i8 0, i8* %42
%43 = load i32, i32* %3
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%45 = load %struct.dirent*, %struct.dirent** %6
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = call i32 @read_sysfs_file_stat(i32 %43, i8* %44, i8* %47, i32 1)
br label %18
49: ; preds = %18
%50 = load i32*, i32** %5
%51 = call i32 @closedir(i32* %50)
br label %52
52: ; preds = %49, %16
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [11 x i8] c"/sys/block\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [9 x i8] c"%s/%s/%s\00"
@.str.5 = [5 x i8] c"stat\00"
define void @read_sysfs_dlist_part_stat(i32 %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %8
%9 = call i32* @opendir(i8* %5)
%10 = icmp eq i32* %9, null
br i1 %10, label %34, label %11
11: ; preds = %2
%12 = call %struct.dirent* @readdir(i32* %9)
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %32, label %14
14: ; preds = %11
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1023
br label %16
16: ; preds = %14, %25
%17 = phi %struct.dirent* [ %12, %14 ], [ %26, %25 ]
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16, %22, %28
%26 = call %struct.dirent* @readdir(i32* %9)
%27 = icmp eq %struct.dirent* %26, null
br i1 %27, label %32, label %16
28: ; preds = %22
%29 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %5, i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i8 0, i8* %15
%30 = load i8*, i8** %18
%31 = call i32 @read_sysfs_file_stat(i32 %0, i8* %6, i8* %30, i32 1)
br label %25
32: ; preds = %25, %11
%33 = call i32 @closedir(i32* %9)
br label %34
34: ; preds = %2, %32
ret void
}