#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*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void print_bit(unsigned int bit_size, unsigned int bit_field) {
  int mask = 1 << (bit_size - 1);
  for (int i = 1; i <= bit_size; ++i) {
    fputc((bit_field & mask) == 0 ? '0' : '1', stdout);
    bit_field <<= 1;
  }
}


x86 assembly (clang, -O0):
<print_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x4(%rbp),%eax
ja     117f <print_bit+0x6f>
mov    -0x8(%rbp),%edx
and    -0xc(%rbp),%edx
mov    $0x31,%eax
mov    $0x30,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
mov    0x2e82(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1135 <print_bit+0x25>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
lea    -0x1(%r14),%ecx
mov    $0x1,%ebp
shl    %cl,%ebp
cmp    $0x1,%edi
jb     115f <print_bit+0x4f>
mov    %esi,%ebx
mov    0x2ead(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebx,%eax
and    %ebp,%eax
mov    (%r15),%esi
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <fputc@plt>
add    %ebx,%ebx
add    $0xffffffff,%r14d
jne    1140 <print_bit+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define void @print_bit(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* %3
%8 = sub i32 %7, 1
%9 = shl i32 1, %8
store i32 %9, i32* %5
store i32 1, i32* %6
br label %10
10: ; preds = %26, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %3
%13 = icmp ule i32 %11, %12
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = and i32 %15, %16
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i64
%20 = select i1 %18, i32 48, i32 49
%21 = trunc i32 %20 to i8
%22 = load i32, i32* @stdout
%23 = call i32 @fputc(i8 signext %21, i32 %22)
%24 = load i32, i32* %4
%25 = shl i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %14
%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):
@stdout = global i32 0
define void @print_bit(i32 %0, i32 %1) {
%3 = add i32 %0, -1
%4 = shl nuw i32 1, %3
%5 = icmp eq i32 %0, 0
br i1 %5, label %6, label %7
6: ; preds = %7, %2
ret void
7: ; preds = %2, %7
%8 = phi i32 [ %16, %7 ], [ 1, %2 ]
%9 = phi i32 [ %15, %7 ], [ %1, %2 ]
%10 = and i32 %9, %4
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, i8 48, i8 49
%13 = load i32, i32* @stdout
%14 = tail call i32 @fputc(i8 signext %12, i32 %13)
%15 = shl i32 %9, 1
%16 = add nuw i32 %8, 1
%17 = icmp eq i32 %8, %0
br i1 %17, label %6, label %7
}