#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 uint8_t;

/* Variables and functions */
uint8_t mask2index(uint8_t input) {
  uint8_t i;
  for (i = 0; i < 9; i++) {
    if (input == 0x80)
      return i;
    input <<= 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<mask2index>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jge    1147 <mask2index+0x47>
cmpl   $0x80,-0x8(%rbp)
jne    1130 <mask2index+0x30>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    114e <mask2index+0x4e>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    110e <mask2index+0xe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mask2index>:
xor    %eax,%eax
cmp    $0x80,%edi
je     1189 <mask2index+0x89>
mov    %edi,%ecx
and    $0x7fffffff,%ecx
mov    $0x1,%eax
cmp    $0x40,%ecx
je     1189 <mask2index+0x89>
mov    %edi,%ecx
and    $0x3fffffff,%ecx
mov    $0x2,%eax
cmp    $0x20,%ecx
je     1189 <mask2index+0x89>
mov    %edi,%ecx
and    $0x1fffffff,%ecx
mov    $0x3,%eax
cmp    $0x10,%ecx
je     1189 <mask2index+0x89>
mov    %edi,%ecx
and    $0xfffffff,%ecx
mov    $0x4,%eax
cmp    $0x8,%ecx
je     1189 <mask2index+0x89>
mov    %edi,%ecx
and    $0x7ffffff,%ecx
mov    $0x5,%eax
cmp    $0x4,%ecx
je     1189 <mask2index+0x89>
mov    %edi,%ecx
and    $0x3ffffff,%ecx
mov    $0x6,%eax
cmp    $0x2,%ecx
je     1189 <mask2index+0x89>
and    $0x1ffffff,%edi
xor    %ecx,%ecx
cmp    $0x1,%edi
mov    $0x7,%eax
cmovne %ecx,%eax
ret

LLVM IR (-O0):
define i32 @mask2index(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %16, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 9
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 128
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %20
13: ; preds = %8
%14 = load i32, i32* %3
%15 = shl i32 %14, 1
store i32 %15, i32* %3
br label %16
16: ; preds = %13
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %5
19: ; preds = %5
store i32 0, i32* %2
br label %20
20: ; preds = %19, %11
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
define i32 @mask2index(i32 %0) {
%2 = icmp eq i32 %0, 128
br i1 %2, label %25, label %3
3: ; preds = %1
%4 = and i32 %0, 2147483647
%5 = icmp eq i32 %4, 64
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = and i32 %0, 1073741823
%8 = icmp eq i32 %7, 32
br i1 %8, label %25, label %9
9: ; preds = %6
%10 = and i32 %0, 536870911
%11 = icmp eq i32 %10, 16
br i1 %11, label %25, label %12
12: ; preds = %9
%13 = and i32 %0, 268435455
%14 = icmp eq i32 %13, 8
br i1 %14, label %25, label %15
15: ; preds = %12
%16 = and i32 %0, 134217727
%17 = icmp eq i32 %16, 4
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = and i32 %0, 67108863
%20 = icmp eq i32 %19, 2
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = and i32 %0, 33554431
%23 = icmp eq i32 %22, 1
%24 = select i1 %23, i32 7, i32 0
br label %25
25: ; preds = %21, %18, %15, %12, %9, %6, %3, %1
%26 = phi i32 [ 0, %1 ], [ 1, %3 ], [ 2, %6 ], [ 3, %9 ], [ 4, %12 ], [ 5, %15 ], [ 6, %18 ], [ %24, %21 ]
ret i32 %26
}