#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 */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strlen(char *);
char *x_strdup(char const *);
char *ircprot_sanitize_username(const char *str) {
  char *ret, *out, *in;
  out = in = ret = x_strdup(str);
  while (*in) {
    if ((*in >= 'A') && (*in <= 'Z')) {
      *(out++) = *in;
    } else if ((*in >= 'a') && (*in <= 'z')) {
      *(out++) = *in;
    } else if ((*in >= '0') && (*in <= '9')) {
      *(out++) = *in;
    }
    in++;
  }
  *out = 0;
  if (!strlen(ret)) {
    free(ret);
    ret = x_strdup("user");
  }
  return ret;
}


x86 assembly (clang, -O0):
<ircprot_sanitize_username>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <x_strdup@plt>
mov    %rax,-0x10(%rbp)
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1228 <ircprot_sanitize_username+0xf8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
jl     119a <ircprot_sanitize_username+0x6a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5a,%eax
jg     119a <ircprot_sanitize_username+0x6a>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1217 <ircprot_sanitize_username+0xe7>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x61,%eax
jl     11d6 <ircprot_sanitize_username+0xa6>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7a,%eax
jg     11d6 <ircprot_sanitize_username+0xa6>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1212 <ircprot_sanitize_username+0xe2>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     120d <ircprot_sanitize_username+0xdd>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     120d <ircprot_sanitize_username+0xdd>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1212 <ircprot_sanitize_username+0xe2>
jmp    1217 <ircprot_sanitize_username+0xe7>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1151 <ircprot_sanitize_username+0x21>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jne    125a <ircprot_sanitize_username+0x12a>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xdaf(%rip),%rdi
call   1050 <x_strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ircprot_sanitize_username>:
push   %r14
push   %rbx
push   %rax
call   1050 <x_strdup@plt>
mov    %rax,%r14
mov    (%rax),%dl
test   %dl,%dl
je     1179 <ircprot_sanitize_username+0x49>
mov    %r14,%rcx
add    $0x1,%rcx
mov    %r14,%rax
jmp    1161 <ircprot_sanitize_username+0x31>
xchg   %ax,%ax
mov    %dl,(%rax)
add    $0x1,%rax
movzbl (%rcx),%edx
add    $0x1,%rcx
test   %dl,%dl
je     1179 <ircprot_sanitize_username+0x49>
mov    %edx,%ebx
and    $0xdf,%bl
add    $0xbf,%bl
cmp    $0x1a,%bl
jb     1150 <ircprot_sanitize_username+0x20>
lea    -0x30(%rdx),%esi
cmp    $0x9,%sil
ja     1156 <ircprot_sanitize_username+0x26>
jmp    1150 <ircprot_sanitize_username+0x20>
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     1193 <ircprot_sanitize_username+0x63>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xe5e(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <x_strdup@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"user\00"
define i8* @ircprot_sanitize_username(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i8* @x_strdup(i8* %6)
store i8* %7, i8** %3
store i8* %7, i8** %5
store i8* %7, i8** %4
br label %8
8: ; preds = %59, %1
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %62
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp sge i32 %15, 65
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp sle i32 %20, 90
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
store i8 %24, i8* %25
br label %59
27: ; preds = %17, %12
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp sge i32 %30, 97
br i1 %31, label %32, label %42
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp sle i32 %35, 122
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i8*, i8** %5
%39 = load i8, i8* %38
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %4
store i8 %39, i8* %40
br label %58
42: ; preds = %32, %27
%43 = load i8*, i8** %5
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp sge i32 %45, 48
br i1 %46, label %47, label %57
47: ; preds = %42
%48 = load i8*, i8** %5
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp sle i32 %50, 57
br i1 %51, label %52, label %57
52: ; preds = %47
%53 = load i8*, i8** %5
%54 = load i8, i8* %53
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %4
store i8 %54, i8* %55
br label %57
57: ; preds = %52, %47, %42
br label %58
58: ; preds = %57, %37
br label %59
59: ; preds = %58, %22
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %5
br label %8
62: ; preds = %8
%63 = load i8*, i8** %4
store i8 0, i8* %63
%64 = load i8*, i8** %3
%65 = call i32 @strlen(i8* %64)
%66 = icmp ne i32 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %62
%68 = load i8*, i8** %3
%69 = call i32 @free(i8* %68)
%70 = call i8* @x_strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %70, i8** %3
br label %71
71: ; preds = %67, %62
%72 = load i8*, i8** %3
ret i8* %72
}

LLVM IR (-O2):
@.str = [5 x i8] c"user\00"
define i8* @ircprot_sanitize_username(i8* %0) {
%2 = tail call i8* @x_strdup(i8* %0)
%3 = load i8, i8* %2
%4 = icmp eq i8 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %1, %17
%6 = phi i8 [ %20, %17 ], [ %3, %1 ]
%7 = phi i8* [ %19, %17 ], [ %2, %1 ]
%8 = phi i8* [ %18, %17 ], [ %2, %1 ]
%9 = and i8 %6, -33
%10 = add i8 %9, -65
%11 = icmp ult i8 %10, 26
%12 = add i8 %6, -48
%13 = icmp ult i8 %12, 10
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %15, label %17
15: ; preds = %5
%16 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %6, i8* %8
br label %17
17: ; preds = %5, %15
%18 = phi i8* [ %16, %15 ], [ %8, %5 ]
%19 = getelementptr inbounds i8, i8* %7, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %5
22: ; preds = %17, %1
%23 = phi i8* [ %2, %1 ], [ %18, %17 ]
store i8 0, i8* %23
%24 = tail call i32 @strlen(i8* %2)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = tail call i32 @free(i8* %2)
%28 = tail call i8* @x_strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %26, %22
%30 = phi i8* [ %2, %22 ], [ %28, %26 ]
ret i8* %30
}