#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 fgetc(int /*<<< orphan*/ *);
int srec_get_hex4(FILE *fp, unsigned char *val) {
  int c;
  c = fgetc(fp);
  if ((c >= '0') && (c <= '9')) {
    *val = c - '0';
  } else if ((c >= 'A') && (c <= 'F')) {
    *val = c - 'A' + 10;
  } else if ((c >= 'a') && (c <= 'f')) {
    *val = c - 'a' + 10;
  } else {
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<srec_get_hex4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x30,-0x1c(%rbp)
jl     1153 <srec_get_hex4+0x43>
cmpl   $0x39,-0x1c(%rbp)
jg     1153 <srec_get_hex4+0x43>
mov    -0x1c(%rbp),%eax
sub    $0x30,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    11bd <srec_get_hex4+0xad>
cmpl   $0x41,-0x1c(%rbp)
jl     117d <srec_get_hex4+0x6d>
cmpl   $0x46,-0x1c(%rbp)
jg     117d <srec_get_hex4+0x6d>
mov    -0x1c(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    11b8 <srec_get_hex4+0xa8>
cmpl   $0x61,-0x1c(%rbp)
jl     11a7 <srec_get_hex4+0x97>
cmpl   $0x66,-0x1c(%rbp)
jg     11a7 <srec_get_hex4+0x97>
mov    -0x1c(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    11b3 <srec_get_hex4+0xa3>
movl   $0x1,-0x4(%rbp)
jmp    11c4 <srec_get_hex4+0xb4>
jmp    11b8 <srec_get_hex4+0xa8>
jmp    11bd <srec_get_hex4+0xad>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<srec_get_hex4>:
push   %rbx
mov    %rsi,%rbx
call   1030 <fgetc@plt>
lea    -0x30(%rax),%ecx
mov    $0xd0,%dl
cmp    $0xa,%ecx
jb     113c <srec_get_hex4+0x2c>
lea    -0x41(%rax),%ecx
mov    $0xc9,%dl
cmp    $0x6,%ecx
jb     113c <srec_get_hex4+0x2c>
lea    -0x61(%rax),%esi
mov    $0x1,%ecx
mov    $0xa9,%dl
cmp    $0x5,%esi
ja     1142 <srec_get_hex4+0x32>
add    %dl,%al
mov    %al,(%rbx)
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @srec_get_hex4(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%7 = load i32*, i32** %4
%8 = call i32 @fgetc(i32* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp sge i32 %9, 48
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = load i32, i32* %6
%13 = icmp sle i32 %12, 57
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = load i32, i32* %6
%16 = sub nsw i32 %15, 48
%17 = trunc i32 %16 to i8
%18 = load i8*, i8** %5
store i8 %17, i8* %18
br label %46
19: ; preds = %11, %2
%20 = load i32, i32* %6
%21 = icmp sge i32 %20, 65
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i32, i32* %6
%24 = icmp sle i32 %23, 70
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* %6
%27 = sub nsw i32 %26, 65
%28 = add nsw i32 %27, 10
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %5
store i8 %29, i8* %30
br label %45
31: ; preds = %22, %19
%32 = load i32, i32* %6
%33 = icmp sge i32 %32, 97
br i1 %33, label %34, label %43
34: ; preds = %31
%35 = load i32, i32* %6
%36 = icmp sle i32 %35, 102
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i32, i32* %6
%39 = sub nsw i32 %38, 97
%40 = add nsw i32 %39, 10
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %5
store i8 %41, i8* %42
br label %44
43: ; preds = %34, %31
store i32 1, i32* %3
br label %47
44: ; preds = %37
br label %45
45: ; preds = %44, %25
br label %46
46: ; preds = %45, %14
store i32 0, i32* %3
br label %47
47: ; preds = %46, %43
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
define i32 @srec_get_hex4(i32* nocapture %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @fgetc(i32* %0)
%4 = add i32 %3, -48
%5 = icmp ult i32 %4, 10
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = add i32 %3, -65
%8 = icmp ult i32 %7, 6
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = add i32 %3, -97
%11 = icmp ult i32 %10, 6
br i1 %11, label %12, label %16
12: ; preds = %9, %6, %2
%13 = phi i8 [ -48, %2 ], [ -55, %6 ], [ -87, %9 ]
%14 = trunc i32 %3 to i8
%15 = add nsw i8 %13, %14
store i8 %15, i8* %1
br label %16
16: ; preds = %12, %9
%17 = phi i32 [ 1, %9 ], [ 0, %12 ]
ret i32 %17
}