#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 *, ...);
void printBits(unsigned char *p, unsigned long count) {
  unsigned long j, i, byte;
  for (j = 0; j < count; j++) {
    byte = p[j];
    for (i = 0x80; i > 0; i /= 2)
      printf("%c", (byte & i) ? '1' : '0');
    printf("|");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printBits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b0 <printBits+0xa0>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %rax,-0x28(%rbp)
movq   $0x80,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    1191 <printBits+0x81>
mov    -0x28(%rbp),%rcx
and    -0x20(%rbp),%rcx
mov    $0x30,%esi
mov    $0x31,%eax
cmp    $0x0,%rcx
cmovne %eax,%esi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114e <printBits+0x3e>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <printBits+0x18>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBits>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     11f3 <printBits+0xe3>
mov    %rsi,%r15
mov    %rdi,%r14
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%r12,1),%ebx
mov    %ebx,%eax
and    $0xffffff80,%eax
cmp    $0x1,%rax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x40,%eax
cmp    $0x1,%rax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x20,%eax
cmp    $0x1,%rax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x10,%eax
cmp    $0x1,%rax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x8,%eax
cmp    $0x1,%rax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x4,%eax
cmp    $0x1,%rax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
and    $0x2,%eax
cmp    $0x1,%rax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
and    $0x1,%ebx
or     $0x30,%ebx
mov    %ebx,%edi
call   1030 <putchar@plt>
mov    $0x7c,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
cmp    %r12,%r15
jne    1130 <printBits+0x20>
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"%c\00"
@.str.1 = [2 x i8] c"|\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @printBits(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %5
br label %8
8: ; preds = %34, %2
%9 = load i64, i64* %5
%10 = load i64, i64* %4
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %37
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i64, i64* %5
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = zext i8 %16 to i64
store i64 %17, i64* %7
store i64 128, i64* %6
br label %18
18: ; preds = %29, %12
%19 = load i64, i64* %6
%20 = icmp ugt i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i64, i64* %7
%23 = load i64, i64* %6
%24 = and i64 %22, %23
%25 = icmp ne i64 %24, 0
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 49, i32 48
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %21
%30 = load i64, i64* %6
%31 = udiv i64 %30, 2
store i64 %31, i64* %6
br label %18
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32
%35 = load i64, i64* %5
%36 = add i64 %35, 1
store i64 %36, i64* %5
br label %8
37: ; preds = %8
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

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