#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);
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] & (1 << j);
      byte >>= j;
      printf("%u", byte);
    }
  }
}


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     11a8 <printBits+0x98>
movl   $0x7,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1195 <printBits+0x85>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x24(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %al,-0x19(%rbp)
mov    -0x24(%rbp),%ecx
movzbl -0x19(%rbp),%eax
sar    %cl,%eax
mov    %al,-0x19(%rbp)
lea    0xe82(%rip),%rdi
movzbl -0x19(%rbp),%esi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1144 <printBits+0x34>
jmp    119a <printBits+0x8a>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1133 <printBits+0x23>
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     11ef <printBits+0xdf>
mov    %rsi,%r15
mov    %edi,%ebx
add    $0xffffffffffffffff,%rbx
lea    0xecf(%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   1030 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
shr    %esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl 0x1(%r15,%rbx,1),%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffffffffffff,%r12
test   $0x80000000,%ebx
mov    %r12,%rbx
je     1140 <printBits+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
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 = %42, %2
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %45
16: ; preds = %13
store i32 7, i32* %8
br label %17
17: ; preds = %38, %16
%18 = load i32, i32* %8
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %41
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 = shl i32 1, %27
%29 = and i32 %26, %28
%30 = trunc i32 %29 to i8
store i8 %30, i8* %6
%31 = load i32, i32* %8
%32 = load i8, i8* %6
%33 = zext i8 %32 to i32
%34 = ashr i32 %33, %31
%35 = trunc i32 %34 to i8
store i8 %35, i8* %6
%36 = load i8, i8* %6
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %36)
br label %38
38: ; preds = %20
%39 = load i32, i32* %8
%40 = add nsw i32 %39, -1
store i32 %40, i32* %8
br label %17
41: ; preds = %17
br label %42
42: ; preds = %41
%43 = load i32, i32* %7
%44 = add nsw i32 %43, -1
store i32 %44, i32* %7
br label %13
45: ; preds = %13
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
ret void
}