#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 */
int /*<<< orphan*/ byte2hex(char *, unsigned char);
void write_hexstr(char *hexstr, unsigned char barray[], int blen) {
  int i;
  char *dst = hexstr;
  unsigned char *byte = barray;
  for (i = 0; i < blen; i++) {
    byte2hex(dst, *byte);
    dst += 2;
    byte++;
  }
}


x86 assembly (clang, -O0):
<write_hexstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    117c <write_hexstr+0x6c>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
movzbl (%rax),%esi
call   1030 <byte2hex@plt>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <write_hexstr+0x2a>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_hexstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    114a <write_hexstr+0x3a>
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%esi
mov    %r12,%rdi
call   1030 <byte2hex@plt>
add    $0x2,%r12
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    1130 <write_hexstr+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @write_hexstr(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %4
store i8* %10, i8** %8
%11 = load i8*, i8** %5
store i8* %11, i8** %9
store i32 0, i32* %7
br label %12
12: ; preds = %25, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i8*, i8** %8
%18 = load i8*, i8** %9
%19 = load i8, i8* %18
%20 = call i32 @byte2hex(i8* %17, i8 zeroext %19)
%21 = load i8*, i8** %8
%22 = getelementptr inbounds i8, i8* %21, i64 2
store i8* %22, i8** %8
%23 = load i8*, i8** %9
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %9
br label %25
25: ; preds = %16
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %12
28: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @write_hexstr(i8* %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %15
5: ; preds = %3, %5
%6 = phi i8* [ %12, %5 ], [ %1, %3 ]
%7 = phi i8* [ %11, %5 ], [ %0, %3 ]
%8 = phi i32 [ %13, %5 ], [ 0, %3 ]
%9 = load i8, i8* %6
%10 = tail call i32 @byte2hex(i8* %7, i8 zeroext %9)
%11 = getelementptr inbounds i8, i8* %7, i64 2
%12 = getelementptr inbounds i8, i8* %6, i64 1
%13 = add nuw nsw i32 %8, 1
%14 = icmp eq i32 %13, %2
br i1 %14, label %15, label %5
15: ; preds = %5, %3
ret void
}