#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 */
unsigned char gdb_atoi_hex(int /*<<< orphan*/);
char *gdb_hex2mem(char *src, unsigned char *mem, int count) {
  unsigned char ch;
  while (count) {
    ch = gdb_atoi_hex(*src++) << 4;
    ch |= gdb_atoi_hex(*src++) << 0;
    *mem++ = ch;
    count--;
  }
  return (char *)mem;
}


x86 assembly (clang, -O0):
<gdb_hex2mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1195 <gdb_hex2mem+0x85>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <gdb_atoi_hex@plt>
movzbl %al,%eax
shl    $0x4,%eax
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <gdb_atoi_hex@plt>
movzbl %al,%ecx
shl    $0x0,%ecx
movzbl -0x15(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <gdb_hex2mem+0x13>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdb_hex2mem>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
test   %edx,%edx
je     115e <gdb_hex2mem+0x4e>
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,2),%edi
call   1030 <gdb_atoi_hex@plt>
mov    %eax,%ebp
shl    $0x4,%bpl
movsbl 0x1(%r15,%rbx,2),%edi
call   1030 <gdb_atoi_hex@plt>
or     %bpl,%al
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %ebx,%r12d
jne    1130 <gdb_hex2mem+0x20>
add    %rbx,%r14
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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