#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") ||
         check_postfix(ent->d_name, "_input"))) {
      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    1258 <dump_channels+0xf8>
jmp    119c <dump_channels+0x3c>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1223 <dump_channels+0xc3>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <check_prefix@plt>
cmp    $0x0,%rax
je     121e <dump_channels+0xbe>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe25(%rip),%rsi
call   1070 <check_postfix@plt>
cmp    $0x0,%rax
jne    120b <dump_channels+0xab>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe0d(%rip),%rsi
call   1070 <check_postfix@plt>
cmp    $0x0,%rax
je     121e <dump_channels+0xbe>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
jmp    119c <dump_channels+0x3c>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
cmp    $0xffffffff,%eax
jne    1248 <dump_channels+0xe8>
xor    %eax,%eax
mov    0x2da2(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x24(%rbp)
jmp    1252 <dump_channels+0xf2>
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
jmp    1252 <dump_channels+0xf2>
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   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   1030 <opendir@plt>
test   %rax,%rax
je     1220 <dump_channels+0xc0>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1201 <dump_channels+0xa1>
mov    %rax,%rbp
lea    0xe6d(%rip),%r14
lea    0xe6a(%rip),%r15
lea    0xe68(%rip),%r12
lea    0xe68(%rip),%r13
jmp    11cc <dump_channels+0x6c>
nopw   0x0(%rax,%rax,1)
mov    0x0(%rbp),%rsi
mov    %r13,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1201 <dump_channels+0xa1>
mov    0x0(%rbp),%rdi
mov    %r14,%rsi
call   1060 <check_prefix@plt>
test   %rax,%rax
je     11bc <dump_channels+0x5c>
mov    0x0(%rbp),%rdi
mov    %r15,%rsi
call   1070 <check_postfix@plt>
test   %rax,%rax
jne    11b0 <dump_channels+0x50>
mov    0x0(%rbp),%rdi
mov    %r12,%rsi
call   1070 <check_postfix@plt>
test   %rax,%rax
jne    11b0 <dump_channels+0x50>
jmp    11bc <dump_channels+0x5c>
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    %eax,%ecx
mov    0x2dce(%rip),%rdx
xor    %eax,%eax
sub    (%rdx),%eax
xor    %edx,%edx
cmp    $0xffffffff,%ecx
cmovne %edx,%eax
jmp    122b <dump_channels+0xcb>
mov    0x2db9(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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 = [7 x i8] c"_input\00"
@.str.3 = [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 %53
13: ; preds = %1
br label %14
14: ; preds = %42, %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 %43
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 %42
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 %37, label %31
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 i64 @check_postfix(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31, %25
%38 = load %struct.dirent*, %struct.dirent** %5
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %37, %31, %19
br label %14
43: ; preds = %14
%44 = load i32*, i32** %4
%45 = call i32 @closedir(i32* %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* @errno
%49 = sub nsw i32 0, %48
br label %51
50: ; preds = %43
br label %51
51: ; preds = %50, %47
%52 = phi i32 [ %49, %47 ], [ 0, %50 ]
store i32 %52, i32* %2
br label %53
53: ; preds = %51, %10
%54 = load i32, i32* %2
ret i32 %54
}

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 = [7 x i8] c"_input\00"
@.str.3 = [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 %30, label %10
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
br label %36
10: ; preds = %4, %27
%11 = phi %struct.dirent* [ %28, %27 ], [ %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 %27, 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 %20, label %24
20: ; preds = %16
%21 = load i8*, i8** %12
%22 = tail call i64 @check_postfix(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %20, %16
%25 = load i8*, i8** %12
%26 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24, %20, %10
%28 = tail call %struct.dirent* @readdir(i32* %2)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %30, label %10
30: ; preds = %27, %4
%31 = tail call i32 @closedir(i32* %2)
%32 = icmp eq i32 %31, -1
%33 = load i32, i32* @errno
%34 = sub nsw i32 0, %33
%35 = select i1 %32, i32 %34, i32 0
br label %36
36: ; preds = %30, %7
%37 = phi i32 [ %35, %30 ], [ %9, %7 ]
ret i32 %37
}