#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 */
unsigned char getUChar(unsigned char);
void unpack(unsigned const char *blkIN, int length, unsigned char *blkOUT) {
  int index = 0, i = 0;
  unsigned char upper = 0x00, lower = 0x00;
  for (i = 0; i < length; i++) {
    upper = (blkIN[i] & 0xF0) >> 4;
    lower = (blkIN[i] & 0x0F);
    blkOUT[index] = getUChar(upper);
    index++;
    blkOUT[index] = getUChar(lower);
    index++;
  }
}


x86 assembly (clang, -O0):
<unpack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
movb   $0x0,-0x22(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c1 <unpack+0xb1>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf0,%eax
sar    $0x4,%eax
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
mov    %al,-0x22(%rbp)
movzbl -0x21(%rbp),%edi
call   1030 <getUChar@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movzbl -0x22(%rbp),%edi
call   1030 <getUChar@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1140 <unpack+0x30>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unpack>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    115e <unpack+0x4e>
mov    %rdx,%r12
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%ebp
mov    %ebp,%eax
shr    $0x4,%al
movzbl %al,%edi
call   1030 <getUChar@plt>
mov    %al,(%r12,%rbx,2)
and    $0xf,%ebp
mov    %ebp,%edi
call   1030 <getUChar@plt>
mov    %al,0x1(%r12,%rbx,2)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <unpack+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @unpack(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
store i8 0, i8* %9
store i8 0, i8* %10
store i32 0, i32* %8
br label %11
11: ; preds = %49, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %52
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = and i32 %21, 240
%23 = ashr i32 %22, 4
%24 = trunc i32 %23 to i8
store i8 %24, i8* %9
%25 = load i8*, i8** %4
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = and i32 %30, 15
%32 = trunc i32 %31 to i8
store i8 %32, i8* %10
%33 = load i8, i8* %9
%34 = call zeroext i8 @getUChar(i8 zeroext %33)
%35 = load i8*, i8** %6
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
%41 = load i8, i8* %10
%42 = call zeroext i8 @getUChar(i8 zeroext %41)
%43 = load i8*, i8** %6
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %42, i8* %46
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %49
49: ; preds = %15
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %11
52: ; preds = %11
ret void
}

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