#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 uint64_t;

/* Variables and functions */
int gdb_decode_hex(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ isxdigit(int /*<<< orphan*/);
uint64_t gdb_decode_hex_str(uint8_t *bytes) {
  uint64_t value = 0;
  uint64_t weight = 1;
  while (isxdigit(bytes[0]) && isxdigit(bytes[1])) {
    value += weight * gdb_decode_hex(bytes[0], bytes[1]);
    bytes += 2;
    weight *= 16 * 16;
  }
  return value;
}


x86 assembly (clang, -O0):
<gdb_decode_hex_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <isxdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     116d <gdb_decode_hex_str+0x4d>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    117d <gdb_decode_hex_str+0x5d>
jmp    11bd <gdb_decode_hex_str+0x9d>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
call   1030 <gdb_decode_hex@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <gdb_decode_hex_str+0x1a>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdb_decode_hex_str>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1040 <isxdigit@plt>
test   %rax,%rax
je     1173 <gdb_decode_hex_str+0x53>
add    $0x8,%rbx
xor    %r14d,%r14d
mov    $0x1,%ebp
nop
mov    -0x4(%rbx),%edi
call   1040 <isxdigit@plt>
test   %rax,%rax
je     1176 <gdb_decode_hex_str+0x56>
mov    -0x8(%rbx),%edi
mov    -0x4(%rbx),%esi
call   1030 <gdb_decode_hex@plt>
imul   %ebp,%eax
add    %eax,%r14d
shl    $0x8,%ebp
mov    (%rbx),%edi
call   1040 <isxdigit@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    1140 <gdb_decode_hex_str+0x20>
jmp    1176 <gdb_decode_hex_str+0x56>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gdb_decode_hex_str(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
store i32 1, i32* %4
br label %5
5: ; preds = %19, %1
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 0
%8 = load i32, i32* %7
%9 = call i64 @isxdigit(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %5
%12 = load i32*, i32** %2
%13 = getelementptr inbounds i32, i32* %12, i64 1
%14 = load i32, i32* %13
%15 = call i64 @isxdigit(i32 %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %11, %5
%18 = phi i1 [ false, %5 ], [ %16, %11 ]
br i1 %18, label %19, label %35
19: ; preds = %17
%20 = load i32, i32* %4
%21 = load i32*, i32** %2
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
%24 = load i32*, i32** %2
%25 = getelementptr inbounds i32, i32* %24, i64 1
%26 = load i32, i32* %25
%27 = call i32 @gdb_decode_hex(i32 %23, i32 %26)
%28 = mul nsw i32 %20, %27
%29 = load i32, i32* %3
%30 = add nsw i32 %29, %28
store i32 %30, i32* %3
%31 = load i32*, i32** %2
%32 = getelementptr inbounds i32, i32* %31, i64 2
store i32* %32, i32** %2
%33 = load i32, i32* %4
%34 = mul nsw i32 %33, 256
store i32 %34, i32* %4
br label %5
35: ; preds = %17
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
define i32 @gdb_decode_hex_str(i32* nocapture %0) {
%2 = load i32, i32* %0
%3 = tail call i64 @isxdigit(i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %1, %13
%6 = phi i32 [ %20, %13 ], [ 1, %1 ]
%7 = phi i32 [ %18, %13 ], [ 0, %1 ]
%8 = phi i32* [ %19, %13 ], [ %0, %1 ]
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = load i32, i32* %9
%11 = tail call i64 @isxdigit(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %5
%14 = load i32, i32* %8
%15 = load i32, i32* %9
%16 = tail call i32 @gdb_decode_hex(i32 %14, i32 %15)
%17 = mul nsw i32 %16, %6
%18 = add nsw i32 %17, %7
%19 = getelementptr inbounds i32, i32* %8, i64 2
%20 = shl nsw i32 %6, 8
%21 = load i32, i32* %19
%22 = tail call i64 @isxdigit(i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %5
24: ; preds = %5, %13, %1
%25 = phi i32 [ 0, %1 ], [ %18, %13 ], [ %7, %5 ]
ret i32 %25
}