#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*/ val;

/* Variables and functions */
int CHAR_BIT;
int /*<<< orphan*/ putchar(char);
void print_bit(int val) {
  int size = sizeof(val);
  int bit_val = size * CHAR_BIT;
  int mask = 1 << (bit_val - 1);
  for (int i = 1; i <= bit_val; ++i) {
    putchar((val & mask) == 0 ? ('0') : ('1'));
    val <<= 1;
    if ((i % 8 == 0) && (i != 0))
      putchar(' ');
  }
}


x86 assembly (clang, -O0):
<print_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2eb4(%rip),%rcx
imul   (%rcx),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b7 <print_bit+0xa7>
mov    -0x4(%rbp),%edx
and    -0x10(%rbp),%edx
mov    $0x31,%eax
mov    $0x30,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a4 <print_bit+0x94>
cmpl   $0x0,-0x14(%rbp)
je     11a4 <print_bit+0x94>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11a9 <print_bit+0x99>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1149 <print_bit+0x39>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2ec2(%rip),%rax
mov    (%rax),%eax
lea    0x0(,%rax,4),%r14d
lea    -0x1(%r14),%ecx
mov    $0x1,%r15d
mov    $0x1,%ebp
shl    %cl,%ebp
test   %eax,%eax
jle    118d <print_bit+0x7d>
mov    %edi,%ebx
cmp    $0x2,%r14d
cmovl  %r15d,%r14d
neg    %r14d
jmp    1167 <print_bit+0x57>
nopl   0x0(%rax)
add    %ebx,%ebx
lea    (%r14,%r15,1),%eax
add    $0x1,%eax
mov    %r15d,%ecx
add    $0x1,%ecx
mov    %ecx,%r15d
cmp    $0x1,%eax
je     118d <print_bit+0x7d>
mov    %ebx,%eax
and    %ebp,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
test   $0x7,%r15b
jne    1150 <print_bit+0x40>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1150 <print_bit+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@CHAR_BIT = 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 %2, 1
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 @llvm.smax.i32(i32 %3, i32 1)
br label %10
9: ; preds = %22, %1
ret void
10: ; preds = %7, %22
%11 = phi i32 [ %23, %22 ], [ 1, %7 ]
%12 = phi i32 [ %17, %22 ], [ %0, %7 ]
%13 = and i32 %12, %5
%14 = icmp eq i32 %13, 0
%15 = select i1 %14, i8 48, i8 49
%16 = tail call i32 @putchar(i8 signext %15)
%17 = shl i32 %12, 1
%18 = and i32 %11, 7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %10
%21 = tail call i32 @putchar(i8 signext 32)
br label %22
22: ; preds = %10, %20
%23 = add nuw nsw i32 %11, 1
%24 = icmp eq i32 %11, %8
br i1 %24, label %9, label %10
}