#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 LONG_MAX;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *);
int read_hex(unsigned char const **, int);
void test_read_hex(void) {
  size_t i;
  char src1[] = "32Fa84x";
  char src2[sizeof(long) * 2 + 1] = "7";
  char src3[sizeof src2] = "8";
  const unsigned char *p1 = (unsigned char *)src1;
  const unsigned char *p2 = (unsigned char *)src2;
  const unsigned char *p3 = (unsigned char *)src3;
  const unsigned char *null_ptr = NULL;
  printf("\tStart  test_read_hex\n");
  for (i = 1; i < sizeof src2 - 1; i++) {
    src2[i] = 'F';
    src3[i] = '0';
  }
  assert(read_hex(NULL, 0) == 0);
  assert(read_hex(NULL, 1) == -1);
  assert(read_hex(&null_ptr, 0) == 0);
  assert(read_hex(&null_ptr, 5) == -1);
  assert(read_hex(&p1, 4) == 0x32fa);
  assert((char)*p1 == '8');
  assert(read_hex(&p1, 1) == 8);
  assert((char)*p1 == '4');
  assert(read_hex(&p1, 0) == 0);
  assert((char)*p1 == '4');
  assert(read_hex(&p1, 2) == -1);
  assert((char)*p1 == 'x');
  assert(read_hex(&p2, sizeof src2 - 1) == LONG_MAX);
  assert((char)*p2 == '\0');
  assert(read_hex(&p3, sizeof src3 - 1) == -1);
  assert((char)*p3 == '0');
  printf("\tFinish test_read_hex\n");
}


