#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 {
  scalar_t__ *d_name;
};

/* Variables and functions */
scalar_t__ isalnum(char const);
int directory_filter(const struct dirent *d) {
  if (d == NULL || d->d_name[0] == 0)
    return 0;
  for (const char *p = d->d_name; *p; p++)
    if (!(isalnum(*p) || *p == '_' || *p == '-'))
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<directory_filter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1138 <directory_filter+0x28>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmpq   $0x0,(%rax)
jne    1144 <directory_filter+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11bb <directory_filter+0xab>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b4 <directory_filter+0xa4>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
jne    119e <directory_filter+0x8e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
je     119e <directory_filter+0x8e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     119e <directory_filter+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    11bb <directory_filter+0xab>
jmp    11a3 <directory_filter+0x93>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114f <directory_filter+0x3f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<directory_filter>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     115b <directory_filter+0x4b>
mov    (%rdi),%rbx
mov    (%rbx),%rax
test   %rax,%rax
je     115b <directory_filter+0x4b>
test   %al,%al
je     1156 <directory_filter+0x46>
add    $0x1,%rbx
jmp    113b <directory_filter+0x2b>
nop
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1156 <directory_filter+0x46>
movsbl %al,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
jne    1130 <directory_filter+0x20>
movzbl -0x1(%rbx),%eax
cmp    $0x5f,%al
je     1130 <directory_filter+0x20>
cmp    $0x2d,%al
je     1130 <directory_filter+0x20>
jmp    115b <directory_filter+0x4b>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i64* }
define i32 @directory_filter(%struct.dirent* %0) {
%2 = alloca i32
%3 = alloca %struct.dirent*
%4 = alloca i8*
store %struct.dirent* %0, %struct.dirent** %3
%5 = load %struct.dirent*, %struct.dirent** %3
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = load %struct.dirent*, %struct.dirent** %3
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i32 0, i32 0
%10 = load i64*, i64** %9
%11 = getelementptr inbounds i64, i64* %10, i64 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %7, %1
store i32 0, i32* %2
br label %45
15: ; preds = %7
%16 = load %struct.dirent*, %struct.dirent** %3
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 0
%18 = load i64*, i64** %17
%19 = bitcast i64* %18 to i8*
store i8* %19, i8** %4
br label %20
20: ; preds = %41, %15
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %44
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = call i64 @isalnum(i8 signext %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %40, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 95
br i1 %33, label %40, label %34
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 45
br i1 %38, label %40, label %39
39: ; preds = %34
store i32 0, i32* %2
br label %45
40: ; preds = %34, %29, %24
br label %41
41: ; preds = %40
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
br label %20
44: ; preds = %20
store i32 1, i32* %2
br label %45
45: ; preds = %44, %39, %14
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
%struct.dirent = type { i64* }
define i32 @directory_filter(%struct.dirent* %0) {
%2 = icmp eq %struct.dirent* %0, null
br i1 %2, label %24, label %3
3: ; preds = %1
%4 = getelementptr inbounds %struct.dirent, %struct.dirent* %0, i64 0, i32 0
%5 = load i64*, i64** %4
%6 = load i64, i64* %5
%7 = icmp eq i64 %6, 0
%8 = trunc i64 %6 to i8
br i1 %7, label %24, label %9
9: ; preds = %3
%10 = icmp eq i8 %8, 0
br i1 %10, label %24, label %11
11: ; preds = %9
%12 = bitcast i64* %5 to i8*
br label %13
13: ; preds = %11, %20
%14 = phi i8 [ %22, %20 ], [ %8, %11 ]
%15 = phi i8* [ %21, %20 ], [ %12, %11 ]
%16 = tail call i64 @isalnum(i8 signext %14)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i8, i8* %15
switch i8 %19, label %24 [
i8 95, label %20
i8 45, label %20
]
20: ; preds = %18, %18, %13
%21 = getelementptr inbounds i8, i8* %15, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %13
24: ; preds = %18, %20, %9, %1, %3
%25 = phi i32 [ 0, %3 ], [ 0, %1 ], [ 1, %9 ], [ 0, %18 ], [ 1, %20 ]
ret i32 %25
}