#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 util_bin_to_byte(unsigned char *, unsigned char *);
int gdb_read_bin_data(uint8_t *bindata, int count, uint8_t *outdata, int max) {
  int j = 0;
  int i = 0;
  int cnt;
  unsigned char *src = (unsigned char *)bindata;
  unsigned char *dst = (unsigned char *)outdata;
  while (j < count) {
    if (i + 2 > max)
      break;
    cnt = util_bin_to_byte(src, dst);
    src += cnt;
    dst++;
    i++;
    j++;
  }
  return i;
}


x86 assembly (clang, -O0):
<gdb_read_bin_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    11a8 <gdb_read_bin_data+0x98>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
cmp    -0x1c(%rbp),%eax
jle    1164 <gdb_read_bin_data+0x54>
jmp    11a8 <gdb_read_bin_data+0x98>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <util_bin_to_byte@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%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_bin_data+0x34>
mov    -0x24(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdb_read_bin_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
test   %esi,%esi
jle    1168 <gdb_read_bin_data+0x58>
mov    %ecx,%r15d
cmp    $0x2,%ecx
jl     1168 <gdb_read_bin_data+0x58>
mov    %rdx,%r14
mov    %esi,%r12d
mov    %rdi,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbp,1),%rsi
mov    %rbx,%rdi
call   1030 <util_bin_to_byte@plt>
mov    %eax,%ecx
lea    0x1(%rbp),%rax
cmp    %r12d,%eax
jge    1168 <gdb_read_bin_data+0x58>
movslq %ecx,%rcx
add    %rcx,%rbx
add    $0x3,%ebp
cmp    %r15d,%ebp
mov    %rax,%rbp
jle    1140 <gdb_read_bin_data+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @gdb_read_bin_data(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = icmp slt i32 %1, 1
%6 = icmp slt i32 %3, 2
%7 = or i1 %5, %6
br i1 %7, label %24, label %8
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* [ %17, %11 ], [ %10, %8 ]
%14 = phi i32 [ %19, %11 ], [ 0, %8 ]
%15 = tail call i32 @util_bin_to_byte(i8* %13, i8* %12)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = getelementptr inbounds i8, i8* %12, i64 1
%19 = add nuw nsw i32 %14, 1
%20 = icmp sge i32 %19, %1
%21 = add nuw nsw i32 %14, 3
%22 = icmp sgt i32 %21, %3
%23 = select i1 %20, i1 true, i1 %22
br i1 %23, label %24, label %11
24: ; preds = %11, %4
%25 = phi i32 [ 0, %4 ], [ %19, %11 ]
ret i32 %25
}