#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 *, ...);
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] & (1 << j);
      byte >>= j;
      if (j == 3)
        printf(" ");
      if (j == 7)
        printf("  ");
      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     11ea <printBits+0xca>
movl   $0x7,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11d7 <printBits+0xb7>
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)
cmpl   $0x3,-0x24(%rbp)
jne    119f <printBits+0x7f>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x7,-0x24(%rbp)
jne    11b7 <printBits+0x97>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movzbl -0x19(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1154 <printBits+0x34>
jmp    11dc <printBits+0xbc>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1143 <printBits+0x23>
lea    0xe11(%rip),%rdi
call   1030 <puts@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
add    $0xffffffff,%edi
js     1224 <printBits+0x104>
mov    %rsi,%r12
mov    %edi,%ebx
add    $0xffffffffffffffff,%rbx
lea    0xebc(%rip),%r14
lea    0xeb8(%rip),%r15
mov    %rbx,%r13
xchg   %ax,%ax
movzbl 0x1(%r12,%rbx,1),%ebp
shr    $0x7,%ebp
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%r12,%rbx,1),%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%r12,%rbx,1),%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%r12,%rbx,1),%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%r12,%rbx,1),%ebp
shr    $0x3,%ebp
and    $0x1,%ebp
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%r12,%rbx,1),%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%r12,%rbx,1),%esi
shr    %esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x1(%r12,%rbx,1),%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%r13
test   $0x80000000,%ebx
mov    %r13,%rbx
je     1150 <printBits+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c" \00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [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 = %53, %2
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %56
16: ; preds = %13
store i32 7, i32* %8
br label %17
17: ; preds = %49, %16
%18 = load i32, i32* %8
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %52
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 i32, i32* %8
%37 = icmp eq i32 %36, 3
br i1 %37, label %38, label %40
38: ; preds = %20
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %38, %20
%41 = load i32, i32* %8
%42 = icmp eq i32 %41, 7
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %43, %40
%46 = load i8, i8* %6
%47 = zext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %45
%50 = load i32, i32* %8
%51 = add nsw i32 %50, -1
store i32 %51, i32* %8
br label %17
52: ; preds = %17
br label %53
53: ; preds = %52
%54 = load i32, i32* %7
%55 = add nsw i32 %54, -1
store i32 %55, i32* %7
br label %13
56: ; preds = %13
%57 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c" \00"
@.str.2 = [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 %54
6: ; preds = %2
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %7, %6 ], [ %51, %8 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = lshr i8 %11, 7
%13 = zext i8 %12 to i32
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%16 = load i8, i8* %10
%17 = lshr i8 %16, 6
%18 = and i8 %17, 1
%19 = zext i8 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i8, i8* %10
%22 = lshr i8 %21, 5
%23 = and i8 %22, 1
%24 = zext i8 %23 to i32
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i8, i8* %10
%27 = lshr i8 %26, 4
%28 = and i8 %27, 1
%29 = zext i8 %28 to i32
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i8, i8* %10
%32 = lshr i8 %31, 3
%33 = and i8 %32, 1
%34 = zext i8 %33 to i32
%35 = tail call i32 @putchar(i32 32)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%37 = load i8, i8* %10
%38 = lshr i8 %37, 2
%39 = and i8 %38, 1
%40 = zext i8 %39 to i32
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = load i8, i8* %10
%43 = lshr i8 %42, 1
%44 = and i8 %43, 1
%45 = zext i8 %44 to i32
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i8, i8* %10
%48 = and i8 %47, 1
%49 = zext i8 %48 to i32
%50 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = add nsw i64 %9, -1
%52 = and i64 %51, 2147483648
%53 = icmp eq i64 %52, 0
br i1 %53, label %8, label %54
54: ; preds = %8, %2
%55 = tail call i32 @putchar(i32 10)
ret void
}