#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*/ EINVAL;
int /*<<< orphan*/ errno;
int check_segment_sanity(const char *text, size_t len) {
  for (unsigned int i = 0; i < len; i++) {
    if (text[i] >= '0' && text[i] <= '9')
      continue;
    if ((text[i] | 0x20) >= 'a' && (text[i] | 0x20) <= 'f')
      continue;
    errno = EINVAL;
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_segment_sanity>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    11ac <check_segment_sanity+0xac>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jl     114d <check_segment_sanity+0x4d>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
jg     114d <check_segment_sanity+0x4d>
jmp    119e <check_segment_sanity+0x9e>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
or     $0x20,%eax
cmp    $0x61,%eax
jl     1180 <check_segment_sanity+0x80>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
or     $0x20,%eax
cmp    $0x66,%eax
jg     1180 <check_segment_sanity+0x80>
jmp    119e <check_segment_sanity+0x9e>
mov    0x2e51(%rip),%rax
mov    (%rax),%ecx
mov    0x2e50(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <check_segment_sanity+0xb3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1113 <check_segment_sanity+0x13>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_segment_sanity>:
test   %rsi,%rsi
je     1149 <check_segment_sanity+0x49>
mov    $0x1,%eax
xor    %ecx,%ecx
jmp    111a <check_segment_sanity+0x1a>
xchg   %ax,%ax
mov    %eax,%ecx
add    $0x1,%eax
cmp    %rsi,%rcx
jae    1149 <check_segment_sanity+0x49>
movzbl (%rdi,%rcx,1),%ecx
lea    -0x30(%rcx),%edx
cmp    $0xa,%dl
jb     1110 <check_segment_sanity+0x10>
or     $0x20,%cl
add    $0x9f,%cl
cmp    $0x6,%cl
jb     1110 <check_segment_sanity+0x10>
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
mov    0x2e9f(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
define i32 @check_segment_sanity(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %21, label %4
4: ; preds = %2, %17
%5 = phi i64 [ %19, %17 ], [ 0, %2 ]
%6 = phi i32 [ %18, %17 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %5
%8 = load i8, i8* %7
%9 = add i8 %8, -48
%10 = icmp ult i8 %9, 10
br i1 %10, label %17, label %11
11: ; preds = %4
%12 = or i8 %8, 32
%13 = add i8 %12, -97
%14 = icmp ult i8 %13, 6
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = load i32, i32* @EINVAL
store i32 %16, i32* @errno
br label %21
17: ; preds = %11, %4
%18 = add i32 %6, 1
%19 = zext i32 %18 to i64
%20 = icmp ult i64 %19, %1
br i1 %20, label %4, label %21
21: ; preds = %17, %2, %15
%22 = phi i32 [ -1, %15 ], [ 0, %2 ], [ 0, %17 ]
ret i32 %22
}