#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 *);
void print_binary(char b, unsigned char length) {
  if (length == 0)
    length = 8;
  int i;
  for (i = 7; i >= 8 - length; i--) {
    if (b & (1 << i)) {
      printf("X");
    } else {
      printf(".");
    }
  }
}


x86 assembly (clang, -O0):
<print_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x0,%eax
jne    1135 <print_binary+0x25>
movb   $0x8,-0x2(%rbp)
movl   $0x7,-0x8(%rbp)
mov    -0x8(%rbp),%eax
movzbl -0x2(%rbp),%edx
mov    $0x8,%ecx
sub    %edx,%ecx
cmp    %ecx,%eax
jl     119d <print_binary+0x8d>
movsbl -0x1(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     117e <print_binary+0x6e>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
jmp    118a <print_binary+0x7a>
lea    0xe7d(%rip),%rdi
call   1030 <printf@plt>
jmp    118f <print_binary+0x7f>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    113c <print_binary+0x2c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
mov    $0x8,%ebp
cmove  %ebp,%esi
mov    %edi,%r14d
mov    $0x8,%ebx
sub    %esi,%ebx
mov    $0x2e,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
bt     %ebp,%r14d
mov    $0x58,%edi
cmovae %r15d,%edi
call   1030 <putchar@plt>
cmp    %ebx,%ebp
jg     1140 <print_binary+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @print_binary(i8 signext %0, i8 zeroext %1) {
%3 = icmp eq i8 %1, 0
%4 = select i1 %3, i8 8, i8 %1
%5 = zext i8 %4 to i32
%6 = sub nsw i32 8, %5
%7 = sext i8 %0 to i32
br label %8
8: ; preds = %2, %8
%9 = phi i32 [ 7, %2 ], [ %15, %8 ]
%10 = shl nuw i32 1, %9
%11 = and i32 %10, %7
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 46, i32 88
%14 = tail call i32 @putchar(i32 %13)
%15 = add nsw i32 %9, -1
%16 = icmp sgt i32 %9, %6
br i1 %16, label %8, label %17
17: ; preds = %8
ret void
}