unsigned char GB_HZZF_len(unsigned char *hzStr) {
  unsigned char c1, c2;
  c1 = *hzStr++;
  if (c1 < 0x20)
    return (0);
  if (c1 < 0x80)
    return (1);
  c2 = *hzStr++;
  if ((c1 == 0x81 && c2 >= 0x39) || (c1 == 0x82))
    return (4);
  return (2);
}


x86 assembly (clang, -O0):
<GB_HZZF_len>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x20,%eax
jge    1132 <GB_HZZF_len+0x32>
movb   $0x0,-0x1(%rbp)
jmp    1196 <GB_HZZF_len+0x96>
movzbl -0x11(%rbp),%eax
cmp    $0x80,%eax
jge    114a <GB_HZZF_len+0x4a>
movb   $0x1,-0x1(%rbp)
jmp    1196 <GB_HZZF_len+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x12(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x81,%eax
jne    117a <GB_HZZF_len+0x7a>
movzbl -0x12(%rbp),%eax
cmp    $0x39,%eax
jge    1189 <GB_HZZF_len+0x89>
movzbl -0x11(%rbp),%eax
cmp    $0x82,%eax
jne    1192 <GB_HZZF_len+0x92>
movb   $0x4,-0x1(%rbp)
jmp    1196 <GB_HZZF_len+0x96>
movb   $0x2,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<GB_HZZF_len>:
mov    (%rdi),%cl
cmp    $0x20,%cl
jae    110a <GB_HZZF_len+0xa>
xor    %eax,%eax
ret
mov    $0x1,%al
test   %cl,%cl
js     1111 <GB_HZZF_len+0x11>
ret
cmp    $0x81,%cl
sete   %al
cmpb   $0x39,0x1(%rdi)
setae  %dl
and    %al,%dl
add    %dl,%dl
add    $0x2,%dl
cmp    $0x82,%cl
movzbl %dl,%ecx
mov    $0x4,%eax
cmovne %ecx,%eax
ret

LLVM IR (-O0):
define zeroext i8 @GB_HZZF_len(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %3
%8 = load i8, i8* %6
store i8 %8, i8* %4
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = icmp slt i32 %10, 32
br i1 %11, label %12, label %13
12: ; preds = %1
store i8 0, i8* %2
br label %35
13: ; preds = %1
%14 = load i8, i8* %4
%15 = zext i8 %14 to i32
%16 = icmp slt i32 %15, 128
br i1 %16, label %17, label %18
17: ; preds = %13
store i8 1, i8* %2
br label %35
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
%21 = load i8, i8* %19
store i8 %21, i8* %5
%22 = load i8, i8* %4
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 129
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i8, i8* %5
%27 = zext i8 %26 to i32
%28 = icmp sge i32 %27, 57
br i1 %28, label %33, label %29
29: ; preds = %25, %18
%30 = load i8, i8* %4
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %31, 130
br i1 %32, label %33, label %34
33: ; preds = %29, %25
store i8 4, i8* %2
br label %35
34: ; preds = %29
store i8 2, i8* %2
br label %35
35: ; preds = %34, %33, %17, %12
%36 = load i8, i8* %2
ret i8 %36
}

LLVM IR (-O2):
define zeroext i8 @GB_HZZF_len(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %0
%4 = icmp ult i8 %3, 32
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = icmp sgt i8 %3, -1
br i1 %6, label %15, label %7
7: ; preds = %5
%8 = load i8, i8* %2
%9 = icmp eq i8 %3, -127
%10 = icmp ugt i8 %8, 56
%11 = select i1 %9, i1 %10, i1 false
%12 = icmp eq i8 %3, -126
%13 = or i1 %12, %11
%14 = select i1 %13, i8 4, i8 2
br label %15
15: ; preds = %7, %5, %1
%16 = phi i8 [ 0, %1 ], [ 1, %5 ], [ %14, %7 ]
ret i8 %16
}