#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 dbg_print_bit(unsigned short bit) {
  int i;
  unsigned short val = 1 << 15;
  for (i = 0; i < 16; i++) {
    if ((bit & val) == 0)
      printf("0");
    else
      printf("1");
    if (((i + 1) % 4) == 0 && (i != 15))
      printf(",");
    val = val >> 1;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dbg_print_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movw   $0x8000,-0xa(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x10,-0x8(%rbp)
jge    11ac <dbg_print_bit+0x9c>
movzwl -0x2(%rbp),%eax
movzwl -0xa(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    115a <dbg_print_bit+0x4a>
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
jmp    1166 <dbg_print_bit+0x56>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1193 <dbg_print_bit+0x83>
cmpl   $0xf,-0x8(%rbp)
je     1193 <dbg_print_bit+0x83>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
movzwl -0xa(%rbp),%eax
sar    $0x1,%eax
mov    %ax,-0xa(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    112c <dbg_print_bit+0x1c>
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbg_print_bit>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x8000,%ebp
mov    $0xfffffff0,%ebx
jmp    1136 <dbg_print_bit+0x26>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
shr    %ebp
inc    %ebx
je     1164 <dbg_print_bit+0x54>
mov    %ebp,%eax
and    %r14d,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
cmp    $0xffffffff,%ebx
je     1130 <dbg_print_bit+0x20>
lea    0x11(%rbx),%eax
and    $0x3,%eax
jne    1130 <dbg_print_bit+0x20>
mov    $0x2c,%edi
call   1030 <putchar@plt>
jmp    1130 <dbg_print_bit+0x20>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
define void @dbg_print_bit(i16 zeroext %0) {
%2 = zext i16 %0 to i32
br label %3
3: ; preds = %1, %17
%4 = phi i32 [ 32768, %1 ], [ %18, %17 ]
%5 = phi i32 [ 0, %1 ], [ %10, %17 ]
%6 = and i32 %4, %2
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i32 48, i32 49
%9 = tail call i32 @putchar(i32 %8)
%10 = add nuw nsw i32 %5, 1
%11 = and i32 %10, 3
%12 = icmp eq i32 %11, 0
%13 = icmp ne i32 %5, 15
%14 = and i1 %13, %12
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = tail call i32 @putchar(i32 44)
br label %17
17: ; preds = %15, %3
%18 = lshr i32 %4, 1
%19 = icmp eq i32 %10, 16
br i1 %19, label %20, label %3
20: ; preds = %17
%21 = tail call i32 @putchar(i32 10)
ret void
}