#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*/ isxdigit(char const);
int verify_hex(const char *buffer) {
  const char *b = buffer;
  if (b == NULL) {
    return 0;
  }
  if (*b != '0') {
    return 0;
  }
  b++;
  if (*b != 'x') {
    return 0;
  }
  b++;
  if (*b == 0) {
    return 0;
  }
  for (; *b != 0; b++) {
    if (!isxdigit(*b)) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<verify_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    113b <verify_hex+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    11fa <verify_hex+0xea>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
je     1157 <verify_hex+0x47>
movl   $0x0,-0x4(%rbp)
jmp    11fa <verify_hex+0xea>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x78,%eax
je     117f <verify_hex+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    11fa <verify_hex+0xea>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a7 <verify_hex+0x97>
movl   $0x0,-0x4(%rbp)
jmp    11fa <verify_hex+0xea>
jmp    11ac <verify_hex+0x9c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f3 <verify_hex+0xe3>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isxdigit@plt>
cmp    $0x0,%eax
jne    11dd <verify_hex+0xcd>
movl   $0x0,-0x4(%rbp)
jmp    11fa <verify_hex+0xea>
jmp    11e2 <verify_hex+0xd2>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11ac <verify_hex+0x9c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_hex>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     115c <verify_hex+0x4c>
mov    %rdi,%rbx
cmpb   $0x30,(%rdi)
jne    115c <verify_hex+0x4c>
cmpb   $0x78,0x1(%rbx)
jne    115c <verify_hex+0x4c>
mov    0x2(%rbx),%al
test   %al,%al
je     115c <verify_hex+0x4c>
add    $0x3,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <isxdigit@plt>
test   %eax,%eax
je     115c <verify_hex+0x4c>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <verify_hex+0x30>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @verify_hex(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %48
9: ; preds = %1
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 48
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 0, i32* %2
br label %48
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 120
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 0, i32* %2
br label %48
23: ; preds = %15
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %23
store i32 0, i32* %2
br label %48
31: ; preds = %23
br label %32
32: ; preds = %44, %31
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %32
%38 = load i8*, i8** %4
%39 = load i8, i8* %38
%40 = call i32 @isxdigit(i8 signext %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %43, label %42
42: ; preds = %37
store i32 0, i32* %2
br label %48
43: ; preds = %37
br label %44
44: ; preds = %43
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %4
br label %32
47: ; preds = %32
store i32 1, i32* %2
br label %48
48: ; preds = %47, %42, %30, %22, %14, %8
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
define i32 @verify_hex(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 48
br i1 %5, label %6, label %23
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 120
br i1 %9, label %10, label %23
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %10, %19
%15 = phi i8* [ %20, %19 ], [ %11, %10 ]
%16 = phi i8 [ %21, %19 ], [ %12, %10 ]
%17 = tail call i32 @isxdigit(i8 signext %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = getelementptr inbounds i8, i8* %15, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %14
23: ; preds = %14, %19, %10, %6, %3, %1
%24 = phi i32 [ 0, %1 ], [ 0, %3 ], [ 0, %6 ], [ 0, %10 ], [ 0, %14 ], [ 1, %19 ]
ret i32 %24
}