x86 assembly (clang, -O0):
<test_read_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xef6(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xef3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xef1(%rip),%al
mov    %al,-0x20(%rbp)
mov    0xef7(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xef4(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xef2(%rip),%al
mov    %al,-0x40(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
movq   $0x0,-0x70(%rbp)
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
movq   $0x1,-0x8(%rbp)
cmpq   $0x10,-0x8(%rbp)
jae    11e3 <test_read_hex+0xb3>
mov    -0x8(%rbp),%rax
movb   $0x46,-0x30(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
movb   $0x30,-0x50(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11b5 <test_read_hex+0x85>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1030 <read_hex@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <read_hex@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
call   1030 <read_hex@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x70(%rbp),%rdi
mov    $0x5,%esi
call   1030 <read_hex@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x58(%rbp),%rdi
mov    $0x4,%esi
call   1030 <read_hex@plt>
cmp    $0x32fa,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x38,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x58(%rbp),%rdi
mov    $0x1,%esi
call   1030 <read_hex@plt>
cmp    $0x8,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x34,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
call   1030 <read_hex@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x34,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x58(%rbp),%rdi
mov    $0x2,%esi
call   1030 <read_hex@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x78,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x60(%rbp),%rdi
mov    $0x10,%esi
call   1030 <read_hex@plt>
mov    0x2ca3(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x68(%rbp),%rdi
mov    $0x10,%esi
call   1030 <read_hex@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x68(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xc80(%rip),%rdi
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_read_hex>:
push   %rbx
sub    $0x70,%rsp
movabs $0x78343861463233,%rax
mov    %rax,0x68(%rsp)
movaps 0xeb5(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movb   $0x0,0x50(%rsp)
movaps 0xec4(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movb   $0x0,0x30(%rsp)
lea    0x68(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0x40(%rsp),%rax
mov    %rax,0x18(%rsp)
lea    0x20(%rsp),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x60(%rsp)
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
movabs $0x4646464646464646,%rax
46 46 46
mov    %rax,0x41(%rsp)
mov    %rax,0x48(%rsp)
movabs $0x3030303030303030,%rax
30 30 30
mov    %rax,0x21(%rsp)
mov    %rax,0x28(%rsp)
xor    %edi,%edi
xor    %esi,%esi
call   1040 <read_hex@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <read_hex@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1050 <assert@plt>
lea    0x60(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <read_hex@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1040 <read_hex@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1050 <assert@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <read_hex@plt>
xor    %edi,%edi
cmp    $0x32fa,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rax
xor    %edi,%edi
cmpb   $0x38,(%rax)
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <read_hex@plt>
xor    %edi,%edi
cmp    $0x8,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rax
xor    %edi,%edi
cmpb   $0x34,(%rax)
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <read_hex@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rax
xor    %edi,%edi
cmpb   $0x34,(%rax)
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1040 <read_hex@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x8(%rsp),%rax
xor    %edi,%edi
cmpb   $0x78,(%rax)
sete   %dil
call   1050 <assert@plt>
lea    0x18(%rsp),%rdi
mov    $0x10,%esi
call   1040 <read_hex@plt>
mov    0x2ce7(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
sete   %dil
call   1050 <assert@plt>
mov    0x18(%rsp),%rax
xor    %edi,%edi
cmpb   $0x0,(%rax)
sete   %dil
call   1050 <assert@plt>
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   1040 <read_hex@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x10(%rsp),%rax
xor    %edi,%edi
cmpb   $0x30,(%rax)
sete   %dil
call   1050 <assert@plt>
lea    0xcf7(%rip),%rdi
call   1030 <puts@plt>
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.test_read_hex.src1 = [8 x i8] c"32Fa84x\00"
@__const.test_read_hex.src2 = [17 x i8] c"7\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.test_read_hex.src3 = [17 x i8] c"8\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [23 x i8] c"\09Start test_read_hex\0A\00"
@LONG_MAX = global i32 0
@.str.1 = [23 x i8] c"\09Finish test_read_hex\0A\00"
define void @test_read_hex() {
%1 = alloca i64
%2 = alloca [8 x i8]
%3 = alloca [17 x i8]
%4 = alloca [17 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = bitcast [8 x i8]* %2 to i8*
%10 = bitcast [17 x i8]* %3 to i8*
%11 = bitcast [17 x i8]* %4 to i8*
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
store i8* %12, i8** %5
%13 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
store i8* %13, i8** %6
%14 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
store i8* %14, i8** %7
store i8* null, i8** %8
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i64 1, i64* %1
br label %16
16: ; preds = %24, %0
%17 = load i64, i64* %1
%18 = icmp ult i64 %17, 16
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i64, i64* %1
%21 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %20
store i8 70, i8* %21
%22 = load i64, i64* %1
%23 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 %22
store i8 48, i8* %23
br label %24
24: ; preds = %19
%25 = load i64, i64* %1
%26 = add i64 %25, 1
store i64 %26, i64* %1
br label %16
27: ; preds = %16
%28 = call i32 @read_hex(i8** null, i32 0)
%29 = icmp eq i32 %28, 0
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 @read_hex(i8** null, i32 1)
%33 = icmp eq i32 %32, -1
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = call i32 @read_hex(i8** %8, i32 0)
%37 = icmp eq i32 %36, 0
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = call i32 @read_hex(i8** %8, i32 5)
%41 = icmp eq i32 %40, -1
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = call i32 @read_hex(i8** %5, i32 4)
%45 = icmp eq i32 %44, 13050
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i8*, i8** %5
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 56
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = call i32 @read_hex(i8** %5, i32 1)
%55 = icmp eq i32 %54, 8
%56 = zext i1 %55 to i32
%57 = call i32 @assert(i32 %56)
%58 = load i8*, i8** %5
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 52
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = call i32 @read_hex(i8** %5, i32 0)
%65 = icmp eq i32 %64, 0
%66 = zext i1 %65 to i32
%67 = call i32 @assert(i32 %66)
%68 = load i8*, i8** %5
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 52
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
%74 = call i32 @read_hex(i8** %5, i32 2)
%75 = icmp eq i32 %74, -1
%76 = zext i1 %75 to i32
%77 = call i32 @assert(i32 %76)
%78 = load i8*, i8** %5
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 120
%82 = zext i1 %81 to i32
%83 = call i32 @assert(i32 %82)
%84 = call i32 @read_hex(i8** %6, i32 16)
%85 = load i32, i32* @LONG_MAX
%86 = icmp eq i32 %84, %85
%87 = zext i1 %86 to i32
%88 = call i32 @assert(i32 %87)
%89 = load i8*, i8** %6
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %91, 0
%93 = zext i1 %92 to i32
%94 = call i32 @assert(i32 %93)
%95 = call i32 @read_hex(i8** %7, i32 16)
%96 = icmp eq i32 %95, -1
%97 = zext i1 %96 to i32
%98 = call i32 @assert(i32 %97)
%99 = load i8*, i8** %7
%100 = load i8, i8* %99
%101 = sext i8 %100 to i32
%102 = icmp eq i32 %101, 48
%103 = zext i1 %102 to i32
%104 = call i32 @assert(i32 %103)
%105 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.test_read_hex.src2 = [17 x i8] c"7\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.test_read_hex.src3 = [17 x i8] c"8\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@LONG_MAX = global i32 0
@str = [22 x i8] c"\09Start test_read_hex\00"
@str.2 = [22 x i8] c"\09Finish test_read_hex\00"
define void @test_read_hex() {
%1 = alloca i64
%2 = alloca [17 x i8]
%3 = alloca [17 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = bitcast i64* %1 to i8*
store i64 33834413960081971, i64* %1
%9 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%10 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%11 = bitcast i8** %4 to i8*
%12 = bitcast i8** %4 to i64**
store i64* %1, i64** %12
%13 = bitcast i8** %5 to i8*
store i8* %9, i8** %5
%14 = bitcast i8** %6 to i8*
store i8* %10, i8** %6
%15 = bitcast i8** %7 to i8*
store i8* null, i8** %7
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%17 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 1
%18 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 1
%19 = call i32 @read_hex(i8** null, i32 0)
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i32 @read_hex(i8** null, i32 1)
%24 = icmp eq i32 %23, -1
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i32 @read_hex(i8** %7, i32 0)
%28 = icmp eq i32 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = call i32 @read_hex(i8** %7, i32 5)
%32 = icmp eq i32 %31, -1
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call i32 @read_hex(i8** %4, i32 4)
%36 = icmp eq i32 %35, 13050
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 56
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = call i32 @read_hex(i8** %4, i32 1)
%45 = icmp eq i32 %44, 8
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = load i8*, i8** %4
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 52
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
%53 = call i32 @read_hex(i8** %4, i32 0)
%54 = icmp eq i32 %53, 0
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = load i8*, i8** %4
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 52
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = call i32 @read_hex(i8** %4, i32 2)
%63 = icmp eq i32 %62, -1
%64 = zext i1 %63 to i32
%65 = call i32 @assert(i32 %64)
%66 = load i8*, i8** %4
%67 = load i8, i8* %66
%68 = icmp eq i8 %67, 120
%69 = zext i1 %68 to i32
%70 = call i32 @assert(i32 %69)
%71 = call i32 @read_hex(i8** %5, i32 16)
%72 = load i32, i32* @LONG_MAX
%73 = icmp eq i32 %71, %72
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = load i8*, i8** %5
%77 = load i8, i8* %76
%78 = icmp eq i8 %77, 0
%79 = zext i1 %78 to i32
%80 = call i32 @assert(i32 %79)
%81 = call i32 @read_hex(i8** %6, i32 16)
%82 = icmp eq i32 %81, -1
%83 = zext i1 %82 to i32
%84 = call i32 @assert(i32 %83)
%85 = load i8*, i8** %6
%86 = load i8, i8* %85
%87 = icmp eq i8 %86, 48
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.2, i64 0, i64 0))
ret void
}