#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*/ printf(char *, char *);
float toupper(char);
int validate_hex_pattern(char *p) {
  int retval = 0;
  int i;
  for (i = 0; p[i]; i++) {
    if (toupper(p[i]) > 'F') {
      printf(" \'%s\' not a valid hex string\n", p);
      retval = -1;
      break;
    }
  }
  return retval;
}


x86 assembly (clang, -O0):
<validate_hex_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     119d <validate_hex_pattern+0x7d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
movss  0xe9b(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    118a <validate_hex_pattern+0x6a>
mov    -0x8(%rbp),%rsi
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0xc(%rbp)
jmp    119d <validate_hex_pattern+0x7d>
jmp    118f <validate_hex_pattern+0x6f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <validate_hex_pattern+0x1a>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_hex_pattern>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%al
xor    %r14d,%r14d
test   %al,%al
je     1174 <validate_hex_pattern+0x54>
mov    %rdi,%rbx
lea    0x1(%rdi),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <toupper@plt>
ucomiss 0xeb1(%rip),%xmm0
ja     115f <validate_hex_pattern+0x3f>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1140 <validate_hex_pattern+0x20>
jmp    1174 <validate_hex_pattern+0x54>
lea    0xe9e(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c" '%s' not a valid hex string\0A\00"
define i32 @validate_hex_pattern(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %24, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %5
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = call float @toupper(i8 signext %17)
%19 = fcmp ogt float %18, 7.000000e+01
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = load i8*, i8** %2
%22 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 -1, i32* %3
br label %27
23: ; preds = %12
br label %24
24: ; preds = %23
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %5
27: ; preds = %20, %5
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@.str = [30 x i8] c" '%s' not a valid hex string\0A\00"
define i32 @validate_hex_pattern(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %16, label %8
4: ; preds = %8
%5 = getelementptr inbounds i8, i8* %0, i64 %13
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %1, %4
%9 = phi i64 [ %13, %4 ], [ 0, %1 ]
%10 = phi i8 [ %6, %4 ], [ %2, %1 ]
%11 = tail call float @toupper(i8 signext %10)
%12 = fcmp ogt float %11, 7.000000e+01
%13 = add nuw i64 %9, 1
br i1 %12, label %14, label %4
14: ; preds = %8
%15 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %4, %1, %14
%17 = phi i32 [ -1, %14 ], [ 0, %1 ], [ 0, %4 ]
ret i32 %17
}