#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 */
char fgetc(unsigned int);
scalar_t__ hex2nibble_(char);
int /*<<< orphan*/ isxdigit(char);
unsigned fscan_uhex(unsigned f) {
  unsigned value;
  char c;
  value = 0;
  while (1) {
    c = fgetc(f);
    if (!isxdigit(c))
      break;
    value <<= 4;
    value += hex2nibble_(c);
  }
  return value;
}


x86 assembly (clang, -O0):
<fscan_uhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <fgetc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%eax
jne    1164 <fscan_uhex+0x34>
jmp    1187 <fscan_uhex+0x57>
mov    -0x8(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x8(%rbp)
movsbl -0x9(%rbp),%edi
call   1030 <hex2nibble_@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x8(%rbp)
jmp    1142 <fscan_uhex+0x12>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fscan_uhex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
call   1040 <fgetc@plt>
mov    %eax,%r15d
movsbl %al,%edi
call   1050 <isxdigit@plt>
test   %eax,%eax
je     117c <fscan_uhex+0x4c>
xor    %ebx,%ebx
shl    $0x4,%ebx
movsbl %r15b,%edi
call   1030 <hex2nibble_@plt>
mov    %rax,%rbp
add    %ebx,%ebp
mov    %r14d,%edi
call   1040 <fgetc@plt>
mov    %eax,%r15d
movsbl %al,%edi
call   1050 <isxdigit@plt>
mov    %ebp,%ebx
test   %eax,%eax
jne    1150 <fscan_uhex+0x20>
jmp    117e <fscan_uhex+0x4e>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @fscan_uhex(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %2
store i32 0, i32* %3
br label %5
5: ; preds = %1, %12
%6 = load i32, i32* %2
%7 = call signext i8 @fgetc(i32 %6)
store i8 %7, i8* %4
%8 = load i8, i8* %4
%9 = call i32 @isxdigit(i8 signext %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %5
br label %21
12: ; preds = %5
%13 = load i32, i32* %3
%14 = shl i32 %13, 4
store i32 %14, i32* %3
%15 = load i8, i8* %4
%16 = call i64 @hex2nibble_(i8 signext %15)
%17 = load i32, i32* %3
%18 = zext i32 %17 to i64
%19 = add nsw i64 %18, %16
%20 = trunc i64 %19 to i32
store i32 %20, i32* %3
br label %5
21: ; preds = %11
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
define i32 @fscan_uhex(i32 %0) {
%2 = tail call signext i8 @fgetc(i32 %0)
%3 = tail call i32 @isxdigit(i8 signext %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1, %5
%6 = phi i8 [ %12, %5 ], [ %2, %1 ]
%7 = phi i32 [ %11, %5 ], [ 0, %1 ]
%8 = shl i32 %7, 4
%9 = tail call i64 @hex2nibble_(i8 signext %6)
%10 = trunc i64 %9 to i32
%11 = add i32 %8, %10
%12 = tail call signext i8 @fgetc(i32 %0)
%13 = tail call i32 @isxdigit(i8 signext %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %5
15: ; preds = %5, %1
%16 = phi i32 [ 0, %1 ], [ %11, %5 ]
ret i32 %16
}