#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*/ is_hex_letter(char const);
int /*<<< orphan*/ isdigit(char const);
int is_valid_hex(const char s[], const unsigned int len) {
  unsigned int i;
  i = 0;
  while (i < len) {
    if (!isdigit(s[i]) && !is_hex_letter(s[i]))
      return 0;
    ++i;
  }
  return 1;
}


x86 assembly (clang, -O0):
<is_valid_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    118e <is_valid_hex+0x6e>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1180 <is_valid_hex+0x60>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <is_hex_letter@plt>
cmp    $0x0,%eax
jne    1180 <is_valid_hex+0x60>
movl   $0x0,-0x4(%rbp)
jmp    1195 <is_valid_hex+0x75>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1136 <is_valid_hex+0x16>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x1,%r14d
test   %esi,%esi
je     1166 <is_valid_hex+0x46>
mov    %rdi,%rbx
mov    %esi,%r15d
xor    %ebp,%ebp
jmp    1149 <is_valid_hex+0x29>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     1166 <is_valid_hex+0x46>
movsbl (%rbx,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
jne    1140 <is_valid_hex+0x20>
movsbl (%rbx,%rbp,1),%edi
call   1040 <is_hex_letter@plt>
test   %eax,%eax
jne    1140 <is_valid_hex+0x20>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_valid_hex(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %28, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %5
%10 = icmp ult i32 %8, %9
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i32, i32* %6
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = call i32 @isdigit(i8 signext %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = load i32, i32* %6
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @is_hex_letter(i8 signext %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %19
store i32 0, i32* %3
br label %32
28: ; preds = %19, %11
%29 = load i32, i32* %6
%30 = add i32 %29, 1
store i32 %30, i32* %6
br label %7
31: ; preds = %7
store i32 1, i32* %3
br label %32
32: ; preds = %31, %27
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @is_valid_hex(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %16
%7 = phi i64 [ 0, %4 ], [ %17, %16 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = tail call i32 @isdigit(i8 signext %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i8, i8* %8
%14 = tail call i32 @is_hex_letter(i8 signext %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12, %6
%17 = add nuw nsw i64 %7, 1
%18 = icmp eq i64 %17, %5
br i1 %18, label %19, label %6
19: ; preds = %12, %16, %2
%20 = phi i32 [ 1, %2 ], [ 1, %16 ], [ 0, %12 ]
ret i32 %20
}