#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 */
int ascii_to_nibble(char);
void fill_bin_buffer(char *source, uint8_t *dest, int ascii_count) {
  for (int i = 0; i < ascii_count; ++i) {
    if (i % 2 == 0) {
      dest[i / 2] = ascii_to_nibble(source[i]) << 4;
    } else {
      dest[i / 2] += ascii_to_nibble(source[i]);
    }
  }
}


x86 assembly (clang, -O0):
<fill_bin_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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    11d4 <fill_bin_buffer+0xc4>
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1188 <fill_bin_buffer+0x78>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <ascii_to_nibble@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11c1 <fill_bin_buffer+0xb1>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <ascii_to_nibble@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
jmp    11c6 <fill_bin_buffer+0xb6>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <fill_bin_buffer+0x1a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_bin_buffer>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    115f <fill_bin_buffer+0x4f>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%r12d
xor    %ebx,%ebx
jmp    1142 <fill_bin_buffer+0x32>
nopl   0x0(%rax)
mov    %ebx,%ecx
and    $0xfffffffe,%ecx
add    %eax,(%r14,%rcx,2)
add    $0x1,%rbx
cmp    %rbx,%r12
je     115f <fill_bin_buffer+0x4f>
movsbl (%r15,%rbx,1),%edi
call   1030 <ascii_to_nibble@plt>
test   $0x1,%bl
jne    1130 <fill_bin_buffer+0x20>
shl    $0x4,%eax
mov    %ebx,%ecx
and    $0xfffffffe,%ecx
mov    %eax,(%r14,%rcx,2)
jmp    1139 <fill_bin_buffer+0x29>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @fill_bin_buffer(i8* nocapture %0, i32* nocapture %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 = %26, %3
ret void
8: ; preds = %5, %26
%9 = phi i64 [ 0, %5 ], [ %27, %26 ]
%10 = and i64 %9, 1
%11 = icmp eq i64 %10, 0
%12 = getelementptr inbounds i8, i8* %0, i64 %9
%13 = load i8, i8* %12
%14 = tail call i32 @ascii_to_nibble(i8 signext %13)
br i1 %11, label %15, label %20
15: ; preds = %8
%16 = shl i32 %14, 4
%17 = lshr i64 %9, 1
%18 = and i64 %17, 2147483647
%19 = getelementptr inbounds i32, i32* %1, i64 %18
store i32 %16, i32* %19
br label %26
20: ; preds = %8
%21 = lshr i64 %9, 1
%22 = and i64 %21, 2147483647
%23 = getelementptr inbounds i32, i32* %1, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %24, %14
store i32 %25, i32* %23
br label %26
26: ; preds = %15, %20
%27 = add nuw nsw i64 %9, 1
%28 = icmp eq i64 %27, %6
br i1 %28, label %7, label %8
}