#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 bitprint(unsigned num) {
  unsigned mask;
  int bit, count, nbits;
  nbits = 8 * sizeof(unsigned);
  mask = 0x1 << (nbits - 1);
  for (count = 1; count <= nbits; count++) {
    bit = (num & mask) ? 1 : 0;
    printf("%x", bit);
    if (count % 4 == 0)
      printf(" ");
    mask >>= 1;
  }
  printf("\n");
  return;
}


x86 assembly (clang, -O0):
<bitprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x20,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11a5 <bitprint+0x95>
mov    -0x4(%rbp),%edx
and    -0x8(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118e <bitprint+0x7e>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1139 <bitprint+0x29>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bitprint>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x1,%ebp
mov    $0x80000000,%ebx
lea    0xec5(%rip),%r14
jmp    114a <bitprint+0x2a>
nopl   (%rax)
shr    %ebx
add    $0x1,%ebp
cmp    $0x21,%ebp
je     116f <bitprint+0x4f>
xor    %esi,%esi
test   %r15d,%ebx
setne  %sil
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0x3,%bpl
jne    1140 <bitprint+0x20>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1140 <bitprint+0x20>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
define void @bitprint(i32 %0) {
br label %2
2: ; preds = %1, %13
%3 = phi i32 [ -2147483648, %1 ], [ %14, %13 ]
%4 = phi i32 [ 1, %1 ], [ %15, %13 ]
%5 = and i32 %3, %0
%6 = icmp ne i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = and i32 %4, 3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @putchar(i32 32)
br label %13
13: ; preds = %11, %2
%14 = lshr i32 %3, 1
%15 = add nuw nsw i32 %4, 1
%16 = icmp eq i32 %15, 33
br i1 %16, label %17, label %2
17: ; preds = %13
%18 = tail call i32 @putchar(i32 10)
ret void
}