#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*/ printf(char *, unsigned char);
int /*<<< orphan*/ puts(char *);
void printBits(size_t const size, void const *const ptr) {
  unsigned char *b = (unsigned char *)ptr;
  unsigned char byte;
  int i, j;
  for (i = size - 1; i >= 0; i--) {
    for (j = 7; j >= 0; j--) {
      byte = (b[i] >> j) & 1;
      printf("%u", byte);
    }
  }
  puts("");
}


x86 assembly (clang, -O0):
<printBits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     11a6 <printBits+0x86>
movl   $0x7,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1193 <printBits+0x73>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x24(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %al,-0x19(%rbp)
lea    0xe84(%rip),%rdi
movzbl -0x19(%rbp),%esi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1154 <printBits+0x34>
jmp    1198 <printBits+0x78>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1143 <printBits+0x23>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBits>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
add    $0xffffffff,%edi
js     11ff <printBits+0xdf>
mov    %rsi,%r15
mov    %edi,%ebx
add    $0xffffffffffffffff,%rbx
lea    0xebf(%rip),%r14
mov    %rbx,%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x1(%r15,%rbx,1),%eax
shr    $0x7,%al
movzbl %al,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    %esi
and    $0x1,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%r12
test   $0x80000000,%ebx
mov    %r12,%rbx
je     1150 <printBits+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [1 x i8] zeroinitializer
define void @printBits(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i64 %0, i64* %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
store i8* %9, i8** %5
%10 = load i64, i64* %3
%11 = sub i64 %10, 1
%12 = trunc i64 %11 to i32
store i32 %12, i32* %7
br label %13
13: ; preds = %37, %2
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %40
16: ; preds = %13
store i32 7, i32* %8
br label %17
17: ; preds = %33, %16
%18 = load i32, i32* %8
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i8*, i8** %5
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = load i32, i32* %8
%28 = ashr i32 %26, %27
%29 = and i32 %28, 1
%30 = trunc i32 %29 to i8
store i8 %30, i8* %6
%31 = load i8, i8* %6
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %31)
br label %33
33: ; preds = %20
%34 = load i32, i32* %8
%35 = add nsw i32 %34, -1
store i32 %35, i32* %8
br label %17
36: ; preds = %17
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add nsw i32 %38, -1
store i32 %39, i32* %7
br label %13
40: ; preds = %13
%41 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
define void @printBits(i64 %0, i8* nocapture %1) {
%3 = trunc i64 %0 to i32
%4 = add i32 %3, -1
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %44
6: ; preds = %2
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %7, %6 ], [ %41, %8 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = lshr i8 %11, 7
%13 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %12)
%14 = load i8, i8* %10
%15 = lshr i8 %14, 6
%16 = and i8 %15, 1
%17 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %16)
%18 = load i8, i8* %10
%19 = lshr i8 %18, 5
%20 = and i8 %19, 1
%21 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %20)
%22 = load i8, i8* %10
%23 = lshr i8 %22, 4
%24 = and i8 %23, 1
%25 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
%26 = load i8, i8* %10
%27 = lshr i8 %26, 3
%28 = and i8 %27, 1
%29 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %28)
%30 = load i8, i8* %10
%31 = lshr i8 %30, 2
%32 = and i8 %31, 1
%33 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %32)
%34 = load i8, i8* %10
%35 = lshr i8 %34, 1
%36 = and i8 %35, 1
%37 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %36)
%38 = load i8, i8* %10
%39 = and i8 %38, 1
%40 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %39)
%41 = add nsw i64 %9, -1
%42 = and i64 %41, 2147483648
%43 = icmp eq i64 %42, 0
br i1 %43, label %8, label %44
44: ; preds = %8, %2
%45 = tail call i32 @putchar(i32 10)
ret void
}