#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*/ uint8_t;
typedef int uint16_t;

/* Variables and functions */
int UINT16_MAX;
int hex_nibble(int /*<<< orphan*/);
int /*<<< orphan*/ isxdigit(int /*<<< orphan*/);
uint16_t gdb_decode_hex(uint8_t msb, uint8_t lsb) {
  if (!isxdigit(msb) || !isxdigit(lsb))
    return UINT16_MAX;
  return 16 * hex_nibble(msb) + hex_nibble(lsb);
}


x86 assembly (clang, -O0):
<gdb_decode_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%eax
je     1150 <gdb_decode_hex+0x30>
mov    -0xc(%rbp),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%eax
jne    1161 <gdb_decode_hex+0x41>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <gdb_decode_hex+0x61>
mov    -0x8(%rbp),%edi
call   1030 <hex_nibble@plt>
shl    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <hex_nibble@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdb_decode_hex>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
call   1040 <isxdigit@plt>
test   %eax,%eax
je     1152 <gdb_decode_hex+0x32>
mov    %ebx,%edi
call   1040 <isxdigit@plt>
test   %eax,%eax
je     1152 <gdb_decode_hex+0x32>
mov    %ebp,%edi
call   1030 <hex_nibble@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
mov    %ebx,%edi
call   1030 <hex_nibble@plt>
add    %ebp,%eax
jmp    115b <gdb_decode_hex+0x3b>
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@UINT16_MAX = global i32 0
define i32 @gdb_decode_hex(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = call i32 @isxdigit(i32 %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* %5
%11 = call i32 @isxdigit(i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9, %2
%14 = load i32, i32* @UINT16_MAX
store i32 %14, i32* %3
br label %22
15: ; preds = %9
%16 = load i32, i32* %4
%17 = call i32 @hex_nibble(i32 %16)
%18 = mul nsw i32 16, %17
%19 = load i32, i32* %5
%20 = call i32 @hex_nibble(i32 %19)
%21 = add nsw i32 %18, %20
store i32 %21, i32* %3
br label %22
22: ; preds = %15, %13
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@UINT16_MAX = global i32 0
define i32 @gdb_decode_hex(i32 %0, i32 %1) {
%3 = tail call i32 @isxdigit(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @isxdigit(i32 %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5, %2
%9 = load i32, i32* @UINT16_MAX
br label %15
10: ; preds = %5
%11 = tail call i32 @hex_nibble(i32 %0)
%12 = shl nsw i32 %11, 4
%13 = tail call i32 @hex_nibble(i32 %1)
%14 = add nsw i32 %12, %13
br label %15
15: ; preds = %10, %8
%16 = phi i32 [ %14, %10 ], [ %9, %8 ]
ret i32 %16
}