#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) {
  size_t i;
  for (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)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11b5 <check_segment_sanity+0xb5>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jl     1151 <check_segment_sanity+0x51>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
jg     1151 <check_segment_sanity+0x51>
jmp    11a4 <check_segment_sanity+0xa4>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
or     $0x20,%eax
cmp    $0x61,%eax
jl     1186 <check_segment_sanity+0x86>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
or     $0x20,%eax
cmp    $0x66,%eax
jg     1186 <check_segment_sanity+0x86>
jmp    11a4 <check_segment_sanity+0xa4>
mov    0x2e4b(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4a(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <check_segment_sanity+0xbc>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1114 <check_segment_sanity+0x14>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_segment_sanity>:
test   %rsi,%rsi
je     1148 <check_segment_sanity+0x48>
xor    %eax,%eax
jmp    1119 <check_segment_sanity+0x19>
nopl   0x0(%rax)
add    $0x1,%rax
cmp    %rax,%rsi
je     1148 <check_segment_sanity+0x48>
movzbl (%rdi,%rax,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    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    0x2ea0(%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 i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 0, i64* %6
br label %7
7: ; preds = %45, %2
%8 = load i64, i64* %6
%9 = load i64, i64* %5
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %48
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i64, i64* %6
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp sge i32 %16, 48
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = load i64, i64* %6
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sle i32 %23, 57
br i1 %24, label %25, label %26
25: ; preds = %18
br label %45
26: ; preds = %18, %11
%27 = load i8*, i8** %4
%28 = load i64, i64* %6
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = or i32 %31, 32
%33 = icmp sge i32 %32, 97
br i1 %33, label %34, label %43
34: ; preds = %26
%35 = load i8*, i8** %4
%36 = load i64, i64* %6
%37 = getelementptr inbounds i8, i8* %35, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = or i32 %39, 32
%41 = icmp sle i32 %40, 102
br i1 %41, label %42, label %43
42: ; preds = %34
br label %45
43: ; preds = %34, %26
%44 = load i32, i32* @EINVAL
store i32 %44, i32* @errno
store i32 -1, i32* %3
br label %49
45: ; preds = %42, %25
%46 = load i64, i64* %6
%47 = add i64 %46, 1
store i64 %47, i64* %6
br label %7
48: ; preds = %7
store i32 0, i32* %3
br label %49
49: ; preds = %48, %43
%50 = load i32, i32* %3
ret i32 %50
}

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 %19, label %4
4: ; preds = %2, %16
%5 = phi i64 [ %17, %16 ], [ 0, %2 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = add i8 %7, -48
%9 = icmp ult i8 %8, 10
br i1 %9, label %16, label %10
10: ; preds = %4
%11 = or i8 %7, 32
%12 = add i8 %11, -97
%13 = icmp ult i8 %12, 6
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = load i32, i32* @EINVAL
store i32 %15, i32* @errno
br label %19
16: ; preds = %10, %4
%17 = add nuw i64 %5, 1
%18 = icmp eq i64 %17, %1
br i1 %18, label %19, label %4
19: ; preds = %16, %2, %14
%20 = phi i32 [ -1, %14 ], [ 0, %2 ], [ 0, %16 ]
ret i32 %20
}