#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 uint32_t;
typedef int uint16_t;

/* Variables and functions */
int gdbstub_from_hex_digit(char);
void gdbstub_from_hex_buf(char *dst, char *src, int lenbytes) {
  if (lenbytes == 2 && ((unsigned long)dst & 0x1) == 0) {
    uint16_t i = gdbstub_from_hex_digit(src[2]) << 12 |
                 gdbstub_from_hex_digit(src[3]) << 8 |
                 gdbstub_from_hex_digit(src[0]) << 4 |
                 gdbstub_from_hex_digit(src[1]);
    *(uint16_t *)dst = i;
  } else if (lenbytes == 4 && ((unsigned long)dst & 0x3) == 0) {
    uint32_t i = gdbstub_from_hex_digit(src[6]) << 28 |
                 gdbstub_from_hex_digit(src[7]) << 24 |
                 gdbstub_from_hex_digit(src[4]) << 20 |
                 gdbstub_from_hex_digit(src[5]) << 16 |
                 gdbstub_from_hex_digit(src[2]) << 12 |
                 gdbstub_from_hex_digit(src[3]) << 8 |
                 gdbstub_from_hex_digit(src[0]) << 4 |
                 gdbstub_from_hex_digit(src[1]);
    *(uint32_t *)dst = i;
  } else {
    while (lenbytes-- > 0) {
      *dst++ =
          gdbstub_from_hex_digit(src[0]) << 4 | gdbstub_from_hex_digit(src[1]);
      src += 2;
    }
  }
}


