#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 CHAR_BIT;
int /*<<< orphan*/ printf(char *, char);
void print_binary(unsigned char n) {
  size_t unsigned_bits = sizeof(unsigned char) * CHAR_BIT;
  unsigned char i;
  for (i = 0; i < unsigned_bits; i++) {
    printf("%c", (n & (1 << (unsigned_bits - i - 1))) ? '1' : '0');
  }
}


x86 assembly (clang, -O0):
<print_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    0x2ebb(%rip),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %rax,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    -0x10(%rbp),%rax
jae    118c <print_binary+0x7c>
movzbl -0x1(%rbp),%edx
mov    -0x10(%rbp),%rax
movzbl -0x11(%rbp),%ecx
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    %eax,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
lea    0xe89(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
mov    -0x11(%rbp),%al
add    $0x1,%al
mov    %al,-0x11(%rbp)
jmp    1134 <print_binary+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2ec2(%rip),%rax
movslq (%rax),%rbx
test   %rbx,%rbx
je     116d <print_binary+0x5d>
movzbl %dil,%r15d
mov    $0x1,%bpl
lea    0xecc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x1(%rbp),%eax
movzbl %al,%eax
not    %eax
add    %ebx,%eax
bt     %eax,%r15d
mov    $0x31,%esi
adc    $0xffffffff,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl %bpl,%eax
mov    %eax,%ebp
add    $0x1,%bpl
cmp    %rax,%rbx
ja     1140 <print_binary+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str = [3 x i8] c"%c\00"
define void @print_binary(i8 zeroext %0) {
%2 = load i32, i32* @CHAR_BIT
%3 = sext i32 %2 to i64
%4 = icmp eq i32 %2, 0
br i1 %4, label %20, label %5
5: ; preds = %1
%6 = zext i8 %0 to i32
br label %7
7: ; preds = %5, %7
%8 = phi i8 [ 0, %5 ], [ %17, %7 ]
%9 = zext i8 %8 to i32
%10 = xor i32 %9, -1
%11 = add i32 %2, %10
%12 = shl nuw i32 1, %11
%13 = and i32 %12, %6
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8 48, i8 49
%16 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %15)
%17 = add i8 %8, 1
%18 = zext i8 %17 to i64
%19 = icmp ugt i64 %3, %18
br i1 %19, label %7, label %20
20: ; preds = %7, %1
ret void
}