#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 *, char *);
void print_bits(unsigned char c) {
  char out[11];
  out[0] = '0';
  out[1] = 'b';
  for (int i = 7; i >= 0; i--) {
    out[2 + i] = (c >> (7 - i)) & 1 ? '1' : '0';
  }
  out[10] = '\0';
  printf("%s\n", out);
}


x86 assembly (clang, -O0):
<print_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movb   $0x30,-0xc(%rbp)
movb   $0x62,-0xb(%rbp)
movl   $0x7,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1174 <print_bits+0x64>
movzbl -0x1(%rbp),%edx
mov    $0x7,%ecx
sub    -0x10(%rbp),%ecx
sar    %cl,%edx
and    $0x1,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x10(%rbp),%eax
add    $0x2,%eax
cltq
mov    %cl,-0xc(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <print_bits+0x1d>
movb   $0x0,-0x2(%rbp)
lea    -0xc(%rbp),%rsi
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bits>:
sub    $0x18,%rsp
movw   $0x6230,0xd(%rsp)
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xed4(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xed8(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%esi
mov    %esi,%r10d
and    $0x2,%r10b
shr    %r10b
mov    %esi,%edi
and    $0x4,%dil
shr    $0x2,%dil
mov    %esi,%r8d
and    $0x8,%r8b
shr    $0x3,%r8b
mov    %esi,%r9d
and    $0x10,%r9b
shr    $0x4,%r9b
mov    %esi,%ecx
and    $0x20,%cl
shr    $0x5,%cl
mov    %esi,%edx
and    $0x40,%dl
shr    $0x6,%dl
mov    %esi,%eax
sar    $0x7,%al
add    $0x31,%al
mov    %al,0x16(%rsp)
xor    $0x31,%dl
mov    %dl,0x15(%rsp)
xor    $0x31,%cl
mov    %cl,0x14(%rsp)
xor    $0x31,%r9b
mov    %r9b,0x13(%rsp)
xor    $0x31,%r8b
mov    %r8b,0x12(%rsp)
xor    $0x31,%dil
mov    %dil,0x11(%rsp)
xor    $0x31,%r10b
mov    %r10b,0x10(%rsp)
and    $0x1,%sil
xor    $0x31,%sil
mov    %sil,0xf(%rsp)
movb   $0x0,0x17(%rsp)
lea    0xe40(%rip),%rdi
lea    0xd(%rsp),%rsi
call   1030 <printf@plt>
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @print_bits(i8 zeroext %0) {
%2 = alloca [11 x i8]
%3 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 0
store i8 48, i8* %3
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 1
store i8 98, i8* %4
%5 = zext i8 %0 to i32
%6 = insertelement <8 x i32> poison, i32 %5, i64 0
%7 = shufflevector <8 x i32> %6, <8 x i32> poison, <8 x i32> zeroinitializer
%8 = and <8 x i32> %7, <i32 128, i32 64, i32 32, i32 16, i32 8, i32 4, i32 2, i32 1>
%9 = icmp eq <8 x i32> %8, zeroinitializer
%10 = extractelement <8 x i1> %9, i64 7
%11 = select i1 %10, i8 48, i8 49
%12 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 9
store i8 %11, i8* %12
%13 = extractelement <8 x i1> %9, i64 6
%14 = select i1 %13, i8 48, i8 49
%15 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 8
store i8 %14, i8* %15
%16 = extractelement <8 x i1> %9, i64 5
%17 = select i1 %16, i8 48, i8 49
%18 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 7
store i8 %17, i8* %18
%19 = extractelement <8 x i1> %9, i64 4
%20 = select i1 %19, i8 48, i8 49
%21 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 6
store i8 %20, i8* %21
%22 = extractelement <8 x i1> %9, i64 3
%23 = select i1 %22, i8 48, i8 49
%24 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 5
store i8 %23, i8* %24
%25 = extractelement <8 x i1> %9, i64 2
%26 = select i1 %25, i8 48, i8 49
%27 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 4
store i8 %26, i8* %27
%28 = extractelement <8 x i1> %9, i64 1
%29 = select i1 %28, i8 48, i8 49
%30 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 3
store i8 %29, i8* %30
%31 = extractelement <8 x i1> %9, i64 0
%32 = select i1 %31, i8 48, i8 49
%33 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 2
store i8 %32, i8* %33
%34 = getelementptr inbounds [11 x i8], [11 x i8]* %2, i64 0, i64 10
store i8 0, i8* %34
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %3)
ret void
}