x86 assembly (clang, -O0):
<gdbstub_from_hex_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    11aa <gdbstub_from_hex_buf+0x9a>
mov    -0x8(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    11aa <gdbstub_from_hex_buf+0x9a>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
shl    $0xc,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
shl    $0x4,%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1306 <gdbstub_from_hex_buf+0x1f6>
cmpl   $0x4,-0x14(%rbp)
jne    1299 <gdbstub_from_hex_buf+0x189>
mov    -0x8(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    1299 <gdbstub_from_hex_buf+0x189>
mov    -0x10(%rbp),%rax
movsbl 0x6(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
shl    $0x1c,%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x7(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x4(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
shl    $0x14,%ecx
or     %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x5(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
shl    $0x10,%ecx
or     %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
shl    $0xc,%ecx
or     %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
shl    $0x4,%ecx
or     %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1301 <gdbstub_from_hex_buf+0x1f1>
jmp    129e <gdbstub_from_hex_buf+0x18e>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    12fc <gdbstub_from_hex_buf+0x1ec>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
shl    $0x4,%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
or     %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    129e <gdbstub_from_hex_buf+0x18e>
jmp    1301 <gdbstub_from_hex_buf+0x1f1>
jmp    1306 <gdbstub_from_hex_buf+0x1f6>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdbstub_from_hex_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%r14
cmp    $0x2,%edx
jne    1159 <gdbstub_from_hex_buf+0x49>
mov    %r14d,%eax
and    $0x1,%eax
test   %rax,%rax
jne    1159 <gdbstub_from_hex_buf+0x49>
movsbl 0x2(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%r15d
shl    $0xc,%r15d
movsbl 0x3(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
jmp    11e0 <gdbstub_from_hex_buf+0xd0>
cmp    $0x4,%r15d
jne    1213 <gdbstub_from_hex_buf+0x103>
mov    %r14d,%eax
and    $0x3,%eax
test   %rax,%rax
jne    1213 <gdbstub_from_hex_buf+0x103>
movsbl 0x6(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%r15d
shl    $0x1c,%r15d
movsbl 0x7(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ebp
shl    $0x18,%ebp
or     %r15d,%ebp
movsbl 0x4(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%r15d
shl    $0x14,%r15d
movsbl 0x5(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%r12d
shl    $0x10,%r12d
or     %r15d,%r12d
or     %ebp,%r12d
movsbl 0x2(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ebp
shl    $0xc,%ebp
or     %r12d,%ebp
movsbl 0x3(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%r15d
shl    $0x8,%r15d
or     %ebp,%r15d
movsbl 0x0(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movsbl 0x1(%r13),%edi
call   1030 <gdbstub_from_hex_digit@plt>
or     %ebx,%eax
or     %r15d,%eax
mov    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r15d,%r15d
jle    1204 <gdbstub_from_hex_buf+0xf4>
add    $0x1,%r15d
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl 0x0(%r13,%rbp,2),%edi
call   1030 <gdbstub_from_hex_digit@plt>
mov    %eax,%ebx
shl    $0x4,%ebx
movsbl 0x1(%r13,%rbp,2),%edi
call   1030 <gdbstub_from_hex_digit@plt>
or     %ebx,%eax
mov    %al,(%r14,%rbp,1)
add    $0x1,%rbp
add    $0xffffffff,%r15d
cmp    $0x1,%r15d
ja     1220 <gdbstub_from_hex_buf+0x110>
jmp    1204 <gdbstub_from_hex_buf+0xf4>

LLVM IR (-O0):
define void @gdbstub_from_hex_buf(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %42
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = ptrtoint i8* %12 to i64
%14 = and i64 %13, 1
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %42
16: ; preds = %11
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 2
%19 = load i8, i8* %18
%20 = call i32 @gdbstub_from_hex_digit(i8 signext %19)
%21 = shl i32 %20, 12
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 3
%24 = load i8, i8* %23
%25 = call i32 @gdbstub_from_hex_digit(i8 signext %24)
%26 = shl i32 %25, 8
%27 = or i32 %21, %26
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = call i32 @gdbstub_from_hex_digit(i8 signext %30)
%32 = shl i32 %31, 4
%33 = or i32 %27, %32
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = call i32 @gdbstub_from_hex_digit(i8 signext %36)
%38 = or i32 %33, %37
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = load i8*, i8** %4
%41 = bitcast i8* %40 to i32*
store i32 %39, i32* %41
br label %123
42: ; preds = %11, %3
%43 = load i32, i32* %6
%44 = icmp eq i32 %43, 4
br i1 %44, label %45, label %100
45: ; preds = %42
%46 = load i8*, i8** %4
%47 = ptrtoint i8* %46 to i64
%48 = and i64 %47, 3
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %100
50: ; preds = %45
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i64 6
%53 = load i8, i8* %52
%54 = call i32 @gdbstub_from_hex_digit(i8 signext %53)
%55 = shl i32 %54, 28
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i64 7
%58 = load i8, i8* %57
%59 = call i32 @gdbstub_from_hex_digit(i8 signext %58)
%60 = shl i32 %59, 24
%61 = or i32 %55, %60
%62 = load i8*, i8** %5
%63 = getelementptr inbounds i8, i8* %62, i64 4
%64 = load i8, i8* %63
%65 = call i32 @gdbstub_from_hex_digit(i8 signext %64)
%66 = shl i32 %65, 20
%67 = or i32 %61, %66
%68 = load i8*, i8** %5
%69 = getelementptr inbounds i8, i8* %68, i64 5
%70 = load i8, i8* %69
%71 = call i32 @gdbstub_from_hex_digit(i8 signext %70)
%72 = shl i32 %71, 16
%73 = or i32 %67, %72
%74 = load i8*, i8** %5
%75 = getelementptr inbounds i8, i8* %74, i64 2
%76 = load i8, i8* %75
%77 = call i32 @gdbstub_from_hex_digit(i8 signext %76)
%78 = shl i32 %77, 12
%79 = or i32 %73, %78
%80 = load i8*, i8** %5
%81 = getelementptr inbounds i8, i8* %80, i64 3
%82 = load i8, i8* %81
%83 = call i32 @gdbstub_from_hex_digit(i8 signext %82)
%84 = shl i32 %83, 8
%85 = or i32 %79, %84
%86 = load i8*, i8** %5
%87 = getelementptr inbounds i8, i8* %86, i64 0
%88 = load i8, i8* %87
%89 = call i32 @gdbstub_from_hex_digit(i8 signext %88)
%90 = shl i32 %89, 4
%91 = or i32 %85, %90
%92 = load i8*, i8** %5
%93 = getelementptr inbounds i8, i8* %92, i64 1
%94 = load i8, i8* %93
%95 = call i32 @gdbstub_from_hex_digit(i8 signext %94)
%96 = or i32 %91, %95
store i32 %96, i32* %8
%97 = load i32, i32* %8
%98 = load i8*, i8** %4
%99 = bitcast i8* %98 to i32*
store i32 %97, i32* %99
br label %122
100: ; preds = %45, %42
br label %101
101: ; preds = %105, %100
%102 = load i32, i32* %6
%103 = add nsw i32 %102, -1
store i32 %103, i32* %6
%104 = icmp sgt i32 %102, 0
br i1 %104, label %105, label %121
105: ; preds = %101
%106 = load i8*, i8** %5
%107 = getelementptr inbounds i8, i8* %106, i64 0
%108 = load i8, i8* %107
%109 = call i32 @gdbstub_from_hex_digit(i8 signext %108)
%110 = shl i32 %109, 4
%111 = load i8*, i8** %5
%112 = getelementptr inbounds i8, i8* %111, i64 1
%113 = load i8, i8* %112
%114 = call i32 @gdbstub_from_hex_digit(i8 signext %113)
%115 = or i32 %110, %114
%116 = trunc i32 %115 to i8
%117 = load i8*, i8** %4
%118 = getelementptr inbounds i8, i8* %117, i32 1
store i8* %118, i8** %4
store i8 %116, i8* %117
%119 = load i8*, i8** %5
%120 = getelementptr inbounds i8, i8* %119, i64 2
store i8* %120, i8** %5
br label %101
121: ; preds = %101
br label %122
122: ; preds = %121, %50
br label %123
123: ; preds = %122, %16
ret void
}

LLVM IR (-O2):
define void @gdbstub_from_hex_buf(i8* %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 2
%5 = ptrtoint i8* %0 to i64
%6 = and i64 %5, 1
%7 = icmp eq i64 %6, 0
%8 = and i1 %4, %7
br i1 %8, label %9, label %18
9: ; preds = %3
%10 = getelementptr inbounds i8, i8* %1, i64 2
%11 = load i8, i8* %10
%12 = tail call i32 @gdbstub_from_hex_digit(i8 signext %11)
%13 = shl i32 %12, 12
%14 = getelementptr inbounds i8, i8* %1, i64 3
%15 = load i8, i8* %14
%16 = tail call i32 @gdbstub_from_hex_digit(i8 signext %15)
%17 = shl i32 %16, 8
br label %70
18: ; preds = %3
%19 = icmp eq i32 %2, 4
%20 = and i64 %5, 3
%21 = icmp eq i64 %20, 0
%22 = and i1 %19, %21
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = icmp sgt i32 %2, 0
br i1 %24, label %54, label %83
25: ; preds = %18
%26 = getelementptr inbounds i8, i8* %1, i64 6
%27 = load i8, i8* %26
%28 = tail call i32 @gdbstub_from_hex_digit(i8 signext %27)
%29 = shl i32 %28, 28
%30 = getelementptr inbounds i8, i8* %1, i64 7
%31 = load i8, i8* %30
%32 = tail call i32 @gdbstub_from_hex_digit(i8 signext %31)
%33 = shl i32 %32, 24
%34 = or i32 %33, %29
%35 = getelementptr inbounds i8, i8* %1, i64 4
%36 = load i8, i8* %35
%37 = tail call i32 @gdbstub_from_hex_digit(i8 signext %36)
%38 = shl i32 %37, 20
%39 = or i32 %34, %38
%40 = getelementptr inbounds i8, i8* %1, i64 5
%41 = load i8, i8* %40
%42 = tail call i32 @gdbstub_from_hex_digit(i8 signext %41)
%43 = shl i32 %42, 16
%44 = or i32 %39, %43
%45 = getelementptr inbounds i8, i8* %1, i64 2
%46 = load i8, i8* %45
%47 = tail call i32 @gdbstub_from_hex_digit(i8 signext %46)
%48 = shl i32 %47, 12
%49 = or i32 %44, %48
%50 = getelementptr inbounds i8, i8* %1, i64 3
%51 = load i8, i8* %50
%52 = tail call i32 @gdbstub_from_hex_digit(i8 signext %51)
%53 = shl i32 %52, 8
br label %70
54: ; preds = %23, %54
%55 = phi i8* [ %67, %54 ], [ %0, %23 ]
%56 = phi i8* [ %68, %54 ], [ %1, %23 ]
%57 = phi i32 [ %58, %54 ], [ %2, %23 ]
%58 = add nsw i32 %57, -1
%59 = load i8, i8* %56
%60 = tail call i32 @gdbstub_from_hex_digit(i8 signext %59)
%61 = shl i32 %60, 4
%62 = getelementptr inbounds i8, i8* %56, i64 1
%63 = load i8, i8* %62
%64 = tail call i32 @gdbstub_from_hex_digit(i8 signext %63)
%65 = or i32 %64, %61
%66 = trunc i32 %65 to i8
%67 = getelementptr inbounds i8, i8* %55, i64 1
store i8 %66, i8* %55
%68 = getelementptr inbounds i8, i8* %56, i64 2
%69 = icmp ugt i32 %57, 1
br i1 %69, label %54, label %83
70: ; preds = %9, %25
%71 = phi i32 [ %53, %25 ], [ %13, %9 ]
%72 = phi i32 [ %49, %25 ], [ %17, %9 ]
%73 = or i32 %72, %71
%74 = load i8, i8* %1
%75 = tail call i32 @gdbstub_from_hex_digit(i8 signext %74)
%76 = shl i32 %75, 4
%77 = or i32 %73, %76
%78 = getelementptr inbounds i8, i8* %1, i64 1
%79 = load i8, i8* %78
%80 = tail call i32 @gdbstub_from_hex_digit(i8 signext %79)
%81 = or i32 %77, %80
%82 = bitcast i8* %0 to i32*
store i32 %81, i32* %82
br label %83
83: ; preds = %54, %70, %23
ret void
}