#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 */
scalar_t__ check_postfix(char *, char *);
scalar_t__ check_prefix(char *, char *);
int closedir(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int dump_channels(const char *dev_dir_name) {
  DIR *dp;
  const struct dirent *ent;
  dp = opendir(dev_dir_name);
  if (!dp)
    return -errno;
  while (ent = readdir(dp), ent)
    if (check_prefix(ent->d_name, "in_") && check_postfix(ent->d_name, "_raw"))
      printf("   %-10s\n", ent->d_name);
  return (closedir(dp) == -1) ? -errno : 0;
}


x86 assembly (clang, -O0):
<dump_channels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1197 <dump_channels+0x37>
xor    %eax,%eax
mov    0x2e53(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    123b <dump_channels+0xdb>
jmp    119c <dump_channels+0x3c>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1206 <dump_channels+0xa6>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <check_prefix@plt>
cmp    $0x0,%rax
je     1201 <dump_channels+0xa1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe25(%rip),%rsi
call   1070 <check_postfix@plt>
cmp    $0x0,%rax
je     1201 <dump_channels+0xa1>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
jmp    119c <dump_channels+0x3c>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
cmp    $0xffffffff,%eax
jne    122b <dump_channels+0xcb>
xor    %eax,%eax
mov    0x2dbf(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x24(%rbp)
jmp    1235 <dump_channels+0xd5>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    1235 <dump_channels+0xd5>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_channels>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
call   1030 <opendir@plt>
test   %rax,%rax
je     120c <dump_channels+0xac>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11ed <dump_channels+0x8d>
mov    %rax,%rbx
lea    0xe6f(%rip),%r14
lea    0xe6c(%rip),%r15
lea    0xe6a(%rip),%r12
jmp    11c0 <dump_channels+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11ed <dump_channels+0x8d>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1060 <check_prefix@plt>
test   %rax,%rax
je     11b0 <dump_channels+0x50>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1070 <check_postfix@plt>
test   %rax,%rax
je     11b0 <dump_channels+0x50>
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    11b0 <dump_channels+0x50>
mov    %r13,%rdi
call   1050 <closedir@plt>
mov    %eax,%ecx
mov    0x2de2(%rip),%rdx
xor    %eax,%eax
sub    (%rdx),%eax
xor    %edx,%edx
cmp    $0xffffffff,%ecx
cmovne %edx,%eax
jmp    1217 <dump_channels+0xb7>
mov    0x2dcd(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@errno = global i32 0
@.str = [4 x i8] c"in_\00"
@.str.1 = [5 x i8] c"_raw\00"
@.str.2 = [10 x i8] c" %-10s\0A\00"
define i32 @dump_channels(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @opendir(i8* %6)
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = sub nsw i32 0, %11
store i32 %12, i32* %2
br label %47
13: ; preds = %1
br label %14
14: ; preds = %36, %13
%15 = load i32*, i32** %4
%16 = call %struct.dirent* @readdir(i32* %15)
store %struct.dirent* %16, %struct.dirent** %5
%17 = load %struct.dirent*, %struct.dirent** %5
%18 = icmp ne %struct.dirent* %17, null
br i1 %18, label %19, label %37
19: ; preds = %14
%20 = load %struct.dirent*, %struct.dirent** %5
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call i64 @check_prefix(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %19
%26 = load %struct.dirent*, %struct.dirent** %5
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i64 @check_postfix(i8* %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = load %struct.dirent*, %struct.dirent** %5
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %31, %25, %19
br label %14
37: ; preds = %14
%38 = load i32*, i32** %4
%39 = call i32 @closedir(i32* %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* @errno
%43 = sub nsw i32 0, %42
br label %45
44: ; preds = %37
br label %45
45: ; preds = %44, %41
%46 = phi i32 [ %43, %41 ], [ 0, %44 ]
store i32 %46, i32* %2
br label %47
47: ; preds = %45, %10
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@errno = global i32 0
@.str = [4 x i8] c"in_\00"
@.str.1 = [5 x i8] c"_raw\00"
@.str.2 = [10 x i8] c" %-10s\0A\00"
define i32 @dump_channels(i8* nocapture %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call %struct.dirent* @readdir(i32* %2)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %26, label %10
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
br label %32
10: ; preds = %4, %23
%11 = phi %struct.dirent* [ %24, %23 ], [ %5, %4 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = tail call i64 @check_prefix(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %10
%17 = load i8*, i8** %12
%18 = tail call i64 @check_postfix(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i8*, i8** %12
%22 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %20, %16, %10
%24 = tail call %struct.dirent* @readdir(i32* %2)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %26, label %10
26: ; preds = %23, %4
%27 = tail call i32 @closedir(i32* %2)
%28 = icmp eq i32 %27, -1
%29 = load i32, i32* @errno
%30 = sub nsw i32 0, %29
%31 = select i1 %28, i32 %30, i32 0
br label %32
32: ; preds = %26, %7
%33 = phi i32 [ %31, %26 ], [ %9, %7 ]
ret i32 %33
}