#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 */
void BitStream_writeBytes(unsigned char *dest, size_t size,
                          unsigned char *data) {
  unsigned char mask;
  size_t i, j;
  unsigned char *p;
  p = dest;
  for (i = 0; i < size; i++) {
    mask = 0x80;
    for (j = 0; j < 8; j++) {
      if (data[i] & mask) {
        *p = 1;
      } else {
        *p = 0;
      }
      p++;
      mask = mask >> 1;
    }
  }
}


x86 assembly (clang, -O0):
<BitStream_writeBytes>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b0 <BitStream_writeBytes+0xb0>
movb   $0x80,-0x19(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x8,-0x30(%rbp)
jae    119a <BitStream_writeBytes+0x9a>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
movzbl -0x19(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     116c <BitStream_writeBytes+0x6c>
mov    -0x38(%rbp),%rax
movb   $0x1,(%rax)
jmp    1173 <BitStream_writeBytes+0x73>
mov    -0x38(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
movzbl -0x19(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x19(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    113a <BitStream_writeBytes+0x3a>
jmp    119f <BitStream_writeBytes+0x9f>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1120 <BitStream_writeBytes+0x20>
pop    %rbp
ret

x86 assembly (clang, -O2):
<BitStream_writeBytes>:
test   %rsi,%rsi
je     1181 <BitStream_writeBytes+0x81>
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
movzbl (%rdx,%rax,1),%ecx
shr    $0x7,%cl
mov    %cl,(%rdi,%rax,8)
movzbl (%rdx,%rax,1),%ecx
shr    $0x6,%cl
and    $0x1,%cl
mov    %cl,0x1(%rdi,%rax,8)
movzbl (%rdx,%rax,1),%ecx
shr    $0x5,%cl
and    $0x1,%cl
mov    %cl,0x2(%rdi,%rax,8)
movzbl (%rdx,%rax,1),%ecx
shr    $0x4,%cl
and    $0x1,%cl
mov    %cl,0x3(%rdi,%rax,8)
movzbl (%rdx,%rax,1),%ecx
shr    $0x3,%cl
and    $0x1,%cl
mov    %cl,0x4(%rdi,%rax,8)
movzbl (%rdx,%rax,1),%ecx
shr    $0x2,%cl
and    $0x1,%cl
mov    %cl,0x5(%rdi,%rax,8)
movzbl (%rdx,%rax,1),%ecx
shr    %cl
and    $0x1,%cl
mov    %cl,0x6(%rdi,%rax,8)
movzbl (%rdx,%rax,1),%ecx
and    $0x1,%cl
mov    %cl,0x7(%rdi,%rax,8)
add    $0x1,%rax
cmp    %rax,%rsi
jne    1110 <BitStream_writeBytes+0x10>
ret

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

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