#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 */
typedef int /*<<< orphan*/ regex_t;

/* Variables and functions */
int REG_NOMATCH;
int regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
            int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
char filter_invalid_characters(char input_char) {
  regex_t regex;
  int reti;
  char input_chars[10];
  input_chars[0] = input_char;
  input_chars[1] = '\0';
  reti = regcomp(&regex, "^[[:alnum:]_.]", 0);
  reti = regexec(&regex, input_chars, 0, NULL, 0);
  if (!reti) {
    return input_char;
  } else if (reti == REG_NOMATCH) {
    return '\0';
  }
  return '\0';
  regfree(&regex);
}


x86 assembly (clang, -O0):
<filter_invalid_characters>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
mov    -0x2(%rbp),%al
mov    %al,-0x16(%rbp)
movb   $0x0,-0x15(%rbp)
lea    -0x8(%rbp),%rdi
lea    0xebd(%rip),%rsi
xor    %edx,%edx
call   1030 <regcomp@plt>
mov    %eax,-0xc(%rbp)
lea    -0x16(%rbp),%rsi
lea    -0x8(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1040 <regexec@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    117c <filter_invalid_characters+0x5c>
mov    -0x2(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11a0 <filter_invalid_characters+0x80>
mov    -0xc(%rbp),%eax
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%eax
jne    1197 <filter_invalid_characters+0x77>
movb   $0x0,-0x1(%rbp)
jmp    11a0 <filter_invalid_characters+0x80>
jmp    119c <filter_invalid_characters+0x7c>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_invalid_characters>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    %bpl,0x2(%rsp)
movb   $0x0,0x3(%rsp)
lea    0xec5(%rip),%rsi
lea    0xc(%rsp),%r14
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %edx,%edx
call   1030 <regcomp@plt>
lea    0x2(%rsp),%rsi
mov    %r14,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <regexec@plt>
test   %eax,%eax
cmove  %ebp,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"^[[:alnum:]_.]\00"
@REG_NOMATCH = global i32 0
define signext i8 @filter_invalid_characters(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i8]
store i8 %0, i8* %3
%7 = load i8, i8* %3
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
store i8 %7, i8* %8
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 1
store i8 0, i8* %9
%10 = call i32 @regcomp(i32* %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %10, i32* %5
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%12 = call i32 @regexec(i32* %4, i8* %11, i32 0, i32* null, i32 0)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %1
%16 = load i8, i8* %3
store i8 %16, i8* %2
br label %24
17: ; preds = %1
%18 = load i32, i32* %5
%19 = load i32, i32* @REG_NOMATCH
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
store i8 0, i8* %2
br label %24
22: ; preds = %17
br label %23
23: ; preds = %22
store i8 0, i8* %2
br label %24
24: ; preds = %23, %21, %15
%25 = load i8, i8* %2
ret i8 %25
}

LLVM IR (-O2):
@.str = [15 x i8] c"^[[:alnum:]_.]\00"
@REG_NOMATCH = global i32 0
define signext i8 @filter_invalid_characters(i8 signext %0) {
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8 %0, i8* %5
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
store i8 0, i8* %6
%7 = call i32 @regcomp(i32* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = call i32 @regexec(i32* %2, i8* %5, i32 0, i32* null, i32 0)
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i8 %0, i8 0
ret i8 %10
}