#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
void printBitString(uint16_t bitString, uint8_t length) {
  uint16_t mask = (0x01 << (length - 1));
  for (int bitIndex = 0; bitIndex < length; bitIndex++) {
    if (bitString & (mask >> bitIndex)) {
      printf("1");
    } else {
      printf("0");
    }
  }
}


x86 assembly (clang, -O0):
<printBitString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1189 <printBitString+0x79>
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
sar    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     116a <printBitString+0x5a>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
jmp    1176 <printBitString+0x66>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
jmp    117b <printBitString+0x6b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1135 <printBitString+0x25>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBitString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
lea    -0x1(%r15),%ecx
mov    $0x1,%ebx
shl    %cl,%ebx
test   %esi,%esi
jle    1151 <printBitString+0x41>
mov    %edi,%r14d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %ebx,%eax
mov    %ebp,%ecx
sar    %cl,%eax
and    %r14d,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1130 <printBitString+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @printBitString(i32 %0, i32 %1) {
%3 = add nsw i32 %1, -1
%4 = shl nuw i32 1, %3
%5 = icmp sgt i32 %1, 0
br i1 %5, label %7, label %6
6: ; preds = %7, %2
ret void
7: ; preds = %2, %7
%8 = phi i32 [ %14, %7 ], [ 0, %2 ]
%9 = ashr i32 %4, %8
%10 = and i32 %9, %0
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i32 48, i32 49
%13 = tail call i32 @putchar(i32 %12)
%14 = add nuw nsw i32 %8, 1
%15 = icmp eq i32 %14, %1
br i1 %15, label %6, label %7
}