#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*/ LOG_ERR;
unsigned char hex2byte(char const *);
int /*<<< orphan*/ isxdigit(char const);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int read_hexstr(unsigned char barray[], int blen, const char *hexstr) {
  int i;
  while ((i < blen) && *hexstr && *(hexstr + 1)) {
    if (!isxdigit(*hexstr) || !isxdigit(*(hexstr + 1))) {
      syslog(LOG_ERR, "Invalid character.");
      return -1;
    }
    barray[i] = hex2byte(hexstr);
    i++;
    hexstr += 2;
  }
  if (i != blen) {
    syslog(LOG_ERR, "Invalid file hash.");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_hexstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x24(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x25(%rbp)
jge    117a <read_hexstr+0x4a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
je     117a <read_hexstr+0x4a>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    118a <read_hexstr+0x5a>
jmp    1206 <read_hexstr+0xd6>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%eax
je     11b5 <read_hexstr+0x85>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%eax
jne    11d6 <read_hexstr+0xa6>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1040 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123a <read_hexstr+0x10a>
mov    -0x20(%rbp),%rdi
call   1030 <hex2byte@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
jmp    1143 <read_hexstr+0x13>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     1233 <read_hexstr+0x103>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
call   1040 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123a <read_hexstr+0x10a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hexstr>:
push   %rax
mov    0x2ec0(%rip),%rax
mov    (%rax),%edi
lea    0xedf(%rip),%rsi
call   1030 <syslog@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [19 x i8] c"Invalid character.\00"
@.str.1 = [19 x i8] c"Invalid file hash.\00"
define i32 @read_hexstr(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
br label %9
9: ; preds = %40, %3
%10 = load i32, i32* %8
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %24
13: ; preds = %9
%14 = load i8*, i8** %7
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br label %24
24: ; preds = %18, %13, %9
%25 = phi i1 [ false, %13 ], [ false, %9 ], [ %23, %18 ]
br i1 %25, label %26, label %51
26: ; preds = %24
%27 = load i8*, i8** %7
%28 = load i8, i8* %27
%29 = call i32 @isxdigit(i8 signext %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = load i8*, i8** %7
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = call i32 @isxdigit(i8 signext %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %31, %26
%38 = load i32, i32* @LOG_ERR
%39 = call i32 @syslog(i32 %38, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %59
40: ; preds = %31
%41 = load i8*, i8** %7
%42 = call zeroext i8 @hex2byte(i8* %41)
%43 = load i8*, i8** %5
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
%49 = load i8*, i8** %7
%50 = getelementptr inbounds i8, i8* %49, i64 2
store i8* %50, i8** %7
br label %9
51: ; preds = %24
%52 = load i32, i32* %8
%53 = load i32, i32* %6
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load i32, i32* @LOG_ERR
%57 = call i32 @syslog(i32 %56, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %59
58: ; preds = %51
store i32 0, i32* %4
br label %59
59: ; preds = %58, %55, %37
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str.1 = [19 x i8] c"Invalid file hash.\00"
define i32 @read_hexstr(i8* nocapture writeonly %0, i32 %1, i8* %2) {
%4 = load i32, i32* @LOG_ERR
%5 = tail call i32 @syslog(i32 %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
ret i32 -1
}