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


x86 assembly (clang, -O0):
<gdbstub_to_hex_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jne    11a5 <gdbstub_to_hex_buf+0x95>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
jne    11a5 <gdbstub_to_hex_buf+0x95>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x4,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%eax
sar    $0xc,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
jmp    12fb <gdbstub_to_hex_buf+0x1eb>
cmpl   $0x4,-0x14(%rbp)
jne    1283 <gdbstub_to_hex_buf+0x173>
mov    -0x10(%rbp),%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    1283 <gdbstub_to_hex_buf+0x173>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x4,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x1c(%rbp),%eax
sar    $0xc,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x8,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x14,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x10,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x1c,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x1c(%rbp),%eax
sar    $0x18,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x7(%rax)
jmp    12f6 <gdbstub_to_hex_buf+0x1e6>
jmp    1288 <gdbstub_to_hex_buf+0x178>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    12f1 <gdbstub_to_hex_buf+0x1e1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sar    $0x4,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <gdbstub_to_hex_digit@plt>
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    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1288 <gdbstub_to_hex_buf+0x178>
jmp    12f6 <gdbstub_to_hex_buf+0x1e6>
jmp    12fb <gdbstub_to_hex_buf+0x1eb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdbstub_to_hex_buf>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
cmp    $0x2,%edx
jne    116c <gdbstub_to_hex_buf+0x5c>
mov    %r15d,%eax
and    $0x1,%eax
test   %rax,%rax
jne    116c <gdbstub_to_hex_buf+0x5c>
mov    (%r15),%ebx
mov    %ebx,%eax
shr    $0x4,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,(%r14)
movsbl %bl,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,0x1(%r14)
mov    %ebx,%eax
shr    $0xc,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,0x2(%r14)
shr    $0x8,%ebx
mov    $0x3,%ebp
jmp    11fd <gdbstub_to_hex_buf+0xed>
cmp    $0x4,%ebp
jne    1214 <gdbstub_to_hex_buf+0x104>
mov    %r15d,%eax
and    $0x3,%eax
test   %rax,%rax
jne    1214 <gdbstub_to_hex_buf+0x104>
mov    (%r15),%ebx
mov    %ebx,%eax
shr    $0x4,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,(%r14)
movsbl %bl,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,0x1(%r14)
mov    %ebx,%eax
shr    $0xc,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,0x2(%r14)
mov    %ebx,%eax
shr    $0x8,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,0x3(%r14)
mov    %ebx,%eax
shr    $0x14,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,0x4(%r14)
mov    %ebx,%eax
shr    $0x10,%eax
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,0x5(%r14)
mov    %ebx,%edi
sar    $0x1c,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,0x6(%r14)
shr    $0x18,%ebx
mov    $0x7,%ebp
movsbl %bl,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,(%r14,%rbp,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
jle    1209 <gdbstub_to_hex_buf+0xf9>
add    $0x1,%ebp
xor    %ebx,%ebx
nopl   (%rax)
movzbl (%r15,%rbx,1),%eax
sar    $0x4,%al
movsbl %al,%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,(%r14,%rbx,2)
movsbl (%r15,%rbx,1),%edi
call   1030 <gdbstub_to_hex_digit@plt>
mov    %al,0x1(%r14,%rbx,2)
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1220 <gdbstub_to_hex_buf+0x110>
jmp    1209 <gdbstub_to_hex_buf+0xf9>

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

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