#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprint_invalid(int /*<<< orphan*/ *, unsigned char *,
                                  unsigned char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void fprint_bit_string(FILE *f, unsigned char *p, unsigned char *e) {
  int b;
  unsigned char v, s;
  if (p >= e || (s = *p++) > 7) {
    fprint_invalid(f, p, e);
    return;
  }
  fprintf(f, "'");
  while (p < e)
    for (v = *p++, b = 8; b > 0 && (p != e || b > s); v >>= 1, b--)
      fprintf(f, "%d", (int)(v & 0x01));
  fprintf(f, "'B");
}


x86 assembly (clang, -O0):
<fprint_bit_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1162 <fprint_bit_string+0x42>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x1e(%rbp)
movzbl %al,%eax
cmp    $0x7,%eax
jle    1178 <fprint_bit_string+0x58>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <fprint_invalid@plt>
jmp    1242 <fprint_bit_string+0x122>
mov    -0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1230 <fprint_bit_string+0x110>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
movl   $0x8,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1f(%rbp)
jle    11ea <fprint_bit_string+0xca>
mov    -0x10(%rbp),%rcx
mov    $0x1,%al
cmp    -0x18(%rbp),%rcx
mov    %al,-0x20(%rbp)
jne    11e4 <fprint_bit_string+0xc4>
mov    -0x1c(%rbp),%eax
movzbl -0x1e(%rbp),%ecx
cmp    %ecx,%eax
setg   %al
mov    %al,-0x20(%rbp)
mov    -0x20(%rbp),%al
mov    %al,-0x1f(%rbp)
mov    -0x1f(%rbp),%al
test   $0x1,%al
jne    11fa <fprint_bit_string+0xda>
jmp    122b <fprint_bit_string+0x10b>
mov    -0x8(%rbp),%rdi
movzbl -0x1d(%rbp),%edx
and    $0x1,%edx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movzbl -0x1d(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x1d(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b3 <fprint_bit_string+0x93>
jmp    118a <fprint_bit_string+0x6a>
mov    -0x8(%rbp),%rdi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fprint_bit_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
cmp    %rdx,%rsi
jae    1169 <fprint_bit_string+0x29>
lea    0x1(%rbx),%rbp
mov    (%rbx),%r13b
cmp    $0x8,%r13b
jb     1185 <fprint_bit_string+0x45>
mov    %rbp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprint_invalid@plt>
mov    $0x27,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
cmp    %r15,%rbp
jae    12ff <fprint_bit_string+0x1bf>
lea    0x2(%rbx),%rbp
not    %rbx
add    %r15,%rbx
jmp    11ce <fprint_bit_string+0x8e>
shr    $0x7,%r12b
movzbl %r12b,%edx
mov    %r14,%rdi
lea    0xe47(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
je     12ff <fprint_bit_string+0x1bf>
movzbl -0x1(%rbp),%r12d
cmp    %r15,%rbp
jne    11de <fprint_bit_string+0x9e>
cmp    $0x7,%r13b
ja     11c0 <fprint_bit_string+0x80>
mov    %r12d,%edx
and    $0x1,%edx
mov    %r14,%rdi
lea    0xe12(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    %r15,%rbp
jne    1200 <fprint_bit_string+0xc0>
cmp    $0x6,%r13b
ja     11c0 <fprint_bit_string+0x80>
mov    %r12d,%edx
shr    %edx
and    $0x1,%edx
mov    %r14,%rdi
lea    0xdee(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    %r15,%rbp
jne    1224 <fprint_bit_string+0xe4>
cmp    $0x5,%r13b
ja     11c0 <fprint_bit_string+0x80>
mov    %r12d,%edx
shr    $0x2,%edx
and    $0x1,%edx
mov    %r14,%rdi
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    %r15,%rbp
jne    124d <fprint_bit_string+0x10d>
cmp    $0x4,%r13b
ja     11c0 <fprint_bit_string+0x80>
mov    %r12d,%edx
shr    $0x3,%edx
and    $0x1,%edx
mov    %r14,%rdi
lea    0xda0(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    %r15,%rbp
jne    1276 <fprint_bit_string+0x136>
cmp    $0x3,%r13b
ja     11c0 <fprint_bit_string+0x80>
mov    %r12d,%eax
shr    $0x4,%al
and    $0x1,%al
movzbl %al,%edx
mov    %r14,%rdi
lea    0xd75(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    %r15,%rbp
jne    12a1 <fprint_bit_string+0x161>
cmp    $0x2,%r13b
ja     11c0 <fprint_bit_string+0x80>
mov    %r12d,%eax
shr    $0x5,%al
and    $0x1,%al
movzbl %al,%edx
mov    %r14,%rdi
lea    0xd4a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    %r15,%rbp
jne    12cc <fprint_bit_string+0x18c>
cmp    $0x1,%r13b
ja     11c0 <fprint_bit_string+0x80>
mov    %r12d,%eax
shr    $0x6,%al
and    $0x1,%al
movzbl %al,%edx
mov    %r14,%rdi
lea    0xd1f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    %r15,%rbp
jne    11a7 <fprint_bit_string+0x67>
test   %r13b,%r13b
jne    11c0 <fprint_bit_string+0x80>
jmp    11a7 <fprint_bit_string+0x67>
lea    0xcfd(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fwrite@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"'\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"'B\00"
define void @fprint_bit_string(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = icmp uge i8* %10, %11
br i1 %12, label %19, label %13
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %5
%16 = load i8, i8* %14
store i8 %16, i8* %9
%17 = zext i8 %16 to i32
%18 = icmp sgt i32 %17, 7
br i1 %18, label %19, label %24
19: ; preds = %13, %3
%20 = load i32*, i32** %4
%21 = load i8*, i8** %5
%22 = load i8*, i8** %6
%23 = call i32 @fprint_invalid(i32* %20, i8* %21, i8* %22)
br label %68
24: ; preds = %13
%25 = load i32*, i32** %4
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %64, %24
%28 = load i8*, i8** %5
%29 = load i8*, i8** %6
%30 = icmp ult i8* %28, %29
br i1 %30, label %31, label %65
31: ; preds = %27
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
%34 = load i8, i8* %32
store i8 %34, i8* %8
store i32 8, i32* %7
br label %35
35: ; preds = %57, %31
%36 = load i32, i32* %7
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %35
%39 = load i8*, i8** %5
%40 = load i8*, i8** %6
%41 = icmp ne i8* %39, %40
br i1 %41, label %47, label %42
42: ; preds = %38
%43 = load i32, i32* %7
%44 = load i8, i8* %9
%45 = zext i8 %44 to i32
%46 = icmp sgt i32 %43, %45
br label %47
47: ; preds = %42, %38
%48 = phi i1 [ true, %38 ], [ %46, %42 ]
br label %49
49: ; preds = %47, %35
%50 = phi i1 [ false, %35 ], [ %48, %47 ]
br i1 %50, label %51, label %64
51: ; preds = %49
%52 = load i32*, i32** %4
%53 = load i8, i8* %8
%54 = zext i8 %53 to i32
%55 = and i32 %54, 1
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %51
%58 = load i8, i8* %8
%59 = zext i8 %58 to i32
%60 = ashr i32 %59, 1
%61 = trunc i32 %60 to i8
store i8 %61, i8* %8
%62 = load i32, i32* %7
%63 = add nsw i32 %62, -1
store i32 %63, i32* %7
br label %35
64: ; preds = %49
br label %27
65: ; preds = %27
%66 = load i32*, i32** %4
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %68
68: ; preds = %65, %19
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"'B\00"
define void @fprint_bit_string(i32* %0, i8* %1, i8* %2) {
%4 = ptrtoint i8* %1 to i64
%5 = ptrtoint i8* %2 to i64
%6 = icmp ult i8* %1, %2
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %1, i64 1
%9 = load i8, i8* %1
%10 = icmp ugt i8 %9, 7
br i1 %10, label %11, label %14
11: ; preds = %7, %3
%12 = phi i8* [ %1, %3 ], [ %8, %7 ]
%13 = tail call i32 @fprint_invalid(i32* %0, i8* %12, i8* %2)
br label %83
14: ; preds = %7
%15 = tail call i32 @fputc(i32 39, i32* %0)
%16 = icmp ult i8* %8, %2
br i1 %16, label %17, label %81
17: ; preds = %14
%18 = sub i64 %5, %4
%19 = getelementptr i8, i8* %1, i64 %18
%20 = icmp ult i8 %9, 8
%21 = icmp ult i8 %9, 7
%22 = icmp ult i8 %9, 6
%23 = icmp ult i8 %9, 5
%24 = icmp ult i8 %9, 4
%25 = icmp ult i8 %9, 3
%26 = icmp ult i8 %9, 2
%27 = icmp eq i8 %9, 0
br label %28
28: ; preds = %17, %79
%29 = phi i8* [ %30, %79 ], [ %8, %17 ]
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %29
%32 = icmp ne i8* %30, %2
%33 = select i1 %32, i1 true, i1 %20
br i1 %33, label %34, label %79
34: ; preds = %28
%35 = and i8 %31, 1
%36 = zext i8 %35 to i32
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = select i1 %32, i1 true, i1 %21
br i1 %38, label %39, label %79
39: ; preds = %34
%40 = lshr i8 %31, 1
%41 = and i8 %40, 1
%42 = zext i8 %41 to i32
%43 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = select i1 %32, i1 true, i1 %22
br i1 %44, label %45, label %79
45: ; preds = %39
%46 = lshr i8 %31, 2
%47 = and i8 %46, 1
%48 = zext i8 %47 to i32
%49 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = select i1 %32, i1 true, i1 %23
br i1 %50, label %51, label %79
51: ; preds = %45
%52 = lshr i8 %31, 3
%53 = and i8 %52, 1
%54 = zext i8 %53 to i32
%55 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = select i1 %32, i1 true, i1 %24
br i1 %56, label %57, label %79
57: ; preds = %51
%58 = lshr i8 %31, 4
%59 = and i8 %58, 1
%60 = zext i8 %59 to i32
%61 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %60)
%62 = select i1 %32, i1 true, i1 %25
br i1 %62, label %63, label %79
63: ; preds = %57
%64 = lshr i8 %31, 5
%65 = and i8 %64, 1
%66 = zext i8 %65 to i32
%67 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %66)
%68 = select i1 %32, i1 true, i1 %26
br i1 %68, label %69, label %79
69: ; preds = %63
%70 = lshr i8 %31, 6
%71 = and i8 %70, 1
%72 = zext i8 %71 to i32
%73 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %72)
%74 = select i1 %32, i1 true, i1 %27
br i1 %74, label %75, label %79
75: ; preds = %69
%76 = lshr i8 %31, 7
%77 = zext i8 %76 to i32
%78 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %77)
br label %79
79: ; preds = %75, %69, %63, %57, %51, %45, %39, %34, %28
%80 = icmp eq i8* %30, %19
br i1 %80, label %81, label %28
81: ; preds = %79, %14
%82 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %0)
br label %83
83: ; preds = %81, %11
ret void
}