#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ isalnum(char const);
int /*<<< orphan*/ stderr;
unsigned int strlen(char const *);
int is_valid_username(const char *username) {
  if (64 < strlen(username)) {
    fprintf(stderr,
            "Bad username. It is much too long! Username follows:\n%s\n",
            username);
    return 0;
  }
  unsigned int i;
  for (i = 0; i < strlen(username); ++i) {
    if (!isalnum(username[i])) {
      fprintf(stderr,
              "Bad username. It is not alphanumeric. Username follows:\n%s\n",
              username);
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_valid_username>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0x40,%eax
cmp    %ecx,%eax
jae    1179 <is_valid_username+0x49>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe98(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <is_valid_username+0xc4>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jae    11ed <is_valid_username+0xbd>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    11da <is_valid_username+0xaa>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <is_valid_username+0xc4>
jmp    11df <is_valid_username+0xaf>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1180 <is_valid_username+0x50>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_username>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x40,%eax
jbe    1153 <is_valid_username+0x23>
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rsi
jmp    11a2 <is_valid_username+0x72>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x1,%r14d
test   %eax,%eax
je     11ad <is_valid_username+0x7d>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl (%rbx,%rbp,1),%edi
call   1040 <isalnum@plt>
test   %eax,%eax
je     1192 <is_valid_username+0x62>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jb     1170 <is_valid_username+0x40>
jmp    11ad <is_valid_username+0x7d>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"Bad username. It is much too long! Username follows:\0A%s\0A\00"
@.str.1 = [60 x i8] c"Bad username. It is not alphanumeric. Username follows:\0A%s\0A\00"
define i32 @is_valid_username(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
%7 = icmp ult i32 64, %6
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %3
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %10)
store i32 0, i32* %2
br label %35
12: ; preds = %1
store i32 0, i32* %4
br label %13
13: ; preds = %31, %12
%14 = load i32, i32* %4
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = icmp ult i32 %14, %16
br i1 %17, label %18, label %34
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = load i32, i32* %4
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = call i32 @isalnum(i8 signext %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %3
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 0, i32* %2
br label %35
30: ; preds = %18
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add i32 %32, 1
store i32 %33, i32* %4
br label %13
34: ; preds = %13
store i32 1, i32* %2
br label %35
35: ; preds = %34, %26, %8
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"Bad username. It is much too long! Username follows:\0A%s\0A\00"
@.str.1 = [60 x i8] c"Bad username. It is not alphanumeric. Username follows:\0A%s\0A\00"
define i32 @is_valid_username(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp ugt i32 %2, 64
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %24, label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %24
10: ; preds = %14
%11 = tail call i32 @strlen(i8* %0)
%12 = zext i32 %11 to i64
%13 = icmp ult i64 %20, %12
br i1 %13, label %14, label %24
14: ; preds = %4, %10
%15 = phi i64 [ %20, %10 ], [ 0, %4 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @isalnum(i8 signext %17)
%19 = icmp eq i32 %18, 0
%20 = add nuw nsw i64 %15, 1
br i1 %19, label %21, label %10
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %10, %4, %21, %7
%25 = phi i32 [ 0, %7 ], [ 0, %21 ], [ 1, %4 ], [ 1, %10 ]
ret i32 %25
}