#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 *calloc(size_t, int);
scalar_t__ nibble_to_hamming(unsigned char);
unsigned char *data_to_hamming(unsigned char *data, size_t length) {
  size_t i;
  unsigned char *hamming = calloc(length * 2, sizeof(char));
  for (i = 0; i < length; i++) {
    hamming[2 * i] = (unsigned char)nibble_to_hamming(data[i] >> 4);
    hamming[2 * i + 1] = (unsigned char)nibble_to_hamming(data[i] & 0x0f);
  }
  return hamming;
}


x86 assembly (clang, -O0):
<data_to_hamming>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x1,%rdi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11be <data_to_hamming+0x9e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
sar    $0x4,%eax
movzbl %al,%edi
call   1040 <nibble_to_hamming@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
and    $0xf,%eax
movzbl %al,%edi
call   1040 <nibble_to_hamming@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114e <data_to_hamming+0x2e>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_to_hamming>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    (%rsi,%rsi,1),%rdi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%r12
test   %r14,%r14
je     117f <data_to_hamming+0x5f>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
shr    $0x4,%al
movzbl %al,%edi
call   1040 <nibble_to_hamming@plt>
mov    %al,(%r12,%rbx,2)
movzbl (%r15,%rbx,1),%edi
and    $0xf,%edi
call   1040 <nibble_to_hamming@plt>
mov    %al,0x1(%r12,%rbx,2)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <data_to_hamming+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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