#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_byte_to_bin(unsigned char *, int /*<<< orphan*/);
int gdb_write_bin_data(uint8_t *indata, int count, uint8_t *bindata, int max) {
  int i = 0;
  int j = 0;
  int len;
  unsigned char *src = (unsigned char *)indata;
  unsigned char *dst = (unsigned char *)bindata;
  while (i < count) {
    if (j + 2 > max)
      break;
    len = util_byte_to_bin(dst, *(src++));
    dst += len;
    j += len;
    i++;
  }
  return i;
}


x86 assembly (clang, -O0):
<gdb_write_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    11aa <gdb_write_bin_data+0x9a>
mov    -0x24(%rbp),%eax
add    $0x2,%eax
cmp    -0x1c(%rbp),%eax
jle    1164 <gdb_write_bin_data+0x54>
jmp    11aa <gdb_write_bin_data+0x9a>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movzbl (%rax),%esi
call   1030 <util_byte_to_bin@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1144 <gdb_write_bin_data+0x34>
mov    -0x20(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdb_write_bin_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
test   %esi,%esi
jle    116d <gdb_write_bin_data+0x5d>
mov    %ecx,%r14d
cmp    $0x2,%ecx
jl     116d <gdb_write_bin_data+0x5d>
mov    %rdx,%rbp
mov    %esi,%r15d
mov    %rdi,%r12
xor    %ebx,%ebx
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
mov    %rbp,%rdi
call   1030 <util_byte_to_bin@plt>
add    $0x1,%rbx
cmp    %r15d,%ebx
jge    116d <gdb_write_bin_data+0x5d>
cltq
add    %rax,%rbp
lea    (%rax,%r13,1),%ecx
add    $0x2,%ecx
add    %r13d,%eax
mov    %eax,%r13d
cmp    %r14d,%ecx
jle    1140 <gdb_write_bin_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_write_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 %44
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 %44
28: ; preds = %22
%29 = load i8*, i8** %13
%30 = load i8*, i8** %12
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %12
%32 = load i8, i8* %30
%33 = zext i8 %32 to i32
%34 = call i32 @util_byte_to_bin(i8* %29, i32 %33)
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = load i8*, i8** %13
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %36, i64 %37
store i8* %38, i8** %13
%39 = load i32, i32* %11
%40 = load i32, i32* %10
%41 = add nsw i32 %40, %39
store i32 %41, i32* %10
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %18
44: ; preds = %27, %18
%45 = load i32, i32* %9
ret i32 %45
}

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