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


x86 assembly (clang, -O0):
<print_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ebe(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jg     11da <print_bit+0xca>
mov    -0x4(%rbp),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
jne    1176 <print_bit+0x66>
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    $0x30,%edi
call   1030 <fputc@plt>
jmp    1189 <print_bit+0x79>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    $0x31,%edi
call   1030 <fputc@plt>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2e44(%rip),%rcx
cltd
idivl  (%rcx)
cmp    $0x0,%edx
jne    11c7 <print_bit+0xb7>
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c7 <print_bit+0xb7>
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
mov    $0x20,%edi
call   1030 <fputc@plt>
jmp    11cc <print_bit+0xbc>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1143 <print_bit+0x33>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ebe(%rip),%rax
mov    (%rax),%r15d
shl    $0x2,%r15d
lea    -0x1(%r15),%ecx
mov    $0x1,%ebx
mov    $0x1,%r12d
shl    %cl,%r12d
test   %r15d,%r15d
jle    11b1 <print_bit+0xa1>
mov    %edi,%ebp
mov    %r15d,%r13d
neg    %r13d
mov    0x2e89(%rip),%r14
jmp    1175 <print_bit+0x65>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ebp,%ebp
lea    (%rbx,%r13,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
je     11b1 <print_bit+0xa1>
mov    %ebp,%eax
and    %r12d,%eax
mov    (%r14),%esi
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <fputc@plt>
mov    %ebx,%eax
cltd
mov    0x2e49(%rip),%rcx
idivl  (%rcx)
test   %edx,%edx
jne    1160 <print_bit+0x50>
cmp    %r15d,%ebx
jge    1160 <print_bit+0x50>
mov    (%r14),%esi
mov    $0x20,%edi
call   1030 <fputc@plt>
jmp    1160 <print_bit+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@stdout = global i32 0
define void @print_bit(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* @CHAR_BIT
%7 = sext i32 %6 to i64
%8 = mul i64 4, %7
%9 = trunc i64 %8 to i32
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = sub nsw i32 %10, 1
%12 = shl i32 1, %11
store i32 %12, i32* %4
store i32 1, i32* %5
br label %13
13: ; preds = %44, %1
%14 = load i32, i32* %5
%15 = load i32, i32* %3
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %47
17: ; preds = %13
%18 = load i32, i32* %2
%19 = load i32, i32* %4
%20 = and i32 %18, %19
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* @stdout
%24 = call i32 @fputc(i8 signext 48, i32 %23)
br label %28
25: ; preds = %17
%26 = load i32, i32* @stdout
%27 = call i32 @fputc(i8 signext 49, i32 %26)
br label %28
28: ; preds = %25, %22
%29 = phi i32 [ %24, %22 ], [ %27, %25 ]
%30 = load i32, i32* %2
%31 = shl i32 %30, 1
store i32 %31, i32* %2
%32 = load i32, i32* %5
%33 = load i32, i32* @CHAR_BIT
%34 = srem i32 %32, %33
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %28
%37 = load i32, i32* %5
%38 = load i32, i32* %3
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @stdout
%42 = call i32 @fputc(i8 signext 32, i32 %41)
br label %43
43: ; preds = %40, %36, %28
br label %44
44: ; preds = %43
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %13
47: ; preds = %13
ret void
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@stdout = global i32 0
define void @print_bit(i32 %0) {
%2 = load i32, i32* @CHAR_BIT
%3 = shl i32 %2, 2
%4 = add nsw i32 %3, -1
%5 = shl nuw i32 1, %4
%6 = icmp slt i32 %3, 1
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = or i32 %3, 1
br label %10
9: ; preds = %27, %1
ret void
10: ; preds = %7, %27
%11 = phi i32 [ %28, %27 ], [ 1, %7 ]
%12 = phi i32 [ %18, %27 ], [ %0, %7 ]
%13 = and i32 %12, %5
%14 = icmp eq i32 %13, 0
%15 = load i32, i32* @stdout
%16 = select i1 %14, i8 48, i8 49
%17 = tail call i32 @fputc(i8 signext %16, i32 %15)
%18 = shl i32 %12, 1
%19 = load i32, i32* @CHAR_BIT
%20 = srem i32 %11, %19
%21 = icmp eq i32 %20, 0
%22 = icmp slt i32 %11, %3
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %24, label %27
24: ; preds = %10
%25 = load i32, i32* @stdout
%26 = tail call i32 @fputc(i8 signext 32, i32 %25)
br label %27
27: ; preds = %10, %24
%28 = add nuw nsw i32 %11, 1
%29 = icmp eq i32 %28, %8
br i1 %29, label %9, label %10
}