#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 strlen(char *);
bool username_sane(char *user) {
  if (strlen(user) > 20)
    return false;
  if (*user == '\0')
    return false;
  for (char *p = user; *p; p++) {
    if (*p >= 'a' && *p <= 'z')
      continue;
    if (*p >= 'A' && *p <= 'Z')
      continue;
    if (*p >= '0' && *p <= '9')
      continue;
    if (*p == '_')
      continue;
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<username_sane>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x14,%eax
jle    113a <username_sane+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    1213 <username_sane+0x103>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1156 <username_sane+0x46>
movl   $0x0,-0x4(%rbp)
jmp    1213 <username_sane+0x103>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     120c <username_sane+0xfc>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x61,%eax
jl     1190 <username_sane+0x80>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7a,%eax
jg     1190 <username_sane+0x80>
jmp    11fb <username_sane+0xeb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
jl     11b5 <username_sane+0xa5>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5a,%eax
jg     11b5 <username_sane+0xa5>
jmp    11fb <username_sane+0xeb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11da <username_sane+0xca>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     11da <username_sane+0xca>
jmp    11fb <username_sane+0xeb>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
jne    11ef <username_sane+0xdf>
jmp    11fb <username_sane+0xeb>
movl   $0x0,-0x4(%rbp)
jmp    1213 <username_sane+0x103>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115e <username_sane+0x4e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<username_sane>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x14,%ecx
jg     1155 <username_sane+0x45>
mov    (%rbx),%cl
test   %cl,%cl
je     1155 <username_sane+0x45>
add    $0x1,%rbx
jmp    113b <username_sane+0x2b>
xchg   %ax,%ax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     1157 <username_sane+0x47>
mov    %ecx,%edx
and    $0xdf,%dl
add    $0xbf,%dl
cmp    $0x1a,%dl
jb     1130 <username_sane+0x20>
cmp    $0x5f,%cl
je     1130 <username_sane+0x20>
add    $0xd0,%cl
cmp    $0x9,%cl
jbe    1130 <username_sane+0x20>
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @username_sane(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 20
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %22, label %7
7: ; preds = %4, %18
%8 = phi i8* [ %19, %18 ], [ %0, %4 ]
%9 = phi i8 [ %20, %18 ], [ %5, %4 ]
%10 = and i8 %9, -33
%11 = add i8 %10, -65
%12 = icmp ult i8 %11, 26
br i1 %12, label %18, label %13
13: ; preds = %7
%14 = add i8 %9, -48
%15 = icmp ult i8 %14, 10
%16 = icmp eq i8 %9, 95
%17 = or i1 %16, %15
br i1 %17, label %18, label %22
18: ; preds = %13, %7
%19 = getelementptr inbounds i8, i8* %8, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %7
22: ; preds = %13, %18, %4, %1
%23 = phi i32 [ 0, %1 ], [ 0, %4 ], [ 1, %18 ], [ 0, %13 ]
ret i32 %23
}