#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 scalar_t__ uint8_t;
typedef scalar_t__ uint32_t;
typedef int int32_t;

/* Variables and functions */
int ReadHexUint32(char const *, int, scalar_t__ *);
int /*<<< orphan*/ assert(int);
int32_t ReadHexUint8(const char *buf, int32_t max_length, uint8_t *value) {
  assert(buf != NULL);
  assert(max_length >= 0);
  assert(value != NULL);
  if (max_length > 2) {
    max_length = 2;
  }
  uint32_t dword;
  int32_t length = ReadHexUint32(buf, max_length, &dword);
  *value = (uint8_t)dword;
  return length;
}


x86 assembly (clang, -O0):
<ReadHexUint8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x2,-0xc(%rbp)
jle    1179 <ReadHexUint8+0x59>
movl   $0x2,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ReadHexUint32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadHexUint8>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
mov    %ebp,%edi
not    %edi
shr    $0x1f,%edi
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
cmp    $0x2,%ebp
mov    $0x2,%esi
cmovl  %ebp,%esi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <ReadHexUint32@plt>
mov    0x8(%rsp),%rcx
mov    %rcx,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ReadHexUint8(i8* %0, i32 %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64* %2, i64** %6
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32, i32* %5
%14 = icmp sge i32 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i64*, i64** %6
%18 = icmp ne i64* %17, null
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %5
%22 = icmp sgt i32 %21, 2
br i1 %22, label %23, label %24
23: ; preds = %3
store i32 2, i32* %5
br label %24
24: ; preds = %23, %3
%25 = load i8*, i8** %4
%26 = load i32, i32* %5
%27 = call i32 @ReadHexUint32(i8* %25, i32 %26, i64* %7)
store i32 %27, i32* %8
%28 = load i64, i64* %7
%29 = load i64*, i64** %6
store i64 %28, i64* %29
%30 = load i32, i32* %8
ret i32 %30
}

LLVM IR (-O2):
define i32 @ReadHexUint8(i8* %0, i32 %1, i64* writeonly %2) {
%4 = alloca i64
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = xor i32 %1, -1
%9 = lshr i32 %8, 31
%10 = tail call i32 @assert(i32 %9)
%11 = icmp ne i64* %2, null
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = icmp slt i32 %1, 2
%15 = select i1 %14, i32 %1, i32 2
%16 = bitcast i64* %4 to i8*
%17 = call i32 @ReadHexUint32(i8* %0, i32 %15, i64* %4)
%18 = load i64, i64* %4
store i64 %18, i64* %2
ret i32 %17
}