#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*/ x;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
void print_bits(unsigned char x) {
  int i;
  printf("0b");
  for (i = 8 * sizeof(x) - 1; i >= 0; i--) {
    (x & (1 << i)) ? putchar('1') : putchar('0');
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
lea    0xecb(%rip),%rdi
call   1040 <printf@plt>
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     118d <print_bits+0x6d>
movzbl -0x1(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1175 <print_bits+0x55>
mov    $0x31,%edi
call   1030 <putchar@plt>
jmp    117f <print_bits+0x5f>
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1141 <print_bits+0x21>
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0xeec(%rip),%rdi
call   1040 <printf@plt>
movd   %ebx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeb6(%rip),%xmm1
pand   %xmm0,%xmm1
pand   0xeba(%rip),%xmm0
pxor   %xmm2,%xmm2
pcmpeqd %xmm2,%xmm0
pcmpeqd %xmm2,%xmm1
packssdw %xmm0,%xmm1
packsswb %xmm1,%xmm1
pmovmskb %xmm1,%ebx
mov    %ebx,%eax
and    $0x2,%al
shr    %al
mov    %al,0x7(%rsp)
mov    %ebx,%r14d
and    $0x4,%r14b
shr    $0x2,%r14b
mov    %ebx,%r15d
and    $0x8,%r15b
shr    $0x3,%r15b
mov    %ebx,%r12d
and    $0x10,%r12b
shr    $0x4,%r12b
mov    %ebx,%r13d
and    $0x20,%r13b
shr    $0x5,%r13b
mov    %ebx,%ebp
and    $0x40,%bpl
shr    $0x6,%bpl
mov    %ebx,%eax
shr    $0x7,%al
movzbl %al,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %bpl,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %r13b,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %r12b,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %r15b,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl %r14b,%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
movzbl 0x7(%rsp),%edi
xor    $0x31,%edi
call   1030 <putchar@plt>
and    $0x1,%ebx
xor    $0x31,%ebx
mov    %ebx,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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