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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, unsigned int);
int get_netmask_prefix_len(unsigned int mask) {
  int prefix = 0, max_loop = sizeof(mask) * 8 + 1;
  while (mask) {
    if (mask & 1)
      prefix++;
    mask >>= 1;
    printf("mask = 0x%x\n", mask);
  }
  return prefix;
}


x86 assembly (clang, -O0):
<get_netmask_prefix_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x21,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1168 <get_netmask_prefix_len+0x58>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     114b <get_netmask_prefix_len+0x3b>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
jmp    1129 <get_netmask_prefix_len+0x19>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_netmask_prefix_len>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
je     114f <get_netmask_prefix_len+0x3f>
mov    %edi,%r15d
xor    %ebx,%ebx
lea    0xed9(%rip),%r14
mov    %edi,%ebp
nopl   0x0(%rax)
mov    %r15d,%eax
and    $0x1,%eax
add    %eax,%ebx
shr    %ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
cmp    $0x1,%r15d
mov    %ebp,%r15d
ja     1130 <get_netmask_prefix_len+0x20>
jmp    1151 <get_netmask_prefix_len+0x41>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"mask = 0x%x\0A\00"
define i32 @get_netmask_prefix_len(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 33, i32* %4
br label %5
5: ; preds = %15, %1
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %5
%9 = load i32, i32* %2
%10 = and i32 %9, 1
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
br label %15
15: ; preds = %12, %8
%16 = load i32, i32* %2
%17 = lshr i32 %16, 1
store i32 %17, i32* %2
%18 = load i32, i32* %2
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %5
20: ; preds = %5
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [13 x i8] c"mask = 0x%x\0A\00"
define i32 @get_netmask_prefix_len(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %11, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %8, %3 ], [ %0, %1 ]
%5 = phi i32 [ %7, %3 ], [ 0, %1 ]
%6 = and i32 %4, 1
%7 = add nuw nsw i32 %6, %5
%8 = lshr i32 %4, 1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp ult i32 %4, 2
br i1 %10, label %11, label %3
11: ; preds = %3, %1
%12 = phi i32 [ 0, %1 ], [ %7, %3 ]
ret i32 %12
}