#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 */
typedef int uint8_t;
typedef size_t uint16_t;

/* Variables and functions */
int /*<<< orphan*/ isxdigit(char);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, size_t);
uint16_t getfield(char *lineptr, size_t bufflen, uint8_t *buff) {
  static size_t p;
  static uint8_t idx0;
  static uint8_t idx1;
  static const uint8_t hashmap[] = {
      0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
      0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  };
  memset(buff, 0, bufflen);
  p = 0;
  while ((lineptr[p] != '*') && (lineptr[p] != 0) && (p / 2 <= bufflen)) {
    if (!isxdigit(lineptr[p + 0]))
      return 0;
    if (!isxdigit(lineptr[p + 1]))
      return 0;
    if ((lineptr[p + 1] == '*') && (lineptr[p + 1] == 0))
      return 0;
    idx0 = ((uint8_t)lineptr[p + 0] & 0x1F) ^ 0x10;
    idx1 = ((uint8_t)lineptr[p + 1] & 0x1F) ^ 0x10;
    buff[p / 2] = (uint8_t)(hashmap[idx0] << 4) | hashmap[idx1];
    p += 2;
    if ((p / 2) > 1024)
      return 0;
  }
  return p / 2;
}


x86 assembly (clang, -O0):
<getfield>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
movq   $0x0,0x2eea(%rip)
mov    -0x10(%rbp),%rax
mov    0x2edf(%rip),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x2a,%ecx
mov    %al,-0x21(%rbp)
je     119d <getfield+0x7d>
mov    -0x10(%rbp),%rax
mov    0x2ec2(%rip),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     119d <getfield+0x7d>
mov    0x2ea9(%rip),%rax
shr    $0x1,%rax
cmp    -0x18(%rbp),%rax
setbe  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ad <getfield+0x8d>
jmp    12ea <getfield+0x1ca>
mov    -0x10(%rbp),%rax
mov    0x2e80(%rip),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%eax
jne    11d7 <getfield+0xb7>
movq   $0x0,-0x8(%rbp)
jmp    12f9 <getfield+0x1d9>
mov    -0x10(%rbp),%rax
mov    0x2e56(%rip),%rcx
movsbl 0x1(%rax,%rcx,1),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%eax
jne    1202 <getfield+0xe2>
movq   $0x0,-0x8(%rbp)
jmp    12f9 <getfield+0x1d9>
mov    -0x10(%rbp),%rax
mov    0x2e2b(%rip),%rcx
movsbl 0x1(%rax,%rcx,1),%eax
cmp    $0x2a,%eax
jne    1241 <getfield+0x121>
mov    -0x10(%rbp),%rax
mov    0x2e12(%rip),%rcx
movsbl 0x1(%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1241 <getfield+0x121>
movq   $0x0,-0x8(%rbp)
jmp    12f9 <getfield+0x1d9>
mov    -0x10(%rbp),%rax
mov    0x2dec(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0x1f,%eax
xor    $0x10,%eax
mov    %eax,0x2de4(%rip)
mov    -0x10(%rbp),%rax
mov    0x2dd1(%rip),%rcx
movsbl 0x1(%rax,%rcx,1),%eax
and    $0x1f,%eax
xor    $0x10,%eax
mov    %eax,0x2dcc(%rip)
movslq 0x2dc1(%rip),%rcx
lea    0xd7a(%rip),%rax
mov    (%rax,%rcx,4),%edx
shl    $0x4,%edx
movslq 0x2db1(%rip),%rcx
lea    0xd66(%rip),%rax
or     (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
mov    0x2d90(%rip),%rcx
shr    $0x1,%rcx
mov    %edx,(%rax,%rcx,4)
mov    0x2d82(%rip),%rax
add    $0x2,%rax
mov    %rax,0x2d77(%rip)
mov    0x2d70(%rip),%rax
shr    $0x1,%rax
cmp    $0x400,%rax
jbe    12e5 <getfield+0x1c5>
movq   $0x0,-0x8(%rbp)
jmp    12f9 <getfield+0x1d9>
jmp    114e <getfield+0x2e>
mov    0x2d47(%rip),%rax
shr    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfield>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
xor    %ebx,%ebx
mov    %rdx,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <memset@plt>
movq   $0x0,0x2eec(%rip)
lea    0xead(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r12,%rbx,1),%eax
test   %al,%al
je     11f6 <getfield+0xd6>
cmp    $0x2a,%al
je     11f6 <getfield+0xd6>
mov    %rbx,%rcx
shr    %rcx
cmp    %r15,%rcx
ja     11f6 <getfield+0xd6>
movsbl %al,%edi
call   1040 <isxdigit@plt>
test   %eax,%eax
je     11f2 <getfield+0xd2>
mov    0x2ea5(%rip),%rax
movsbl 0x1(%rax,%r12,1),%edi
call   1040 <isxdigit@plt>
test   %eax,%eax
je     11f2 <getfield+0xd2>
mov    0x2e8f(%rip),%rbx
movzbl 0x1(%r12,%rbx,1),%eax
movzbl (%r12,%rbx,1),%ecx
and    $0x1f,%ecx
xor    $0x10,%rcx
and    $0x1f,%eax
xor    $0x10,%rax
mov    0x0(%r13,%rcx,4),%ecx
shl    $0x4,%ecx
or     0x0(%r13,%rax,4),%ecx
mov    %rbx,%rax
and    $0xfffffffffffffffe,%rax
mov    %ecx,(%r14,%rax,2)
add    $0x2,%rbx
mov    %rbx,0x2e53(%rip)
cmp    $0x801,%rbx
jbe    1160 <getfield+0x40>
xor    %ebx,%ebx
jmp    11f9 <getfield+0xd9>
shr    %rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@getfield.p = internal global i64 0
@getfield.idx0 = internal global i32 0
@getfield.idx1 = internal global i32 0
@getfield.hashmap = internal constant <{ [55 x i32], [9 x i32] }> <{ [55 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15], [9 x i32] zeroinitializer }>
define i64 @getfield(i8* %0, i64 %1, i32* %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%8 = load i32*, i32** %7
%9 = load i64, i64* %6
%10 = call i32 @memset(i32* %8, i32 0, i64 %9)
store i64 0, i64* @getfield.p
br label %11
11: ; preds = %104, %3
%12 = load i8*, i8** %5
%13 = load i64, i64* @getfield.p
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 42
br i1 %17, label %18, label %30
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = load i64, i64* @getfield.p
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i64, i64* @getfield.p
%27 = udiv i64 %26, 2
%28 = load i64, i64* %6
%29 = icmp ule i64 %27, %28
br label %30
30: ; preds = %25, %18, %11
%31 = phi i1 [ false, %18 ], [ false, %11 ], [ %29, %25 ]
br i1 %31, label %32, label %105
32: ; preds = %30
%33 = load i8*, i8** %5
%34 = load i64, i64* @getfield.p
%35 = add i64 %34, 0
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = call i32 @isxdigit(i8 signext %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %32
store i64 0, i64* %4
br label %108
41: ; preds = %32
%42 = load i8*, i8** %5
%43 = load i64, i64* @getfield.p
%44 = add i64 %43, 1
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @isxdigit(i8 signext %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %41
store i64 0, i64* %4
br label %108
50: ; preds = %41
%51 = load i8*, i8** %5
%52 = load i64, i64* @getfield.p
%53 = add i64 %52, 1
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 42
br i1 %57, label %58, label %67
58: ; preds = %50
%59 = load i8*, i8** %5
%60 = load i64, i64* @getfield.p
%61 = add i64 %60, 1
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %67
66: ; preds = %58
store i64 0, i64* %4
br label %108
67: ; preds = %58, %50
%68 = load i8*, i8** %5
%69 = load i64, i64* @getfield.p
%70 = add i64 %69, 0
%71 = getelementptr inbounds i8, i8* %68, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = and i32 %73, 31
%75 = xor i32 %74, 16
store i32 %75, i32* @getfield.idx0
%76 = load i8*, i8** %5
%77 = load i64, i64* @getfield.p
%78 = add i64 %77, 1
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i8, i8* %79
%81 = sext i8 %80 to i32
%82 = and i32 %81, 31
%83 = xor i32 %82, 16
store i32 %83, i32* @getfield.idx1
%84 = load i32, i32* @getfield.idx0
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [64 x i32], [64 x i32]* bitcast (<{ [55 x i32], [9 x i32] }>* @getfield.hashmap to [64 x i32]*), i64 0, i64 %85
%87 = load i32, i32* %86
%88 = shl i32 %87, 4
%89 = load i32, i32* @getfield.idx1
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [64 x i32], [64 x i32]* bitcast (<{ [55 x i32], [9 x i32] }>* @getfield.hashmap to [64 x i32]*), i64 0, i64 %90
%92 = load i32, i32* %91
%93 = or i32 %88, %92
%94 = load i32*, i32** %7
%95 = load i64, i64* @getfield.p
%96 = udiv i64 %95, 2
%97 = getelementptr inbounds i32, i32* %94, i64 %96
store i32 %93, i32* %97
%98 = load i64, i64* @getfield.p
%99 = add i64 %98, 2
store i64 %99, i64* @getfield.p
%100 = load i64, i64* @getfield.p
%101 = udiv i64 %100, 2
%102 = icmp ugt i64 %101, 1024
br i1 %102, label %103, label %104
103: ; preds = %67
store i64 0, i64* %4
br label %108
104: ; preds = %67
br label %11
105: ; preds = %30
%106 = load i64, i64* @getfield.p
%107 = udiv i64 %106, 2
store i64 %107, i64* %4
br label %108
108: ; preds = %105, %103, %66, %49, %40
%109 = load i64, i64* %4
ret i64 %109
}

LLVM IR (-O2):
@getfield.p = internal unnamed_addr global i64 0
@getfield.hashmap = internal unnamed_addr constant <{ [55 x i32], [9 x i32] }> <{ [55 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15], [9 x i32] zeroinitializer }>
define i64 @getfield(i8* nocapture %0, i64 %1, i32* %2) {
%4 = tail call i32 @memset(i32* %2, i32 0, i64 %1)
store i64 0, i64* @getfield.p
br label %5
5: ; preds = %22, %3
%6 = phi i64 [ %43, %22 ], [ 0, %3 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %9 [
i8 42, label %45
i8 0, label %45
]
9: ; preds = %5
%10 = lshr i64 %6, 1
%11 = icmp ugt i64 %10, %1
br i1 %11, label %45, label %12
12: ; preds = %9
%13 = tail call i32 @isxdigit(i8 signext %8)
%14 = icmp eq i32 %13, 0
br i1 %14, label %47, label %15
15: ; preds = %12
%16 = load i64, i64* @getfield.p
%17 = add i64 %16, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = tail call i32 @isxdigit(i8 signext %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %47, label %22
22: ; preds = %15
%23 = load i64, i64* @getfield.p
%24 = add i64 %23, 1
%25 = getelementptr inbounds i8, i8* %0, i64 %24
%26 = load i8, i8* %25
%27 = getelementptr inbounds i8, i8* %0, i64 %23
%28 = load i8, i8* %27
%29 = and i8 %28, 31
%30 = xor i8 %29, 16
%31 = and i8 %26, 31
%32 = xor i8 %31, 16
%33 = zext i8 %30 to i64
%34 = getelementptr inbounds [64 x i32], [64 x i32]* bitcast (<{ [55 x i32], [9 x i32] }>* @getfield.hashmap to [64 x i32]*), i64 0, i64 %33
%35 = load i32, i32* %34
%36 = shl i32 %35, 4
%37 = zext i8 %32 to i64
%38 = getelementptr inbounds [64 x i32], [64 x i32]* bitcast (<{ [55 x i32], [9 x i32] }>* @getfield.hashmap to [64 x i32]*), i64 0, i64 %37
%39 = load i32, i32* %38
%40 = or i32 %36, %39
%41 = lshr i64 %23, 1
%42 = getelementptr inbounds i32, i32* %2, i64 %41
store i32 %40, i32* %42
%43 = add i64 %23, 2
store i64 %43, i64* @getfield.p
%44 = icmp ugt i64 %43, 2049
br i1 %44, label %47, label %5
45: ; preds = %5, %5, %9
%46 = lshr i64 %6, 1
br label %47
47: ; preds = %22, %15, %12, %45
%48 = phi i64 [ %46, %45 ], [ 0, %12 ], [ 0, %15 ], [ 0, %22 ]
ret i64 %48
}