#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 PATH_MAX;
int /*<<< orphan*/ cachunk_data();
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ update_alsa_device(char *, char *);
void do_alsa_stats(void) {
  DIR *dir;
  struct dirent *dirent;
  char pathname[PATH_MAX];
  dir = opendir("/sys/class/sound/card0");
  if (!dir)
    return;
  cachunk_data();
  while ((dirent = readdir(dir))) {
    if (dirent->d_name[0] == '.')
      continue;
    sprintf(pathname, "/sys/class/sound/card0/%s", dirent->d_name);
    update_alsa_device(pathname, dirent->d_name);
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<do_alsa_stats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe65(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11bb <do_alsa_stats+0x5b>
movl   $0x1,-0x24(%rbp)
jmp    122d <do_alsa_stats+0xcd>
mov    $0x0,%al
call   1060 <cachunk_data@plt>
mov    -0x8(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     121d <do_alsa_stats+0xbd>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11f1 <do_alsa_stats+0x91>
jmp    11c2 <do_alsa_stats+0x62>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe14(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1080 <update_alsa_device@plt>
jmp    11c2 <do_alsa_stats+0x62>
mov    -0x8(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_alsa_stats>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe74(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11f8 <do_alsa_stats+0x98>
mov    %rax,%r12
xor    %eax,%eax
call   1060 <cachunk_data@plt>
mov    %r12,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     11f0 <do_alsa_stats+0x90>
mov    %rax,%rbx
lea    0xe60(%rip),%r15
jmp    11d0 <do_alsa_stats+0x70>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1050 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11f0 <do_alsa_stats+0x90>
mov    (%rbx),%rdx
cmpb   $0x2e,(%rdx)
je     11c0 <do_alsa_stats+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <sprintf@plt>
mov    (%rbx),%rsi
mov    %r14,%rdi
call   1080 <update_alsa_device@plt>
jmp    11c0 <do_alsa_stats+0x60>
mov    %r12,%rdi
call   1040 <closedir@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [23 x i8] c"/sys/class/sound/card0\00"
@.str.1 = [26 x i8] c"/sys/class/sound/card0/%s\00"
define void @do_alsa_stats() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %3
%9 = alloca i8, i64 %7
store i64 %7, i64* %4
%10 = call i32* @opendir(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %1
%11 = load i32*, i32** %1
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %0
store i32 1, i32* %5
br label %41
14: ; preds = %0
%15 = call i32 (...) @cachunk_data()
br label %16
16: ; preds = %29, %28, %14
%17 = load i32*, i32** %1
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %2
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %2
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 46
br i1 %27, label %28, label %29
28: ; preds = %20
br label %16
29: ; preds = %20
%30 = load %struct.dirent*, %struct.dirent** %2
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load %struct.dirent*, %struct.dirent** %2
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @update_alsa_device(i8* %9, i8* %36)
br label %16
38: ; preds = %16
%39 = load i32*, i32** %1
%40 = call i32 @closedir(i32* %39)
store i32 0, i32* %5
br label %41
41: ; preds = %38, %13
%42 = load i8*, i8** %3
%43 = load i32, i32* %5
switch i32 %43, label %45 [
i32 0, label %44
i32 1, label %44
]
44: ; preds = %41, %41
ret void
45: ; preds = %41
unreachable
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [23 x i8] c"/sys/class/sound/card0\00"
@.str.1 = [26 x i8] c"/sys/class/sound/card0/%s\00"
define void @do_alsa_stats() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = tail call i32* @opendir(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %25, label %6
6: ; preds = %0
%7 = tail call i32 (...) @cachunk_data()
%8 = call %struct.dirent* @readdir(i32* %4)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %23, label %10
10: ; preds = %6, %20
%11 = phi %struct.dirent* [ %21, %20 ], [ %8, %6 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 46
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%18 = load i8*, i8** %12
%19 = call i32 @update_alsa_device(i8* %3, i8* %18)
br label %20
20: ; preds = %16, %10
%21 = call %struct.dirent* @readdir(i32* %4)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %23, label %10
23: ; preds = %20, %6
%24 = call i32 @closedir(i32* %4)
br label %25
25: ; preds = %0, %23
ret void
}