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

/* Variables and functions */
char nibble_to_ascii(int);
void fill_ascii_buffer(uint8_t *source, char *dest, int bin_count) {
  for (int i = 0; i < bin_count; ++i) {
    dest[i * 2] = nibble_to_ascii(source[i] >> 4);
    dest[i * 2 + 1] = nibble_to_ascii(source[i] & 0xF);
  }
}


x86 assembly (clang, -O0):
<fill_ascii_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1191 <fill_ascii_buffer+0x81>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
sar    $0x4,%edi
call   1030 <nibble_to_ascii@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
and    $0xf,%edi
call   1030 <nibble_to_ascii@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <fill_ascii_buffer+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_ascii_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    115a <fill_ascii_buffer+0x4a>
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%edi
sar    $0x4,%edi
call   1030 <nibble_to_ascii@plt>
mov    %al,(%r14,%rbx,2)
mov    (%r12,%rbx,4),%edi
and    $0xf,%edi
call   1030 <nibble_to_ascii@plt>
mov    %al,0x1(%r14,%rbx,2)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <fill_ascii_buffer+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @fill_ascii_buffer(i32* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %8
7: ; preds = %8, %3
ret void
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %21, %8 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = ashr i32 %11, 4
%13 = tail call signext i8 @nibble_to_ascii(i32 %12)
%14 = shl nuw nsw i64 %9, 1
%15 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 %13, i8* %15
%16 = load i32, i32* %10
%17 = and i32 %16, 15
%18 = tail call signext i8 @nibble_to_ascii(i32 %17)
%19 = or i64 %14, 1
%20 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 %18, i8* %20
%21 = add nuw nsw i64 %9, 1
%22 = icmp eq i64 %21, %6
br i1 %22, label %7, label %8
}