#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 value) {
  char bits[] = {'0', '1'};
  for (int bit = 7; bit >= 0; bit--) {
    unsigned char bit_val = value;
    bit_val &= (1 << bit);
    bit_val >>= bit;
    printf("%c", bits[bit_val]);
  }
}


x86 assembly (clang, -O0):
<print_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    0xedb(%rip),%ax
mov    %ax,-0x3(%rbp)
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1184 <print_bits+0x74>
mov    -0x1(%rbp),%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
movzbl -0x9(%rbp),%eax
and    %ecx,%eax
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%ecx
movzbl -0x9(%rbp),%eax
sar    %cl,%eax
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
lea    0xe96(%rip),%rdi
movsbl -0x3(%rbp,%rax,1),%esi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1130 <print_bits+0x20>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %edi,%ebx
mov    %rbx,%rax
shr    $0x7,%rax
lea    0xed7(%rip),%r15
movsbl (%rax,%r15,1),%esi
lea    0xecd(%rip),%r14
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebp,%eax
shr    $0x6,%al
movzbl %al,%eax
and    $0x1,%eax
movsbl (%rax,%r15,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebp,%eax
shr    $0x5,%al
movzbl %al,%eax
and    $0x1,%eax
movsbl (%rax,%r15,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebp,%eax
shr    $0x4,%al
movzbl %al,%eax
and    $0x1,%eax
movsbl (%rax,%r15,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebp,%eax
shr    $0x3,%al
movzbl %al,%eax
and    $0x1,%eax
movsbl (%rax,%r15,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %ebp,%eax
shr    $0x2,%al
movzbl %al,%eax
and    $0x1,%eax
movsbl (%rax,%r15,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
shr    %bpl
movzbl %bpl,%eax
and    $0x1,%eax
movsbl (%rax,%r15,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
and    $0x1,%ebx
movsbl (%rbx,%r15,1),%esi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@__const.print_bits.bits = [2 x i8] c"01"
@.str = [3 x i8] c"%c\00"
define void @print_bits(i8 zeroext %0) {
%2 = lshr i8 %0, 7
%3 = zext i8 %2 to i64
%4 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.print_bits.bits, i64 0, i64 %3
%5 = load i8, i8* %4
%6 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %5)
%7 = lshr i8 %0, 6
%8 = and i8 %7, 1
%9 = zext i8 %8 to i64
%10 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.print_bits.bits, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %11)
%13 = lshr i8 %0, 5
%14 = and i8 %13, 1
%15 = zext i8 %14 to i64
%16 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.print_bits.bits, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %17)
%19 = lshr i8 %0, 4
%20 = and i8 %19, 1
%21 = zext i8 %20 to i64
%22 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.print_bits.bits, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %23)
%25 = lshr i8 %0, 3
%26 = and i8 %25, 1
%27 = zext i8 %26 to i64
%28 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.print_bits.bits, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %29)
%31 = lshr i8 %0, 2
%32 = and i8 %31, 1
%33 = zext i8 %32 to i64
%34 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.print_bits.bits, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %35)
%37 = lshr i8 %0, 1
%38 = and i8 %37, 1
%39 = zext i8 %38 to i64
%40 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.print_bits.bits, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %41)
%43 = and i8 %0, 1
%44 = zext i8 %43 to i64
%45 = getelementptr inbounds [2 x i8], [2 x i8]* @__const.print_bits.bits, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %46)
ret void
}