#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 hex2int(char);
int /*<<< orphan*/ ishexdigit(char);
int strlen(char *);
int high_bit_order(char *allowed) {
  int order = -1;
  int i = 0;
  int k = strlen(allowed) - 1;
  for (; k >= 0; --k) {
    char ch = allowed[k];
    if (!ishexdigit(ch))
      continue;
    int mask = hex2int(ch);
    if (mask) {
      int neworder;
      if (mask & 8)
        neworder = 4 + i;
      else if (mask & 4)
        neworder = 3 + i;
      else if (mask & 2)
        neworder = 2 + i;
      else
        neworder = 1 + i;
      if (neworder > order)
        order = neworder;
    }
    i += 4;
  }
  return order;
}


x86 assembly (clang, -O0):
<high_bit_order>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1236 <high_bit_order+0x106>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1050 <ishexdigit@plt>
cmp    $0x0,%eax
jne    1188 <high_bit_order+0x58>
jmp    1228 <high_bit_order+0xf8>
movsbl -0x15(%rbp),%edi
call   1040 <hex2int@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     121f <high_bit_order+0xef>
mov    -0x1c(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11bb <high_bit_order+0x8b>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
jmp    1208 <high_bit_order+0xd8>
mov    -0x1c(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11d8 <high_bit_order+0xa8>
mov    -0x10(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x20(%rbp)
jmp    1203 <high_bit_order+0xd3>
mov    -0x1c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11f5 <high_bit_order+0xc5>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    11fe <high_bit_order+0xce>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1203 <high_bit_order+0xd3>
jmp    1208 <high_bit_order+0xd8>
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    121a <high_bit_order+0xea>
mov    -0x20(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    121f <high_bit_order+0xef>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <high_bit_order+0x29>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<high_bit_order>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    11b8 <high_bit_order+0x88>
mov    %eax,%ebp
add    $0x1,%rbp
xor    %r12d,%r12d
mov    $0xffffffff,%r15d
jmp    1178 <high_bit_order+0x48>
cs nopw 0x0(%rax,%rax,1)
nop
add    %r12d,%ecx
cmp    %r15d,%ecx
cmovg  %ecx,%r15d
add    $0x4,%r12d
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
jbe    11be <high_bit_order+0x8e>
lea    -0x2(%rbp),%eax
movsbl (%r14,%rax,1),%ebx
mov    %ebx,%edi
call   1050 <ishexdigit@plt>
test   %eax,%eax
je     116e <high_bit_order+0x3e>
mov    %ebx,%edi
call   1040 <hex2int@plt>
test   %eax,%eax
je     116a <high_bit_order+0x3a>
mov    $0x4,%ecx
test   $0x8,%al
jne    1160 <high_bit_order+0x30>
mov    $0x3,%ecx
test   $0x4,%al
jne    1160 <high_bit_order+0x30>
and    $0x2,%eax
cmp    $0x1,%eax
mov    $0x2,%ecx
sbb    $0x0,%ecx
jmp    1160 <high_bit_order+0x30>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @high_bit_order(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
store i32 0, i32* %4
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %5
br label %12
12: ; preds = %66, %1
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %69
15: ; preds = %12
%16 = load i8*, i8** %2
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %6
%21 = load i8, i8* %6
%22 = call i32 @ishexdigit(i8 signext %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %15
br label %66
25: ; preds = %15
%26 = load i8, i8* %6
%27 = call i32 @hex2int(i8 signext %26)
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %63
30: ; preds = %25
%31 = load i32, i32* %7
%32 = and i32 %31, 8
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i32, i32* %4
%36 = add nsw i32 4, %35
store i32 %36, i32* %8
br label %56
37: ; preds = %30
%38 = load i32, i32* %7
%39 = and i32 %38, 4
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %4
%43 = add nsw i32 3, %42
store i32 %43, i32* %8
br label %55
44: ; preds = %37
%45 = load i32, i32* %7
%46 = and i32 %45, 2
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44
%49 = load i32, i32* %4
%50 = add nsw i32 2, %49
store i32 %50, i32* %8
br label %54
51: ; preds = %44
%52 = load i32, i32* %4
%53 = add nsw i32 1, %52
store i32 %53, i32* %8
br label %54
54: ; preds = %51, %48
br label %55
55: ; preds = %54, %41
br label %56
56: ; preds = %55, %34
%57 = load i32, i32* %8
%58 = load i32, i32* %3
%59 = icmp sgt i32 %57, %58
br i1 %59, label %60, label %62
60: ; preds = %56
%61 = load i32, i32* %8
store i32 %61, i32* %3
br label %62
62: ; preds = %60, %56
br label %63
63: ; preds = %62, %25
%64 = load i32, i32* %4
%65 = add nsw i32 %64, 4
store i32 %65, i32* %4
br label %66
66: ; preds = %63, %24
%67 = load i32, i32* %5
%68 = add nsw i32 %67, -1
store i32 %68, i32* %5
br label %12
69: ; preds = %12
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
define i32 @high_bit_order(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %41
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %37
%7 = phi i64 [ %5, %4 ], [ %10, %37 ]
%8 = phi i32 [ -1, %4 ], [ %39, %37 ]
%9 = phi i32 [ 0, %4 ], [ %38, %37 ]
%10 = add nsw i64 %7, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @ishexdigit(i8 signext %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %37, label %16
16: ; preds = %6
%17 = tail call i32 @hex2int(i8 signext %13)
%18 = icmp eq i32 %17, 0
br i1 %18, label %34, label %19
19: ; preds = %16
%20 = and i32 %17, 8
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = and i32 %17, 4
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = and i32 %17, 2
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i32 1, i32 2
br label %29
29: ; preds = %25, %22, %19
%30 = phi i32 [ 4, %19 ], [ 3, %22 ], [ %28, %25 ]
%31 = add nsw i32 %9, %30
%32 = icmp sgt i32 %31, %8
%33 = select i1 %32, i32 %31, i32 %8
br label %34
34: ; preds = %29, %16
%35 = phi i32 [ %33, %29 ], [ %8, %16 ]
%36 = add nsw i32 %9, 4
br label %37
37: ; preds = %6, %34
%38 = phi i32 [ %36, %34 ], [ %9, %6 ]
%39 = phi i32 [ %35, %34 ], [ %8, %6 ]
%40 = icmp ugt i64 %7, 1
br i1 %40, label %6, label %41
41: ; preds = %37, %1
%42 = phi i32 [ -1, %1 ], [ %39, %37 ]
ret i32 %42
}