#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
void *s_b2h4(int);
void pdu_bytes2hex(uint8_t *b, uint16_t len, uint8_t *h) {
  if (len == 0)
    return;
  b += len - 1;
  h += ((uint16_t)len << 1) - 1;
  while (len--) {
    *h-- = s_b2h4(*b & 0xF);
    *h-- = s_b2h4(*b-- >> 4);
  }
}


x86 assembly (clang, -O0):
<pdu_bytes2hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1132 <pdu_bytes2hex+0x22>
jmp    11cb <pdu_bytes2hex+0xbb>
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11cb <pdu_bytes2hex+0xbb>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
and    $0xf,%edi
call   1030 <s_b2h4@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xfffffffffffffffc,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xfffffffffffffffc,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%edi
sar    $0x4,%edi
call   1030 <s_b2h4@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0xfffffffffffffffc,%rdx
mov    %rdx,-0x18(%rbp)
mov    %ecx,(%rax)
jmp    1165 <pdu_bytes2hex+0x55>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdu_bytes2hex>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     116a <pdu_bytes2hex+0x5a>
mov    %esi,%r14d
movslq %esi,%rax
lea    (%rdi,%rax,4),%r15
add    $0xfffffffffffffffc,%r15
lea    (%r14,%r14,1),%eax
cltq
lea    (%rdx,%rax,4),%r12
add    $0xfffffffffffffffc,%r12
neg    %r14d
xor    %ebx,%ebx
nopl   (%rax)
mov    (%r15,%rbx,4),%edi
and    $0xf,%edi
call   1030 <s_b2h4@plt>
mov    %eax,(%r12,%rbx,8)
mov    (%r15,%rbx,4),%edi
sar    $0x4,%edi
call   1030 <s_b2h4@plt>
mov    %eax,-0x4(%r12,%rbx,8)
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r14d
jne    1140 <pdu_bytes2hex+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @pdu_bytes2hex(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32, i32* %5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %3
br label %42
10: ; preds = %3
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
%13 = load i32*, i32** %4
%14 = sext i32 %12 to i64
%15 = getelementptr inbounds i32, i32* %13, i64 %14
store i32* %15, i32** %4
%16 = load i32, i32* %5
%17 = shl i32 %16, 1
%18 = sub nsw i32 %17, 1
%19 = load i32*, i32** %6
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i32, i32* %19, i64 %20
store i32* %21, i32** %6
br label %22
22: ; preds = %26, %10
%23 = load i32, i32* %5
%24 = add nsw i32 %23, -1
store i32 %24, i32* %5
%25 = icmp ne i32 %23, 0
br i1 %25, label %26, label %42
26: ; preds = %22
%27 = load i32*, i32** %4
%28 = load i32, i32* %27
%29 = and i32 %28, 15
%30 = call i8* @s_b2h4(i32 %29)
%31 = ptrtoint i8* %30 to i32
%32 = load i32*, i32** %6
%33 = getelementptr inbounds i32, i32* %32, i32 -1
store i32* %33, i32** %6
store i32 %31, i32* %32
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i32 -1
store i32* %35, i32** %4
%36 = load i32, i32* %34
%37 = ashr i32 %36, 4
%38 = call i8* @s_b2h4(i32 %37)
%39 = ptrtoint i8* %38 to i32
%40 = load i32*, i32** %6
%41 = getelementptr inbounds i32, i32* %40, i32 -1
store i32* %41, i32** %6
store i32 %39, i32* %40
br label %22
42: ; preds = %9, %22
ret void
}

LLVM IR (-O2):
define void @pdu_bytes2hex(i32* nocapture %0, i32 %1, i32* nocapture writeonly %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %32, label %5
5: ; preds = %3
%6 = add nsw i32 %1, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = shl i32 %1, 1
%10 = add nsw i32 %9, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %2, i64 %11
br label %13
13: ; preds = %5, %13
%14 = phi i32* [ %12, %5 ], [ %30, %13 ]
%15 = phi i32 [ %1, %5 ], [ %17, %13 ]
%16 = phi i32* [ %8, %5 ], [ %24, %13 ]
%17 = add nsw i32 %15, -1
%18 = load i32, i32* %16
%19 = and i32 %18, 15
%20 = tail call i8* @s_b2h4(i32 %19)
%21 = ptrtoint i8* %20 to i64
%22 = trunc i64 %21 to i32
%23 = getelementptr inbounds i32, i32* %14, i64 -1
store i32 %22, i32* %14
%24 = getelementptr inbounds i32, i32* %16, i64 -1
%25 = load i32, i32* %16
%26 = ashr i32 %25, 4
%27 = tail call i8* @s_b2h4(i32 %26)
%28 = ptrtoint i8* %27 to i64
%29 = trunc i64 %28 to i32
%30 = getelementptr inbounds i32, i32* %14, i64 -2
store i32 %29, i32* %23
%31 = icmp eq i32 %17, 0
br i1 %31, label %32, label %13
32: ; preds = %13, %3
ret void
}