#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 */
scalar_t__ decode_hex_byte(char, char, unsigned char *);
int parse_uint16hex(char *ch) {
  int w = 0;
  unsigned char v;
  if (decode_hex_byte(ch[0], ch[1], &v)) {
    return 0;
  }
  w |= v;
  w <<= 8;
  if (decode_hex_byte(ch[2], ch[3], &v)) {
    return 0;
  }
  w |= v;
  return w;
}


x86 assembly (clang, -O0):
<parse_uint16hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
lea    -0x15(%rbp),%rdx
movsbl %cl,%edi
movsbl 0x1(%rax),%esi
call   1030 <decode_hex_byte@plt>
cmp    $0x0,%rax
je     1153 <parse_uint16hex+0x43>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <parse_uint16hex+0x97>
movzbl -0x15(%rbp),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%cl
mov    -0x10(%rbp),%rax
lea    -0x15(%rbp),%rdx
movsbl %cl,%edi
movsbl 0x3(%rax),%esi
call   1030 <decode_hex_byte@plt>
cmp    $0x0,%rax
je     1197 <parse_uint16hex+0x87>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <parse_uint16hex+0x97>
movzbl -0x15(%rbp),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_uint16hex>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsbl (%rdi),%edi
movsbl 0x1(%rbx),%esi
lea    0xf(%rsp),%rdx
call   1030 <decode_hex_byte@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    115c <parse_uint16hex+0x4c>
movzbl 0xf(%rsp),%r14d
movsbl 0x2(%rbx),%edi
movsbl 0x3(%rbx),%esi
lea    0xf(%rsp),%rdx
call   1030 <decode_hex_byte@plt>
test   %rax,%rax
jne    115c <parse_uint16hex+0x4c>
shl    $0x8,%r14d
movzbl 0xf(%rsp),%ebp
or     %r14d,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parse_uint16hex(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
%12 = call i64 @decode_hex_byte(i8 signext %8, i8 signext %11, i8* %5)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %1
store i32 0, i32* %2
br label %37
15: ; preds = %1
%16 = load i8, i8* %5
%17 = zext i8 %16 to i32
%18 = load i32, i32* %4
%19 = or i32 %18, %17
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = shl i32 %20, 8
store i32 %21, i32* %4
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 2
%24 = load i8, i8* %23
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 3
%27 = load i8, i8* %26
%28 = call i64 @decode_hex_byte(i8 signext %24, i8 signext %27, i8* %5)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %15
store i32 0, i32* %2
br label %37
31: ; preds = %15
%32 = load i8, i8* %5
%33 = zext i8 %32 to i32
%34 = load i32, i32* %4
%35 = or i32 %34, %33
store i32 %35, i32* %4
%36 = load i32, i32* %4
store i32 %36, i32* %2
br label %37
37: ; preds = %31, %30, %14
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @parse_uint16hex(i8* nocapture %0) {
%2 = alloca i8
%3 = load i8, i8* %0
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = call i64 @decode_hex_byte(i8 signext %3, i8 signext %5, i8* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = load i8, i8* %2
%10 = getelementptr inbounds i8, i8* %0, i64 2
%11 = load i8, i8* %10
%12 = getelementptr inbounds i8, i8* %0, i64 3
%13 = load i8, i8* %12
%14 = call i64 @decode_hex_byte(i8 signext %11, i8 signext %13, i8* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %8
%17 = zext i8 %9 to i32
%18 = shl nuw nsw i32 %17, 8
%19 = load i8, i8* %2
%20 = zext i8 %19 to i32
%21 = or i32 %18, %20
br label %22
22: ; preds = %8, %1, %16
%23 = phi i32 [ %21, %16 ], [ 0, %1 ], [ 0, %8 ]
ret i32 %23
}