#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 */
size_t strlen(char const *);
int validate_name(const char *name) {
  size_t i;
  if (name == NULL) {
    return -1;
  }
  if (strlen(name) < 2 || strlen(name) > 50) {
    return -1;
  }
  for (i = 0; i < strlen(name); i++) {
    if ((name[i] < 'a' || name[i] > 'z') && name[i] != '-' && name[i] != '_') {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<validate_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <validate_name+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <validate_name+0xfb>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%rax
jb     1159 <validate_name+0x49>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x32,%rax
jbe    1165 <validate_name+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <validate_name+0xfb>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jae    1204 <validate_name+0xf4>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x61,%eax
jl     11b8 <validate_name+0xa8>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7a,%eax
jle    11ee <validate_name+0xde>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
je     11ee <validate_name+0xde>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
je     11ee <validate_name+0xde>
movl   $0xffffffff,-0x4(%rbp)
jmp    120b <validate_name+0xfb>
jmp    11f3 <validate_name+0xe3>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    116d <validate_name+0x5d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_name>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1164 <validate_name+0x54>
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    -0x33(%rax),%rcx
cmp    $0xffffffffffffffcf,%rcx
jb     1164 <validate_name+0x54>
xor    %ecx,%ecx
jmp    1149 <validate_name+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rcx
cmp    %rcx,%rax
je     1162 <validate_name+0x52>
movzbl (%rbx,%rcx,1),%edx
lea    -0x7b(%rdx),%esi
cmp    $0xe5,%sil
ja     1140 <validate_name+0x30>
cmp    $0x5f,%dl
je     1140 <validate_name+0x30>
cmp    $0x2d,%dl
je     1140 <validate_name+0x30>
jmp    1164 <validate_name+0x54>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @validate_name(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %17, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = add i64 %4, -51
%6 = icmp ult i64 %5, -49
br i1 %6, label %17, label %7
7: ; preds = %3, %14
%8 = phi i64 [ %15, %14 ], [ 0, %3 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = add i8 %10, -123
%12 = icmp ult i8 %11, -26
br i1 %12, label %13, label %14
13: ; preds = %7
switch i8 %10, label %17 [
i8 45, label %14
i8 95, label %14
]
14: ; preds = %13, %13, %7
%15 = add nuw i64 %8, 1
%16 = icmp eq i64 %15, %4
br i1 %16, label %17, label %7
17: ; preds = %13, %14, %3, %1
%18 = phi i32 [ -1, %1 ], [ -1, %3 ], [ -1, %13 ], [ 0, %14 ]
ret i32 %18
}