#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 */
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ getBits(char, unsigned char *);
scalar_t__ malloc(int);
void bufferToBits(char *buffer, size_t bufferSize, unsigned char *bitsToWrite,
                  size_t bitsSize) {
  unsigned char *tempChar =
      (unsigned char *)malloc(sizeof(unsigned char *) * 8);
  unsigned x, y, temp;
  temp = 0;
  for (y = 0; y < bufferSize; y++) {
    getBits(buffer[y], tempChar);
    for (x = 0; x < 8; x++) {
      bitsToWrite[temp] = tempChar[x];
      temp++;
    }
  }
  free(tempChar);
}


x86 assembly (clang, -O0):
<bufferToBits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    11d6 <bufferToBits+0xa6>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1040 <getBits@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x8,-0x2c(%rbp)
jae    11c3 <bufferToBits+0x93>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    118e <bufferToBits+0x5e>
jmp    11c8 <bufferToBits+0x98>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1164 <bufferToBits+0x34>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bufferToBits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x40,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %r14,%r14
je     11cf <bufferToBits+0x9f>
xor    %r13d,%r13d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%r13,1),%edi
mov    %rbx,%rsi
call   1040 <getBits@plt>
movzbl (%rbx),%eax
mov    %ebp,%ecx
mov    %al,(%r12,%rcx,1)
lea    0x1(%rbp),%eax
movzbl 0x1(%rbx),%ecx
mov    %cl,(%r12,%rax,1)
lea    0x2(%rbp),%eax
movzbl 0x2(%rbx),%ecx
mov    %cl,(%r12,%rax,1)
movzbl 0x3(%rbx),%eax
lea    0x3(%rbp),%ecx
mov    %al,(%r12,%rcx,1)
lea    0x4(%rbp),%eax
movzbl 0x4(%rbx),%ecx
mov    %cl,(%r12,%rax,1)
lea    0x5(%rbp),%eax
movzbl 0x5(%rbx),%ecx
mov    %cl,(%r12,%rax,1)
lea    0x6(%rbp),%eax
movzbl 0x6(%rbx),%ecx
mov    %cl,(%r12,%rax,1)
movzbl 0x7(%rbx),%eax
lea    0x7(%rbp),%ecx
mov    %al,(%r12,%rcx,1)
add    $0x8,%ebp
add    $0x1,%r13d
cmp    %r14,%r13
jb     1160 <bufferToBits+0x30>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
define void @bufferToBits(i8* nocapture %0, i64 %1, i8* nocapture writeonly %2, i64 %3) {
%5 = tail call i64 @malloc(i32 64)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %1, 0
br i1 %7, label %57, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = getelementptr inbounds i8, i8* %6, i64 2
%11 = getelementptr inbounds i8, i8* %6, i64 3
%12 = getelementptr inbounds i8, i8* %6, i64 4
%13 = getelementptr inbounds i8, i8* %6, i64 5
%14 = getelementptr inbounds i8, i8* %6, i64 6
%15 = getelementptr inbounds i8, i8* %6, i64 7
br label %16
16: ; preds = %8, %16
%17 = phi i64 [ %55, %16 ], [ 0, %8 ]
%18 = phi i32 [ %53, %16 ], [ 0, %8 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %17
%20 = load i8, i8* %19
%21 = tail call i32 @getBits(i8 signext %20, i8* %6)
%22 = load i8, i8* %6
%23 = zext i32 %18 to i64
%24 = getelementptr inbounds i8, i8* %2, i64 %23
store i8 %22, i8* %24
%25 = or i32 %18, 1
%26 = load i8, i8* %9
%27 = zext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %2, i64 %27
store i8 %26, i8* %28
%29 = or i32 %18, 2
%30 = load i8, i8* %10
%31 = zext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %2, i64 %31
store i8 %30, i8* %32
%33 = or i32 %18, 3
%34 = load i8, i8* %11
%35 = zext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %2, i64 %35
store i8 %34, i8* %36
%37 = or i32 %18, 4
%38 = load i8, i8* %12
%39 = zext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %2, i64 %39
store i8 %38, i8* %40
%41 = or i32 %18, 5
%42 = load i8, i8* %13
%43 = zext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %2, i64 %43
store i8 %42, i8* %44
%45 = or i32 %18, 6
%46 = load i8, i8* %14
%47 = zext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %2, i64 %47
store i8 %46, i8* %48
%49 = or i32 %18, 7
%50 = load i8, i8* %15
%51 = zext i32 %49 to i64
%52 = getelementptr inbounds i8, i8* %2, i64 %51
store i8 %50, i8* %52
%53 = add i32 %18, 8
%54 = add nuw nsw i64 %17, 1
%55 = and i64 %54, 4294967295
%56 = icmp ult i64 %55, %1
br i1 %56, label %16, label %57
57: ; preds = %16, %4
%58 = tail call i32 @free(i8* %6)
ret void
}