#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 */

/* Variables and functions */
scalar_t__ isalnum(unsigned char);
int validate_filter_name(const char *name) {
  int i;
  for (i = 0; name[i]; i++) {
    if (isalnum((unsigned char)name[i]))
      continue;
    if (name[i] == '_' || name[i] == '-')
      continue;
    return 0;
  }
  return i != 0;
}


x86 assembly (clang, -O0):
<validate_filter_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     119e <validate_filter_name+0x8e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <isalnum@plt>
cmp    $0x0,%rax
je     1155 <validate_filter_name+0x45>
jmp    1190 <validate_filter_name+0x80>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
je     117f <validate_filter_name+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    1184 <validate_filter_name+0x74>
jmp    1190 <validate_filter_name+0x80>
movl   $0x0,-0x4(%rbp)
jmp    11ad <validate_filter_name+0x9d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <validate_filter_name+0x13>
cmpl   $0x0,-0x14(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_filter_name>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%bpl
test   %bpl,%bpl
je     1158 <validate_filter_name+0x48>
mov    %rdi,%rbx
add    $0x1,%rbx
mov    %ebp,%eax
jmp    113b <validate_filter_name+0x2b>
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1158 <validate_filter_name+0x48>
movzbl %al,%edi
call   1030 <isalnum@plt>
test   %rax,%rax
jne    1130 <validate_filter_name+0x20>
movzbl -0x1(%rbx),%eax
cmp    $0x5f,%al
je     1130 <validate_filter_name+0x20>
cmp    $0x2d,%al
je     1130 <validate_filter_name+0x20>
xor    %eax,%eax
jmp    1160 <validate_filter_name+0x50>
xor    %eax,%eax
test   %bpl,%bpl
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @validate_filter_name(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1, %12
%5 = phi i64 [ %13, %12 ], [ 0, %1 ]
%6 = phi i8 [ %15, %12 ], [ %2, %1 ]
%7 = phi i8* [ %14, %12 ], [ %0, %1 ]
%8 = tail call i64 @isalnum(i8 zeroext %6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = load i8, i8* %7
switch i8 %11, label %20 [
i8 95, label %12
i8 45, label %12
]
12: ; preds = %10, %10, %4
%13 = add nuw i64 %5, 1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %4
17: ; preds = %12, %1
%18 = xor i1 %3, true
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %10, %17
%21 = phi i32 [ %19, %17 ], [ 0, %10 ]
ret i32 %21
}