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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
void byteBaseBinaryPut(FILE *fd, unsigned char byte) {
  char bits[(sizeof(byte) * 8) + 1];
  char *p;
  for (*(p = bits + sizeof(bits) - 1) = '\0'; p-- != bits; byte >>= 1) {
    *p = '0' + (byte & 0x01);
  }
  fprintf(fd, "%s", bits);
}


x86 assembly (clang, -O0):
<byteBaseBinaryPut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
lea    -0x12(%rbp),%rax
add    $0x9,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
movb   $0x0,-0xa(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
lea    -0x12(%rbp),%rcx
cmp    %rcx,%rax
je     1173 <byteBaseBinaryPut+0x63>
movzbl -0x9(%rbp),%eax
and    $0x1,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
movzbl -0x9(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x9(%rbp)
jmp    1136 <byteBaseBinaryPut+0x26>
mov    -0x8(%rbp),%rdi
lea    -0x12(%rbp),%rdx
lea    0xe7e(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byteBaseBinaryPut>:
sub    $0x18,%rsp
mov    %rdi,%rax
movb   $0x0,0x17(%rsp)
mov    %esi,%ecx
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x16(%rsp)
mov    %esi,%ecx
shr    %cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x15(%rsp)
mov    %esi,%ecx
shr    $0x2,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x14(%rsp)
mov    %esi,%ecx
shr    $0x3,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x13(%rsp)
mov    %esi,%ecx
shr    $0x4,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x12(%rsp)
mov    %esi,%ecx
shr    $0x5,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x11(%rsp)
mov    %esi,%ecx
shr    $0x6,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x10(%rsp)
shr    $0x7,%sil
or     $0x30,%sil
mov    %sil,0xf(%rsp)
lea    0xf(%rsp),%rdi
mov    %rax,%rsi
call   1030 <fputs@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define void @byteBaseBinaryPut(i32* %0, i8 zeroext %1) {
%3 = alloca i32*
%4 = alloca i8
%5 = alloca [9 x i8]
%6 = alloca i8*
store i32* %0, i32** %3
store i8 %1, i8* %4
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds i8, i8* %7, i64 9
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %6
store i8 0, i8* %9
br label %10
10: ; preds = %22, %2
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i32 -1
store i8* %12, i8** %6
%13 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%14 = icmp ne i8* %11, %13
br i1 %14, label %15, label %27
15: ; preds = %10
%16 = load i8, i8* %4
%17 = zext i8 %16 to i32
%18 = and i32 %17, 1
%19 = add nsw i32 48, %18
%20 = trunc i32 %19 to i8
%21 = load i8*, i8** %6
store i8 %20, i8* %21
br label %22
22: ; preds = %15
%23 = load i8, i8* %4
%24 = zext i8 %23 to i32
%25 = ashr i32 %24, 1
%26 = trunc i32 %25 to i8
store i8 %26, i8* %4
br label %10
27: ; preds = %10
%28 = load i32*, i32** %3
%29 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%30 = call i32 @fprintf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %29)
ret void
}

LLVM IR (-O2):
define void @byteBaseBinaryPut(i32* nocapture %0, i8 zeroext %1) {
%3 = alloca [9 x i8]
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 8
store i8 0, i8* %5
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 7
%7 = and i8 %1, 1
%8 = or i8 %7, 48
store i8 %8, i8* %6
%9 = lshr i8 %1, 1
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 6
%11 = and i8 %9, 1
%12 = or i8 %11, 48
store i8 %12, i8* %10
%13 = lshr i8 %1, 2
%14 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 5
%15 = and i8 %13, 1
%16 = or i8 %15, 48
store i8 %16, i8* %14
%17 = lshr i8 %1, 3
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 4
%19 = and i8 %17, 1
%20 = or i8 %19, 48
store i8 %20, i8* %18
%21 = lshr i8 %1, 4
%22 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 3
%23 = and i8 %21, 1
%24 = or i8 %23, 48
store i8 %24, i8* %22
%25 = lshr i8 %1, 5
%26 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 2
%27 = and i8 %25, 1
%28 = or i8 %27, 48
store i8 %28, i8* %26
%29 = lshr i8 %1, 6
%30 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 1
%31 = and i8 %29, 1
%32 = or i8 %31, 48
store i8 %32, i8* %30
%33 = lshr i8 %1, 7
%34 = getelementptr inbounds [9 x i8], [9 x i8]* %3, i64 0, i64 0
%35 = or i8 %33, 48
store i8 %35, i8* %34
%36 = call i32 @fputs(i8* %4, i32* %0)
ret void
}