#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 *);
int /*<<< orphan*/ putchar(unsigned char);
void printbits(unsigned char v) {
  int i;
  for (i = 7; i >= 0; i--)
    putchar('0' + ((v >> i) & 1));
  printf("\n");
}


x86 assembly (clang, -O0):
<printbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x7,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1164 <printbits+0x44>
movzbl -0x1(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
add    $0x30,%eax
movzbl %al,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1135 <printbits+0x15>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbits>:
push   %rbx
mov    %edi,%ebx
mov    %ebx,%eax
shr    $0x7,%al
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
shr    $0x6,%al
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
shr    $0x5,%al
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
shr    $0x4,%al
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
shr    $0x3,%al
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
shr    $0x2,%al
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
shr    %al
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
and    $0x1,%bl
or     $0x30,%bl
movzbl %bl,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
define void @printbits(i8 zeroext %0) {
%2 = lshr i8 %0, 7
%3 = or i8 %2, 48
%4 = tail call i32 @putchar(i8 zeroext %3)
%5 = lshr i8 %0, 6
%6 = and i8 %5, 1
%7 = or i8 %6, 48
%8 = tail call i32 @putchar(i8 zeroext %7)
%9 = lshr i8 %0, 5
%10 = and i8 %9, 1
%11 = or i8 %10, 48
%12 = tail call i32 @putchar(i8 zeroext %11)
%13 = lshr i8 %0, 4
%14 = and i8 %13, 1
%15 = or i8 %14, 48
%16 = tail call i32 @putchar(i8 zeroext %15)
%17 = lshr i8 %0, 3
%18 = and i8 %17, 1
%19 = or i8 %18, 48
%20 = tail call i32 @putchar(i8 zeroext %19)
%21 = lshr i8 %0, 2
%22 = and i8 %21, 1
%23 = or i8 %22, 48
%24 = tail call i32 @putchar(i8 zeroext %23)
%25 = lshr i8 %0, 1
%26 = and i8 %25, 1
%27 = or i8 %26, 48
%28 = tail call i32 @putchar(i8 zeroext %27)
%29 = and i8 %0, 1
%30 = or i8 %29, 48
%31 = tail call i32 @putchar(i8 zeroext %30)
%32 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
ret void
}