char *chunk_data(char *buff, int size) {
  static char t[] = "0123456789ABCDEF";
  buff[size] = '\r';
  buff[size + 1] = '\n';
  *(--buff) = '\n';
  *(--buff) = '\r';
  int i = 4;
  do {
    *(--buff) = t[size & 0x0f];
    size >>= 4;
    --i;
  } while (size && i > 0);
  return buff;
}


x86 assembly (clang, -O0):
<chunk_data>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0xd,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0xa,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xa,-0x1(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xd,-0x1(%rax)
movl   $0x4,-0x10(%rbp)
mov    -0xc(%rbp),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0x2ecb(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,-0x1(%rax)
mov    -0xc(%rbp),%eax
sar    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x11(%rbp)
je     11a5 <chunk_data+0xa5>
cmpl   $0x0,-0x10(%rbp)
setg   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1155 <chunk_data+0x55>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<chunk_data>:
mov    %rdi,%rax
movslq %esi,%rdx
movw   $0xa0d,(%rdi,%rdx,1)
movw   $0xa0d,-0x2(%rdi)
mov    %edx,%edi
and    $0xf,%edi
lea    0xee2(%rip),%r8
mov    (%rdi,%r8,1),%cl
mov    %cl,-0x3(%rax)
cmp    $0x10,%edx
jb     116a <chunk_data+0x6a>
mov    %esi,%ecx
shr    $0x4,%ecx
and    $0xf,%ecx
mov    (%rcx,%r8,1),%cl
mov    %cl,-0x4(%rax)
cmp    $0x100,%esi
jb     116f <chunk_data+0x6f>
mov    %esi,%ecx
shr    $0x8,%ecx
and    $0xf,%ecx
mov    (%rcx,%r8,1),%cl
mov    %cl,-0x5(%rax)
cmp    $0x1000,%esi
jb     1174 <chunk_data+0x74>
shr    $0xc,%esi
and    $0xf,%esi
mov    (%rsi,%r8,1),%cl
mov    %cl,-0x6(%rax)
add    $0xfffffffffffffffa,%rax
ret
add    $0xfffffffffffffffd,%rax
ret
add    $0xfffffffffffffffc,%rax
ret
add    $0xfffffffffffffffb,%rax
ret

LLVM IR (-O0):
@chunk_data.t = internal global [17 x i8] c"0123456789ABCDEF\00"
define i8* @chunk_data(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
store i8 13, i8* %9
%10 = load i8*, i8** %3
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
store i8 10, i8* %14
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 -1
store i8* %16, i8** %3
store i8 10, i8* %16
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i32 -1
store i8* %18, i8** %3
store i8 13, i8* %18
store i32 4, i32* %5
br label %19
19: ; preds = %37, %2
%20 = load i32, i32* %4
%21 = and i32 %20, 15
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @chunk_data.t, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 -1
store i8* %26, i8** %3
store i8 %24, i8* %26
%27 = load i32, i32* %4
%28 = ashr i32 %27, 4
store i32 %28, i32* %4
%29 = load i32, i32* %5
%30 = add nsw i32 %29, -1
store i32 %30, i32* %5
br label %31
31: ; preds = %19
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i32, i32* %5
%36 = icmp sgt i32 %35, 0
br label %37
37: ; preds = %34, %31
%38 = phi i1 [ false, %31 ], [ %36, %34 ]
br i1 %38, label %19, label %39
39: ; preds = %37
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
@chunk_data.t = internal unnamed_addr constant [17 x i8] c"0123456789ABCDEF\00"
define i8* @chunk_data(i8* writeonly %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
store i8 13, i8* %4
%5 = add nsw i32 %1, 1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 10, i8* %7
%8 = getelementptr inbounds i8, i8* %0, i64 -1
store i8 10, i8* %8
%9 = getelementptr inbounds i8, i8* %0, i64 -2
store i8 13, i8* %9
%10 = and i32 %1, 15
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [17 x i8], [17 x i8]* @chunk_data.t, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %0, i64 -3
store i8 %13, i8* %14
%15 = icmp ugt i32 %1, 15
br i1 %15, label %16, label %39
16: ; preds = %2
%17 = lshr i32 %1, 4
%18 = and i32 %17, 15
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [17 x i8], [17 x i8]* @chunk_data.t, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8, i8* %0, i64 -4
store i8 %21, i8* %22
%23 = icmp ugt i32 %1, 255
br i1 %23, label %24, label %39
24: ; preds = %16
%25 = lshr i32 %1, 8
%26 = and i32 %25, 15
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds [17 x i8], [17 x i8]* @chunk_data.t, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds i8, i8* %0, i64 -5
store i8 %29, i8* %30
%31 = icmp ugt i32 %1, 4095
br i1 %31, label %32, label %39
32: ; preds = %24
%33 = lshr i32 %1, 12
%34 = and i32 %33, 15
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [17 x i8], [17 x i8]* @chunk_data.t, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = getelementptr inbounds i8, i8* %0, i64 -6
store i8 %37, i8* %38
br label %39
39: ; preds = %32, %24, %16, %2
%40 = phi i8* [ %14, %2 ], [ %22, %16 ], [ %30, %24 ], [ %38, %32 ]
ret i8* %40
}