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

/* Variables and functions */
scalar_t__ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ show_key(char const *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int strlen(char *);
int show_key_list(const char *dev) {
  char dirname[128];
  DIR *procdir;
  struct dirent *entry;
  if (show_key(dev, "ff:ff:ff:ff:ff:ff", 1))
    return -1;
  snprintf(dirname, sizeof(dirname), "/proc/net/hostap/%s", dev);
  procdir = opendir(dirname);
  if (!procdir) {
    printf("Could not open directory '%s'\n", dirname);
    perror("opendir");
    return -1;
  }
  while ((entry = readdir(procdir)) != NULL) {
    if (strlen(entry->d_name) == 17 && entry->d_name[2] == ':')
      show_key(dev, entry->d_name, 0);
  }
  if (closedir(procdir))
    perror("closedir");
  return 0;
}


x86 assembly (clang, -O0):
<show_key_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe66(%rip),%rsi
mov    $0x1,%edx
call   1090 <show_key@plt>
cmp    $0x0,%eax
je     11b9 <show_key_list+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b5 <show_key_list+0x135>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x80,%esi
lea    0xe42(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x90(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    1221 <show_key_list+0xa1>
lea    -0x90(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1050 <printf@plt>
lea    0xe35(%rip),%rdi
call   10a0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b5 <show_key_list+0x135>
jmp    1226 <show_key_list+0xa6>
mov    -0x98(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
je     128c <show_key_list+0x10c>
mov    -0xa0(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x11,%eax
jne    1287 <show_key_list+0x107>
mov    -0xa0(%rbp),%rax
mov    (%rax),%rax
movsbl 0x2(%rax),%eax
cmp    $0x3a,%eax
jne    1287 <show_key_list+0x107>
mov    -0x10(%rbp),%rdi
mov    -0xa0(%rbp),%rax
mov    (%rax),%rsi
xor    %edx,%edx
call   1090 <show_key@plt>
jmp    1226 <show_key_list+0xa6>
mov    -0x98(%rbp),%rdi
call   1070 <closedir@plt>
cmp    $0x0,%rax
je     12ae <show_key_list+0x12e>
lea    0xda4(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_key_list>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rdi,%r14
lea    0xe6a(%rip),%rsi
mov    $0x1,%edx
call   1090 <show_key@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
jne    1231 <show_key_list+0xb1>
lea    0xe5e(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1240 <show_key_list+0xc0>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1222 <show_key_list+0xa2>
mov    %rax,%rbx
jmp    1200 <show_key_list+0x80>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1222 <show_key_list+0xa2>
mov    (%rbx),%rdi
call   1040 <strlen@plt>
cmp    $0x11,%eax
jne    11f0 <show_key_list+0x70>
mov    (%rbx),%rsi
cmpb   $0x3a,0x2(%rsi)
jne    11f0 <show_key_list+0x70>
mov    %r14,%rdi
xor    %edx,%edx
call   1090 <show_key@plt>
jmp    11f0 <show_key_list+0x70>
mov    %r15,%rdi
call   1070 <closedir@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    125d <show_key_list+0xdd>
mov    %ebx,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xddf(%rip),%rdi
mov    %rsp,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%ebx
lea    0xdea(%rip),%rdi
jmp    1264 <show_key_list+0xe4>
lea    0xde9(%rip),%rdi
call   10a0 <perror@plt>
jmp    1231 <show_key_list+0xb1>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [18 x i8] c"ff:ff:ff:ff:ff:ff\00"
@.str.1 = [20 x i8] c"/proc/net/hostap/%s\00"
@.str.2 = [31 x i8] c"Could not open directory '%s'\0A\00"
@.str.3 = [8 x i8] c"opendir\00"
@.str.4 = [9 x i8] c"closedir\00"
define i32 @show_key_list(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [128 x i8]
%5 = alloca i32*
%6 = alloca %struct.dirent*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @show_key(i8* %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 1)
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %56
11: ; preds = %1
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i32 @snprintf(i8* %12, i32 128, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%16 = call i32* @opendir(i8* %15)
store i32* %16, i32** %5
%17 = load i32*, i32** %5
%18 = icmp ne i32* %17, null
br i1 %18, label %23, label %19
19: ; preds = %11
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %56
23: ; preds = %11
br label %24
24: ; preds = %48, %23
%25 = load i32*, i32** %5
%26 = call %struct.dirent* @readdir(i32* %25)
store %struct.dirent* %26, %struct.dirent** %6
%27 = icmp ne %struct.dirent* %26, null
br i1 %27, label %28, label %49
28: ; preds = %24
%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 @strlen(i8* %31)
%33 = icmp eq i32 %32, 17
br i1 %33, label %34, label %48
34: ; preds = %28
%35 = load %struct.dirent*, %struct.dirent** %6
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 2
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 58
br i1 %41, label %42, label %48
42: ; preds = %34
%43 = load i8*, i8** %3
%44 = load %struct.dirent*, %struct.dirent** %6
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i32 @show_key(i8* %43, i8* %46, i32 0)
br label %48
48: ; preds = %42, %34, %28
br label %24
49: ; preds = %24
%50 = load i32*, i32** %5
%51 = call i64 @closedir(i32* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
store i32 0, i32* %2
br label %56
56: ; preds = %55, %19, %10
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [18 x i8] c"ff:ff:ff:ff:ff:ff\00"
@.str.1 = [20 x i8] c"/proc/net/hostap/%s\00"
@.str.2 = [31 x i8] c"Could not open directory '%s'\0A\00"
@.str.3 = [8 x i8] c"opendir\00"
@.str.4 = [9 x i8] c"closedir\00"
define i32 @show_key_list(i8* %0) {
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @show_key(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %38
6: ; preds = %1
%7 = call i32 @snprintf(i8* %3, i32 128, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = call i32* @opendir(i8* %3)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = call %struct.dirent* @readdir(i32* %8)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %31, label %15
13: ; preds = %6
%14 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %34
15: ; preds = %10, %28
%16 = phi %struct.dirent* [ %29, %28 ], [ %11, %10 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
%20 = icmp eq i32 %19, 17
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i8*, i8** %17
%23 = getelementptr inbounds i8, i8* %22, i64 2
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 58
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @show_key(i8* %0, i8* %22, i32 0)
br label %28
28: ; preds = %26, %21, %15
%29 = call %struct.dirent* @readdir(i32* %8)
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %31, label %15
31: ; preds = %28, %10
%32 = call i64 @closedir(i32* %8)
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %31, %13
%35 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %13 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %31 ]
%36 = phi i32 [ -1, %13 ], [ 0, %31 ]
%37 = call i32 @perror(i8* %35)
br label %38
38: ; preds = %34, %31, %1
%39 = phi i32 [ -1, %1 ], [ 0, %31 ], [ %36, %34 ]
ret i32 %39
}