#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 */
void byte_array_to_bit_array(uint8_t *byte_array, size_t size,
                             uint8_t *bit_array) {
  int i;
  for (i = 0; i < size; i++) {
    uint8_t t = byte_array[i];
    int j;
    for (j = 8 * i + 7; j >= 8 * i; j--) {
      bit_array[j] = t & 1;
      t >>= 1;
    }
  }
}


x86 assembly (clang, -O0):
<byte_array_to_bit_array>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118b <byte_array_to_bit_array+0x8b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
add    $0x7,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x1c(%rbp),%ecx
shl    $0x3,%ecx
cmp    %ecx,%eax
jl     1178 <byte_array_to_bit_array+0x78>
mov    -0x20(%rbp),%edx
and    $0x1,%edx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    113f <byte_array_to_bit_array+0x3f>
jmp    117d <byte_array_to_bit_array+0x7d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <byte_array_to_bit_array+0x17>
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_array_to_bit_array>:
test   %rsi,%rsi
je     1195 <byte_array_to_bit_array+0x95>
mov    $0x7,%eax
xor    %r8d,%r8d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cltq
mov    (%rdi,%r8,4),%r9d
mov    %r9d,%ecx
and    $0x1,%ecx
mov    %ecx,(%rdx,%rax,4)
mov    %r9d,%ecx
shr    %ecx
and    $0x1,%ecx
mov    %ecx,-0x4(%rdx,%rax,4)
mov    %r9d,%ecx
shr    $0x2,%ecx
and    $0x1,%ecx
mov    %ecx,-0x8(%rdx,%rax,4)
mov    %r9d,%ecx
shr    $0x3,%ecx
and    $0x1,%ecx
mov    %ecx,-0xc(%rdx,%rax,4)
mov    %r9d,%ecx
shr    $0x4,%ecx
and    $0x1,%ecx
mov    %ecx,-0x10(%rdx,%rax,4)
mov    %r9d,%ecx
shr    $0x5,%ecx
and    $0x1,%ecx
mov    %ecx,-0x14(%rdx,%rax,4)
mov    %r9d,%ecx
shr    $0x6,%ecx
and    $0x1,%ecx
mov    %ecx,-0x18(%rdx,%rax,4)
shr    $0x7,%r9d
and    $0x1,%r9d
mov    %r9d,-0x1c(%rdx,%rax,4)
add    $0x1,%r8
add    $0x8,%eax
cmp    %r8,%rsi
jne    1120 <byte_array_to_bit_array+0x20>
ret

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

LLVM IR (-O2):
define void @byte_array_to_bit_array(i32* nocapture %0, i64 %1, i32* nocapture writeonly %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %45, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %42, %5 ], [ 0, %3 ]
%7 = phi i32 [ %43, %5 ], [ 0, %3 ]
%8 = or i32 %7, 7
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %6
%11 = load i32, i32* %10
%12 = and i32 %11, 1
%13 = getelementptr inbounds i32, i32* %2, i64 %9
store i32 %12, i32* %13
%14 = lshr i32 %11, 1
%15 = add nsw i64 %9, -1
%16 = and i32 %14, 1
%17 = getelementptr inbounds i32, i32* %2, i64 %15
store i32 %16, i32* %17
%18 = lshr i32 %11, 2
%19 = add nsw i64 %9, -2
%20 = and i32 %18, 1
%21 = getelementptr inbounds i32, i32* %2, i64 %19
store i32 %20, i32* %21
%22 = lshr i32 %11, 3
%23 = add nsw i64 %9, -3
%24 = and i32 %22, 1
%25 = getelementptr inbounds i32, i32* %2, i64 %23
store i32 %24, i32* %25
%26 = lshr i32 %11, 4
%27 = add nsw i64 %9, -4
%28 = and i32 %26, 1
%29 = getelementptr inbounds i32, i32* %2, i64 %27
store i32 %28, i32* %29
%30 = lshr i32 %11, 5
%31 = add nsw i64 %9, -5
%32 = and i32 %30, 1
%33 = getelementptr inbounds i32, i32* %2, i64 %31
store i32 %32, i32* %33
%34 = lshr i32 %11, 6
%35 = add nsw i64 %9, -6
%36 = and i32 %34, 1
%37 = getelementptr inbounds i32, i32* %2, i64 %35
store i32 %36, i32* %37
%38 = lshr i32 %11, 7
%39 = add nsw i64 %9, -7
%40 = and i32 %38, 1
%41 = getelementptr inbounds i32, i32* %2, i64 %39
store i32 %40, i32* %41
%42 = add nuw nsw i64 %6, 1
%43 = add i32 %7, 8
%44 = icmp eq i64 %42, %1
br i1 %44, label %45, label %5
45: ; preds = %5, %3
ret void
}