#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*/ dump_interface(char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int dump_interfaces(void) {
  DIR *d;
  struct dirent *de;
  d = opendir("/sys/class/net");
  if (d == 0)
    return -1;
  while ((de = readdir(d))) {
    if (de->d_name[0] == '.')
      continue;
    dump_interface(de->d_name);
  }
  closedir(d);
  return 0;
}


x86 assembly (clang, -O0):
<dump_interfaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <dump_interfaces+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <dump_interfaces+0x84>
jmp    1174 <dump_interfaces+0x34>
mov    -0x10(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11b4 <dump_interfaces+0x74>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11a3 <dump_interfaces+0x63>
jmp    1174 <dump_interfaces+0x34>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <dump_interface@plt>
jmp    1174 <dump_interfaces+0x34>
mov    -0x10(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_interfaces>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1188 <dump_interfaces+0x48>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     117c <dump_interfaces+0x3c>
mov    (%rax),%rdi
cmpb   $0x2e,(%rdi)
je     1160 <dump_interfaces+0x20>
call   1060 <dump_interface@plt>
jmp    1160 <dump_interfaces+0x20>
mov    %rbx,%rdi
call   1040 <closedir@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [15 x i8] c"/sys/class/net\00"
define i32 @dump_interfaces() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 -1, i32* %1
br label %30
8: ; preds = %0
br label %9
9: ; preds = %22, %21, %8
%10 = load i32*, i32** %2
%11 = call %struct.dirent* @readdir(i32* %10)
store %struct.dirent* %11, %struct.dirent** %3
%12 = icmp ne %struct.dirent* %11, null
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load %struct.dirent*, %struct.dirent** %3
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 46
br i1 %20, label %21, label %22
21: ; preds = %13
br label %9
22: ; preds = %13
%23 = load %struct.dirent*, %struct.dirent** %3
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @dump_interface(i8* %25)
br label %9
27: ; preds = %9
%28 = load i32*, i32** %2
%29 = call i32 @closedir(i32* %28)
store i32 0, i32* %1
br label %30
30: ; preds = %27, %7
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [15 x i8] c"/sys/class/net\00"
define i32 @dump_interfaces() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %19, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %17, label %6
6: ; preds = %3, %14
%7 = phi %struct.dirent* [ %15, %14 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 46
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = tail call i32 @dump_interface(i8* %9)
br label %14
14: ; preds = %12, %6
%15 = tail call %struct.dirent* @readdir(i32* %1)
%16 = icmp eq %struct.dirent* %15, null
br i1 %16, label %17, label %6
17: ; preds = %14, %3
%18 = tail call i32 @closedir(i32* %1)
br label %19
19: ; preds = %0, %17
%20 = phi i32 [ 0, %17 ], [ -1, %0 ]
ret i32 %20
}