#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 */
void *gdbserv_to_hex(char);
unsigned int gdbserv_raw_to_hex(char **ptr, char *mem, int nr_bytes) {
  int i;
  for (i = 0; i < nr_bytes; i++) {
    *(*ptr)++ = gdbserv_to_hex(*mem >> 4);
    *(*ptr)++ = gdbserv_to_hex(*mem);
  }
  return i;
}


x86 assembly (clang, -O0):
<gdbserv_raw_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118c <gdbserv_raw_to_hex+0x7c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sar    $0x4,%eax
movsbl %al,%edi
call   1030 <gdbserv_to_hex@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <gdbserv_to_hex@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <gdbserv_raw_to_hex+0x1a>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdbserv_raw_to_hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    116b <gdbserv_raw_to_hex+0x5b>
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %edx,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl (%r15),%eax
sar    $0x4,%al
movsbl %al,%edi
call   1030 <gdbserv_to_hex@plt>
mov    0x0(%rbp),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,0x0(%rbp)
mov    %al,(%rcx)
movsbl (%r15),%edi
call   1030 <gdbserv_to_hex@plt>
mov    0x0(%rbp),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,0x0(%rbp)
mov    %al,(%rcx)
add    $0xffffffff,%ebx
jne    1130 <gdbserv_raw_to_hex+0x20>
jmp    116e <gdbserv_raw_to_hex+0x5e>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gdbserv_raw_to_hex(i8** %0, i8* %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %30, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %33
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = ashr i32 %15, 4
%17 = trunc i32 %16 to i8
%18 = call i8* @gdbserv_to_hex(i8 signext %17)
%19 = ptrtoint i8* %18 to i8
%20 = load i8**, i8*** %4
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %20
store i8 %19, i8* %21
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = call i8* @gdbserv_to_hex(i8 signext %24)
%26 = ptrtoint i8* %25 to i8
%27 = load i8**, i8*** %4
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %27
store i8 %26, i8* %28
br label %30
30: ; preds = %12
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %8
33: ; preds = %8
%34 = load i32, i32* %7
ret i32 %34
}

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