#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fail(char *);
int fgetc(int /*<<< orphan*/ *);
scalar_t__ isspace(int);
int /*<<< orphan*/ isxdigit(int);
int readhex(char *seq, FILE *ifp) {
  int ch, aa, nres = 0;
  while ((ch = fgetc(ifp)) != EOF)
    if (ch == '\'')
      break;
  if (ch == EOF)
    fail("Bad sequence record in checkpoint file!");
  for (;;) {
    ch = fgetc(ifp);
    if (ch == '\'')
      break;
    if (isspace(ch))
      continue;
    if (!isxdigit(ch))
      fail("Bad sequence record in checkpoint file!");
    if (ch >= 'A')
      aa = 16 * (10 + ch - 'A');
    else
      aa = 16 * (ch - '0');
    ch = fgetc(ifp);
    if (!isxdigit(ch))
      fail("Bad sequence record in checkpoint file!");
    if (ch >= 'A')
      aa += 10 + ch - 'A';
    else
      aa += ch - '0';
    if (nres > 65536)
      break;
    seq[nres++] = aa;
  }
  return nres;
}


x86 assembly (clang, -O0):
<readhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
je     1186 <readhex+0x46>
cmpl   $0x27,-0x14(%rbp)
jne    1181 <readhex+0x41>
jmp    1186 <readhex+0x46>
jmp    1157 <readhex+0x17>
mov    -0x14(%rbp),%eax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%eax
jne    11a4 <readhex+0x64>
lea    0xe61(%rip),%rdi
call   1030 <fail@plt>
jmp    11a9 <readhex+0x69>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x27,-0x14(%rbp)
jne    11c4 <readhex+0x84>
jmp    12a6 <readhex+0x166>
mov    -0x14(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11db <readhex+0x9b>
jmp    11a9 <readhex+0x69>
mov    -0x14(%rbp),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%eax
jne    11f8 <readhex+0xb8>
lea    0xe0d(%rip),%rdi
call   1030 <fail@plt>
cmpl   $0x41,-0x14(%rbp)
jl     1216 <readhex+0xd6>
mov    -0x14(%rbp),%eax
add    $0xa,%eax
sub    $0x41,%eax
shl    $0x4,%eax
mov    %eax,-0x18(%rbp)
jmp    1222 <readhex+0xe2>
mov    -0x14(%rbp),%eax
sub    $0x30,%eax
shl    $0x4,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <isxdigit@plt>
cmp    $0x0,%eax
jne    124b <readhex+0x10b>
lea    0xdba(%rip),%rdi
call   1030 <fail@plt>
cmpl   $0x41,-0x14(%rbp)
jl     1269 <readhex+0x129>
mov    -0x14(%rbp),%eax
add    $0xa,%eax
sub    $0x41,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1275 <readhex+0x135>
mov    -0x14(%rbp),%eax
sub    $0x30,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x10000,-0x1c(%rbp)
jle    1287 <readhex+0x147>
jmp    12a6 <readhex+0x166>
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11a9 <readhex+0x69>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readhex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e90(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    0x0(%rbp),%ecx
cmp    $0x27,%eax
je     1174 <readhex+0x34>
cmp    %ecx,%eax
jne    1160 <readhex+0x20>
cmp    %ecx,%eax
jne    1184 <readhex+0x44>
lea    0xe81(%rip),%rdi
call   1030 <fail@plt>
xor    %r15d,%r15d
mov    $0x90,%r13d
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0x27,%eax
je     122e <readhex+0xee>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    1190 <readhex+0x50>
mov    %ebp,%edi
call   1060 <isxdigit@plt>
test   %eax,%eax
jne    11c6 <readhex+0x86>
lea    0xe3f(%rip),%rdi
call   1030 <fail@plt>
cmp    $0x41,%ebp
mov    $0x0,%r12d
cmovge %r13d,%r12d
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%r13d
mov    %eax,%edi
call   1060 <isxdigit@plt>
test   %eax,%eax
jne    11f5 <readhex+0xb5>
lea    0xe10(%rip),%rdi
call   1030 <fail@plt>
cmp    $0x10001,%r15
je     1228 <readhex+0xe8>
shl    $0x4,%ebp
add    %ebp,%r12d
cmp    $0x41,%r13d
lea    0xc9(%r13,%r12,1),%eax
lea    0xd0(%r13,%r12,1),%ecx
cmovge %eax,%ecx
mov    %cl,(%r14,%r15,1)
add    $0x1,%r15
jmp    1187 <readhex+0x47>
mov    $0x10001,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [40 x i8] c"Bad sequence record in checkpoint file!\00"
define i32 @readhex(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %7
br label %8
8: ; preds = %17, %2
%9 = load i32*, i32** %4
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %5
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 39
br i1 %15, label %16, label %17
16: ; preds = %13
br label %18
17: ; preds = %13
br label %8
18: ; preds = %16, %8
%19 = load i32, i32* %5
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
br label %25
25: ; preds = %80, %35, %24
%26 = load i32*, i32** %4
%27 = call i32 @fgetc(i32* %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 39
br i1 %29, label %30, label %31
30: ; preds = %25
br label %88
31: ; preds = %25
%32 = load i32, i32* %5
%33 = call i64 @isspace(i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
br label %25
36: ; preds = %31
%37 = load i32, i32* %5
%38 = call i32 @isxdigit(i32 %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %36
%41 = call i32 @fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %40, %36
%43 = load i32, i32* %5
%44 = icmp sge i32 %43, 65
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load i32, i32* %5
%47 = add nsw i32 10, %46
%48 = sub nsw i32 %47, 65
%49 = mul nsw i32 16, %48
store i32 %49, i32* %6
br label %54
50: ; preds = %42
%51 = load i32, i32* %5
%52 = sub nsw i32 %51, 48
%53 = mul nsw i32 16, %52
store i32 %53, i32* %6
br label %54
54: ; preds = %50, %45
%55 = load i32*, i32** %4
%56 = call i32 @fgetc(i32* %55)
store i32 %56, i32* %5
%57 = load i32, i32* %5
%58 = call i32 @isxdigit(i32 %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %62, label %60
60: ; preds = %54
%61 = call i32 @fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %62
62: ; preds = %60, %54
%63 = load i32, i32* %5
%64 = icmp sge i32 %63, 65
br i1 %64, label %65, label %71
65: ; preds = %62
%66 = load i32, i32* %5
%67 = add nsw i32 10, %66
%68 = sub nsw i32 %67, 65
%69 = load i32, i32* %6
%70 = add nsw i32 %69, %68
store i32 %70, i32* %6
br label %76
71: ; preds = %62
%72 = load i32, i32* %5
%73 = sub nsw i32 %72, 48
%74 = load i32, i32* %6
%75 = add nsw i32 %74, %73
store i32 %75, i32* %6
br label %76
76: ; preds = %71, %65
%77 = load i32, i32* %7
%78 = icmp sgt i32 %77, 65536
br i1 %78, label %79, label %80
79: ; preds = %76
br label %88
80: ; preds = %76
%81 = load i32, i32* %6
%82 = trunc i32 %81 to i8
%83 = load i8*, i8** %3
%84 = load i32, i32* %7
%85 = add nsw i32 %84, 1
store i32 %85, i32* %7
%86 = sext i32 %84 to i64
%87 = getelementptr inbounds i8, i8* %83, i64 %86
store i8 %82, i8* %87
br label %25
88: ; preds = %79, %30
%89 = load i32, i32* %7
ret i32 %89
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [40 x i8] c"Bad sequence record in checkpoint file!\00"
define i32 @readhex(i8* nocapture writeonly %0, i32* nocapture %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call i32 @fgetc(i32* %1)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
%7 = icmp eq i32 %4, 39
%8 = or i1 %7, %6
br i1 %8, label %9, label %3
9: ; preds = %3
br i1 %6, label %10, label %12
10: ; preds = %9
%11 = tail call i32 @fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %9
br label %13
13: ; preds = %12, %37
%14 = phi i64 [ %44, %37 ], [ 0, %12 ]
br label %15
15: ; preds = %13, %18
%16 = tail call i32 @fgetc(i32* %1)
%17 = icmp eq i32 %16, 39
br i1 %17, label %46, label %18
18: ; preds = %15
%19 = tail call i64 @isspace(i32 %16)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %18
%22 = tail call i32 @isxdigit(i32 %16)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 @fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = icmp sgt i32 %16, 64
%28 = shl i32 %16, 4
%29 = select i1 %27, i32 144, i32 0
%30 = tail call i32 @fgetc(i32* %1)
%31 = tail call i32 @isxdigit(i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = tail call i32 @fail(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %26
%36 = icmp eq i64 %14, 65537
br i1 %36, label %48, label %37
37: ; preds = %35
%38 = icmp sgt i32 %30, 64
%39 = select i1 %38, i32 201, i32 208
%40 = add i32 %29, %28
%41 = add i32 %40, %30
%42 = add i32 %41, %39
%43 = trunc i32 %42 to i8
%44 = add nuw nsw i64 %14, 1
%45 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 %43, i8* %45
br label %13
46: ; preds = %15
%47 = trunc i64 %14 to i32
br label %48
48: ; preds = %35, %46
%49 = phi i32 [ %47, %46 ], [ 65537, %35 ]
ret i32 %49
}