#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 most_significant_bit_pos_uchar(unsigned char);
int most_significant_bit_pos_ulong(unsigned long num) {
  int pos = 0;
  for (pos = 0;
       num > ((((1 << (8))) - (((((1 << (8))) & 1) | (!!(((1 << (8))))) |
                                (((1 << (8))) & 1)))));
       pos += 8, num >>= 8)
    ;
  return pos +
         most_significant_bit_pos_uchar(
             (unsigned char)(num & ((((1 << (8))) -
                                     (((((1 << (8))) & 1) | (!!(((1 << (8))))) |
                                       (((1 << (8))) & 1)))))));
}


x86 assembly (clang, -O0):
<most_significant_bit_pos_ulong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0xc(%rbp)
cmpq   $0xff,-0x8(%rbp)
jbe    1157 <most_significant_bit_pos_ulong+0x47>
jmp    113d <most_significant_bit_pos_ulong+0x2d>
mov    -0xc(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    112a <most_significant_bit_pos_ulong+0x1a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
and    $0xff,%rax
movzbl %al,%edi
call   1030 <most_significant_bit_pos_uchar@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<most_significant_bit_pos_ulong>:
push   %rbx
xor    %ebx,%ebx
cmp    $0x100,%rdi
jb     1145 <most_significant_bit_pos_ulong+0x35>
xor    %ebx,%ebx
mov    %rdi,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x8,%ebx
shr    $0x8,%rax
cmp    $0xffff,%rdi
mov    %rax,%rdi
ja     1130 <most_significant_bit_pos_ulong+0x20>
jmp    1148 <most_significant_bit_pos_ulong+0x38>
mov    %rdi,%rax
movzbl %al,%edi
call   1030 <most_significant_bit_pos_uchar@plt>
add    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @most_significant_bit_pos_ulong(i64 %0) {
%2 = alloca i64
%3 = alloca i32
store i64 %0, i64* %2
store i32 0, i32* %3
store i32 0, i32* %3
br label %4
4: ; preds = %8, %1
%5 = load i64, i64* %2
%6 = icmp ugt i64 %5, 255
br i1 %6, label %7, label %13
7: ; preds = %4
br label %8
8: ; preds = %7
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 8
store i32 %10, i32* %3
%11 = load i64, i64* %2
%12 = lshr i64 %11, 8
store i64 %12, i64* %2
br label %4
13: ; preds = %4
%14 = load i32, i32* %3
%15 = load i64, i64* %2
%16 = and i64 %15, 255
%17 = trunc i64 %16 to i8
%18 = call i32 @most_significant_bit_pos_uchar(i8 zeroext %17)
%19 = add nsw i32 %14, %18
ret i32 %19
}

LLVM IR (-O2):
define i32 @most_significant_bit_pos_ulong(i64 %0) {
%2 = icmp ugt i64 %0, 255
br i1 %2, label %3, label %9
3: ; preds = %1, %3
%4 = phi i32 [ %6, %3 ], [ 0, %1 ]
%5 = phi i64 [ %7, %3 ], [ %0, %1 ]
%6 = add nuw nsw i32 %4, 8
%7 = lshr i64 %5, 8
%8 = icmp ugt i64 %5, 65535
br i1 %8, label %3, label %9
9: ; preds = %3, %1
%10 = phi i64 [ %0, %1 ], [ %7, %3 ]
%11 = phi i32 [ 0, %1 ], [ %6, %3 ]
%12 = trunc i64 %10 to i8
%13 = tail call i32 @most_significant_bit_pos_uchar(i8 zeroext %12)
%14 = add nsw i32 %13, %11
ret i32 %14
}