#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 NBBY;
int /*<<< orphan*/ flockfile(int /*<<< orphan*/);
int /*<<< orphan*/ funlockfile(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
void printvbin(const void *ptr, size_t len) {
  const unsigned char *p = ptr;
  size_t n;
  int i;
  flockfile(stdout);
  for (n = 0, p = ptr; n < len; p++, n++) {
    if (n && n % 8 == 0)
      printf("\n");
    for (i = 0; i < NBBY; i++)
      putchar((*p & (1 << i)) ? '1' : '0');
    if (n % 8 != 7 && n != len - 1)
      putchar(' ');
  }
  putchar('\n');
  funlockfile(stdout);
}


x86 assembly (clang, -O0):
<printvbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1060 <flockfile@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1252 <printvbin+0x112>
cmpq   $0x0,-0x20(%rbp)
je     11ad <printvbin+0x6d>
mov    -0x20(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    11ad <printvbin+0x6d>
lea    0xe58(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%eax
jge    11ff <printvbin+0xbf>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edx
mov    -0x24(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b4 <printvbin+0x74>
mov    -0x20(%rbp),%rax
and    $0x7,%rax
cmp    $0x7,%rax
je     1230 <printvbin+0xf0>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
je     1230 <printvbin+0xf0>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1235 <printvbin+0xf5>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1176 <printvbin+0x36>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
call   1040 <funlockfile@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printvbin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
call   1050 <flockfile@plt>
test   %rbp,%rbp
je     11e6 <printvbin+0xb6>
mov    %rbp,%r12
lea    -0x1(%rbp),%rax
mov    %rax,(%rsp)
xor    %r13d,%r13d
mov    0x2e7b(%rip),%rbp
jmp    117d <printvbin+0x4d>
nop
add    $0x1,%rbx
add    $0x1,%r13
cmp    %r12,%r13
je     11e6 <printvbin+0xb6>
mov    %r13d,%r15d
and    $0x7,%r15d
test   %r13,%r13
je     1198 <printvbin+0x68>
test   %r15,%r15
jne    1198 <printvbin+0x68>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,0x0(%rbp)
jle    11ce <printvbin+0x9e>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
bt     %r14d,%eax
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
add    $0x1,%r14d
cmp    0x0(%rbp),%r14d
jl     11b0 <printvbin+0x80>
cmp    (%rsp),%r13
je     1170 <printvbin+0x40>
cmp    $0x7,%r15d
je     1170 <printvbin+0x40>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1170 <printvbin+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <funlockfile@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [2 x i8] c"\0A\00"
@NBBY = global i32 0
define void @printvbin(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i32, i32* @stdout
%10 = call i32 @flockfile(i32 %9)
store i64 0, i64* %6
%11 = load i8*, i8** %3
store i8* %11, i8** %5
br label %12
12: ; preds = %57, %2
%13 = load i64, i64* %6
%14 = load i64, i64* %4
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %62
16: ; preds = %12
%17 = load i64, i64* %6
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i64, i64* %6
%21 = urem i64 %20, 8
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %19, %16
store i32 0, i32* %7
br label %26
26: ; preds = %42, %25
%27 = load i32, i32* %7
%28 = load i32, i32* @NBBY
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %45
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = load i32, i32* %7
%35 = shl i32 1, %34
%36 = and i32 %33, %35
%37 = icmp ne i32 %36, 0
%38 = zext i1 %37 to i64
%39 = select i1 %37, i32 49, i32 48
%40 = trunc i32 %39 to i8
%41 = call i32 @putchar(i8 signext %40)
br label %42
42: ; preds = %30
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %26
45: ; preds = %26
%46 = load i64, i64* %6
%47 = urem i64 %46, 8
%48 = icmp ne i64 %47, 7
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = load i64, i64* %6
%51 = load i64, i64* %4
%52 = sub i64 %51, 1
%53 = icmp ne i64 %50, %52
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @putchar(i8 signext 32)
br label %56
56: ; preds = %54, %49, %45
br label %57
57: ; preds = %56
%58 = load i8*, i8** %5
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %5
%60 = load i64, i64* %6
%61 = add i64 %60, 1
store i64 %61, i64* %6
br label %12
62: ; preds = %12
%63 = call i32 @putchar(i8 signext 10)
%64 = load i32, i32* @stdout
%65 = call i32 @funlockfile(i32 %64)
ret void
}

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