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

/* Variables and functions */
int /*<<< orphan*/ util_hex_to_byte(char *);
int gdb_read_hex_data(uint8_t *hexdata, int count, uint8_t *outdata, int max) {
  int i = 0;
  int j = 0;
  unsigned char *src = (unsigned char *)hexdata;
  unsigned char *dst = (unsigned char *)outdata;
  while (i < count) {
    if (j + 1 > max)
      break;
    *(dst++) = util_hex_to_byte((char *)src);
    src += 2;
    j++;
    i++;
  }
  return i;
}


x86 assembly (clang, -O0):
<gdb_read_hex_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a3 <gdb_read_hex_data+0x93>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jle    1164 <gdb_read_hex_data+0x54>
jmp    11a3 <gdb_read_hex_data+0x93>
mov    -0x30(%rbp),%rdi
call   1030 <util_hex_to_byte@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cl,(%rax)
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1144 <gdb_read_hex_data+0x34>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdb_read_hex_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %esi,%esi
jle    1161 <gdb_read_hex_data+0x51>
mov    %ecx,%r15d
test   %ecx,%ecx
jle    1161 <gdb_read_hex_data+0x51>
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%r13
add    $0x1,%rbx
mov    %rbp,%rdi
call   1030 <util_hex_to_byte@plt>
mov    %al,(%r14,%r13,1)
cmp    %r12d,%ebx
jge    1161 <gdb_read_hex_data+0x51>
add    $0x2,%rbp
cmp    %r15d,%ebx
jl     1140 <gdb_read_hex_data+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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