#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_bitmap(unsigned short *buffer, int len) {
  int i;
  int i1, i2;
  int a;
  for (i = 0; i < len * (sizeof(unsigned short) * 8); i++) {
    i1 = i / (sizeof(unsigned short) * 8);
    i2 = (sizeof(unsigned short) * 8) - 1 - i % (sizeof(unsigned short) * 8);
    a = !!((buffer[i1]) & (1 << i2));
    printf("%d", a);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_bitmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movslq -0xc(%rbp),%rcx
shl    $0x4,%rcx
cmp    %rcx,%rax
jae    11a4 <print_bitmap+0x94>
movslq -0x10(%rbp),%rax
shr    $0x4,%rax
mov    %eax,-0x14(%rbp)
movslq -0x10(%rbp),%rcx
and    $0xf,%rcx
mov    $0xf,%eax
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzwl (%rax,%rcx,2),%eax
mov    -0x18(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <print_bitmap+0x16>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bitmap>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1180 <print_bitmap+0x60>
mov    %rdi,%r15
movslq %esi,%rax
shl    $0x4,%rax
cmp    $0x2,%rax
mov    $0x1,%r12d
cmovae %rax,%r12
lea    0xeb5(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
mov    %rbx,%rax
shr    $0x3,%rax
and    $0x1ffffffe,%eax
movzwl (%r15,%rax,1),%esi
mov    %ebx,%ecx
not    %cl
and    $0xf,%cl
shr    %cl,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <print_bitmap+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_bitmap(i16* %0, i32 %1) {
%3 = alloca i16*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i16* %0, i16** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %41, %2
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 16
%15 = icmp ult i64 %11, %14
br i1 %15, label %16, label %44
16: ; preds = %9
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = udiv i64 %18, 16
%20 = trunc i64 %19 to i32
store i32 %20, i32* %6
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = urem i64 %22, 16
%24 = sub i64 15, %23
%25 = trunc i64 %24 to i32
store i32 %25, i32* %7
%26 = load i16*, i16** %3
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i16, i16* %26, i64 %28
%30 = load i16, i16* %29
%31 = zext i16 %30 to i32
%32 = load i32, i32* %7
%33 = shl i32 1, %32
%34 = and i32 %31, %33
%35 = icmp ne i32 %34, 0
%36 = xor i1 %35, true
%37 = xor i1 %36, true
%38 = zext i1 %37 to i32
store i32 %38, i32* %8
%39 = load i32, i32* %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %16
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %9
44: ; preds = %9
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @print_bitmap(i16* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %23, label %4
4: ; preds = %2
%5 = sext i32 %1 to i64
%6 = shl nsw i64 %5, 4
%7 = call i64 @llvm.umax.i64(i64 %6, i64 1)
br label %8
8: ; preds = %4, %8
%9 = phi i64 [ 0, %4 ], [ %21, %8 ]
%10 = trunc i64 %9 to i32
%11 = lshr i64 %9, 4
%12 = and i32 %10, 15
%13 = xor i32 %12, 15
%14 = and i64 %11, 268435455
%15 = getelementptr inbounds i16, i16* %0, i64 %14
%16 = load i16, i16* %15
%17 = zext i16 %16 to i32
%18 = lshr i32 %17, %13
%19 = and i32 %18, 1
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = add nuw i64 %9, 1
%22 = icmp eq i64 %21, %7
br i1 %22, label %23, label %8
23: ; preds = %8, %2
%24 = tail call i32 @putchar(i32 10)
ret void
}