#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 uint64_t;
typedef int uint32_t;
typedef int int64_t;

/* Variables and functions */
uint32_t num_significant_bits(int64_t x) {
  uint64_t mask;
  uint32_t k;
  mask = ((uint64_t)1) << 63;
  k = 64;
  if (x < 0) {
    for (;;) {
      mask >>= 1;
      if ((mask & x) == 0)
        break;
      k--;
    }
  } else {
    for (;;) {
      mask >>= 1;
      if (mask == 0 || (mask & x) != 0)
        break;
      k--;
    }
  }
  return k;
}


x86 assembly (clang, -O0):
<num_significant_bits>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %eax,-0x8(%rbp)
movl   $0x40,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1150 <num_significant_bits+0x50>
jmp    1120 <num_significant_bits+0x20>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    -0x4(%rbp),%eax
cmp    $0x0,%eax
jne    113d <num_significant_bits+0x3d>
jmp    114b <num_significant_bits+0x4b>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1120 <num_significant_bits+0x20>
jmp    118f <num_significant_bits+0x8f>
jmp    1155 <num_significant_bits+0x55>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1177 <num_significant_bits+0x77>
mov    -0x8(%rbp),%eax
and    -0x4(%rbp),%eax
cmp    $0x0,%eax
je     117c <num_significant_bits+0x7c>
jmp    118a <num_significant_bits+0x8a>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <num_significant_bits+0x55>
jmp    118f <num_significant_bits+0x8f>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_significant_bits>:
test   %edi,%edi
js     1121 <num_significant_bits+0x21>
mov    $0x41,%eax
nopl   0x0(%rax)
add    $0xffffffff,%eax
cmp    $0x2,%ecx
jb     1120 <num_significant_bits+0x20>
sar    %ecx
mov    %ecx,%edx
and    %edi,%edx
je     1110 <num_significant_bits+0x10>
ret
mov    $0x40,%eax
ret

LLVM IR (-O0):
define i32 @num_significant_bits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 poison, i32* %3
store i32 64, i32* %4
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %1
br label %8
8: ; preds = %16, %7
%9 = load i32, i32* %3
%10 = ashr i32 %9, 1
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = and i32 %11, %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %8
br label %19
16: ; preds = %8
%17 = load i32, i32* %4
%18 = add nsw i32 %17, -1
store i32 %18, i32* %4
br label %8
19: ; preds = %15
br label %36
20: ; preds = %1
br label %21
21: ; preds = %32, %20
%22 = load i32, i32* %3
%23 = ashr i32 %22, 1
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = load i32, i32* %3
%28 = load i32, i32* %2
%29 = and i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26, %21
br label %35
32: ; preds = %26
%33 = load i32, i32* %4
%34 = add nsw i32 %33, -1
store i32 %34, i32* %4
br label %21
35: ; preds = %31
br label %36
36: ; preds = %35, %19
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @num_significant_bits(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %12, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %6, %3 ], [ poison, %1 ]
%5 = phi i32 [ %11, %3 ], [ 64, %1 ]
%6 = ashr i32 %4, 1
%7 = icmp ugt i32 %4, 1
%8 = and i32 %6, %0
%9 = icmp eq i32 %8, 0
%10 = select i1 %7, i1 %9, i1 false
%11 = add nsw i32 %5, -1
br i1 %10, label %3, label %12
12: ; preds = %3, %1
%13 = phi i32 [ 64, %1 ], [ %5, %3 ]
ret i32 %13
}