#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);
void print_binary(unsigned char c, int length) {
  int i;
  c = c << (8 - length);
  for (i = 0; i < length; i++) {
    printf("%1d", (c & 0x80) ? 1 : 0);
    c = c << 1;
  }
}


x86 assembly (clang, -O0):
<print_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
movzbl -0x1(%rbp),%eax
mov    $0x8,%ecx
sub    -0x8(%rbp),%ecx
shl    %cl,%eax
mov    %al,-0x1(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1180 <print_binary+0x70>
movzbl -0x1(%rbp),%ecx
and    $0x80,%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
movzbl -0x1(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x1(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <print_binary+0x29>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
jle    114b <print_binary+0x3b>
mov    %esi,%ebx
movzbl %dil,%ebp
mov    $0x8,%cl
sub    %bl,%cl
shl    %cl,%ebp
lea    0xed5(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebp,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl %bpl,%ebp
add    %ebp,%ebp
add    $0xffffffff,%ebx
jne    1130 <print_binary+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%1d\00"
define void @print_binary(i8 zeroext %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = zext i8 %0 to i32
%6 = sub nsw i32 8, %1
%7 = shl nuw nsw i32 %5, %6
br label %8
8: ; preds = %4, %8
%9 = phi i32 [ %16, %8 ], [ 0, %4 ]
%10 = phi i32 [ %15, %8 ], [ %7, %4 ]
%11 = lshr i32 %10, 7
%12 = and i32 %11, 1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = shl i32 %10, 1
%15 = and i32 %14, 510
%16 = add nuw nsw i32 %9, 1
%17 = icmp eq i32 %16, %1
br i1 %17, label %18, label %8
18: ; preds = %8, %2
ret void
}