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


x86 assembly (clang, -O0):
<printvbinr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
call   1060 <flockfile@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1252 <printvbinr+0x112>
cmpq   $0x0,-0x20(%rbp)
je     11ad <printvbinr+0x6d>
mov    -0x20(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    11ad <printvbinr+0x6d>
lea    0xe58(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11ff <printvbinr+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    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11bc <printvbinr+0x7c>
mov    -0x20(%rbp),%rax
and    $0x7,%rax
cmp    $0x7,%rax
je     1230 <printvbinr+0xf0>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
je     1230 <printvbinr+0xf0>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1235 <printvbinr+0xf5>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1176 <printvbinr+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):
<printvbinr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
call   1050 <flockfile@plt>
test   %r14,%r14
je     11e8 <printvbinr+0xb8>
add    %r14,%rbx
lea    -0x1(%r14),%r12
xor    %r13d,%r13d
jmp    1179 <printvbinr+0x49>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13
cmp    %r14,%r13
je     11e8 <printvbinr+0xb8>
mov    %r13d,%r15d
and    $0x7,%r15d
test   %r13,%r13
je     1194 <printvbinr+0x64>
test   %r15,%r15
jne    1194 <printvbinr+0x64>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
mov    0x2e49(%rip),%rax
mov    (%rax),%ebp
test   %ebp,%ebp
jle    11d1 <printvbinr+0xa1>
add    $0x1,%ebp
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
lea    -0x2(%rbp),%ecx
movzbl %cl,%ecx
bt     %ecx,%eax
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     11b0 <printvbinr+0x80>
cmp    %r12,%r13
je     1170 <printvbinr+0x40>
cmp    $0x7,%r15d
je     1170 <printvbinr+0x40>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1170 <printvbinr+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2ddf(%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 @printvbinr(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 i32, i32* @stdout
%9 = call i32 @flockfile(i32 %8)
store i64 0, i64* %6
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = getelementptr inbounds i8, i8* %10, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
store i8* %13, i8** %5
br label %14
14: ; preds = %60, %2
%15 = load i64, i64* %6
%16 = load i64, i64* %4
%17 = icmp ult i64 %15, %16
br i1 %17, label %18, label %65
18: ; preds = %14
%19 = load i64, i64* %6
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i64, i64* %6
%23 = urem i64 %22, 8
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %21, %18
%28 = load i32, i32* @NBBY
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %7
br label %30
30: ; preds = %45, %27
%31 = load i32, i32* %7
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %48
33: ; preds = %30
%34 = load i8*, i8** %5
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = load i32, i32* %7
%38 = shl i32 1, %37
%39 = and i32 %36, %38
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 49, i32 48
%43 = trunc i32 %42 to i8
%44 = call i32 @putchar(i8 signext %43)
br label %45
45: ; preds = %33
%46 = load i32, i32* %7
%47 = add nsw i32 %46, -1
store i32 %47, i32* %7
br label %30
48: ; preds = %30
%49 = load i64, i64* %6
%50 = urem i64 %49, 8
%51 = icmp ne i64 %50, 7
br i1 %51, label %52, label %59
52: ; preds = %48
%53 = load i64, i64* %6
%54 = load i64, i64* %4
%55 = sub i64 %54, 1
%56 = icmp ne i64 %53, %55
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 @putchar(i8 signext 32)
br label %59
59: ; preds = %57, %52, %48
br label %60
60: ; preds = %59
%61 = load i8*, i8** %5
%62 = getelementptr inbounds i8, i8* %61, i32 -1
store i8* %62, i8** %5
%63 = load i64, i64* %6
%64 = add i64 %63, 1
store i64 %64, i64* %6
br label %14
65: ; preds = %14
%66 = call i32 @putchar(i8 signext 10)
%67 = load i32, i32* @stdout
%68 = call i32 @funlockfile(i32 %67)
ret void
}

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