#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 unsigned int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ is_pow2(unsigned int);
int find_1bit(uint16_t x) {
  int i;
  if (!is_pow2(x))
    return -1;
  for (i = 0; i < 16; i++)
    if (x & (1u << i))
      return i;
  return 0;
}


x86 assembly (clang, -O0):
<find_1bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <is_pow2@plt>
cmp    $0x0,%eax
jne    1138 <find_1bit+0x28>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <find_1bit+0x78>
movl   $0x0,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jge    1181 <find_1bit+0x71>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     116e <find_1bit+0x5e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1188 <find_1bit+0x78>
jmp    1173 <find_1bit+0x63>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113f <find_1bit+0x2f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_1bit>:
push   %rbx
mov    %edi,%ebx
call   1030 <is_pow2@plt>
test   %eax,%eax
je     11e7 <find_1bit+0xd7>
xor    %eax,%eax
test   $0x1,%bl
jne    11e5 <find_1bit+0xd5>
mov    $0x1,%eax
test   $0x2,%bl
jne    11e5 <find_1bit+0xd5>
mov    $0x2,%eax
test   $0x4,%bl
jne    11e5 <find_1bit+0xd5>
mov    $0x3,%eax
test   $0x8,%bl
jne    11e5 <find_1bit+0xd5>
mov    $0x4,%eax
test   $0x10,%bl
jne    11e5 <find_1bit+0xd5>
mov    $0x5,%eax
test   $0x20,%bl
jne    11e5 <find_1bit+0xd5>
mov    $0x6,%eax
test   $0x40,%bl
jne    11e5 <find_1bit+0xd5>
mov    $0x7,%eax
test   $0x80,%bl
jne    11e5 <find_1bit+0xd5>
mov    $0x8,%eax
test   $0x100,%ebx
jne    11e5 <find_1bit+0xd5>
mov    $0x9,%eax
test   $0x200,%ebx
jne    11e5 <find_1bit+0xd5>
mov    $0xa,%eax
test   $0x400,%ebx
jne    11e5 <find_1bit+0xd5>
mov    $0xb,%eax
test   $0x800,%ebx
jne    11e5 <find_1bit+0xd5>
mov    $0xc,%eax
test   $0x1000,%ebx
jne    11e5 <find_1bit+0xd5>
mov    $0xd,%eax
test   $0x2000,%ebx
jne    11e5 <find_1bit+0xd5>
mov    $0xe,%eax
test   $0x4000,%ebx
jne    11e5 <find_1bit+0xd5>
movswl %bx,%eax
shr    $0xf,%eax
and    $0xf,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @find_1bit(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @is_pow2(i32 %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 -1, i32* %2
br label %26
9: ; preds = %1
store i32 0, i32* %4
br label %10
10: ; preds = %22, %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 16
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = shl i32 1, %15
%17 = and i32 %14, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = load i32, i32* %4
store i32 %20, i32* %2
br label %26
21: ; preds = %13
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %10
25: ; preds = %10
store i32 0, i32* %2
br label %26
26: ; preds = %25, %19, %8
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @find_1bit(i32 %0) {
%2 = tail call i32 @is_pow2(i32 %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %53, label %4
4: ; preds = %1
%5 = and i32 %0, 1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %53
7: ; preds = %4
%8 = and i32 %0, 2
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %53
10: ; preds = %7
%11 = and i32 %0, 4
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %53
13: ; preds = %10
%14 = and i32 %0, 8
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %53
16: ; preds = %13
%17 = and i32 %0, 16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %53
19: ; preds = %16
%20 = and i32 %0, 32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %53
22: ; preds = %19
%23 = and i32 %0, 64
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %53
25: ; preds = %22
%26 = and i32 %0, 128
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %53
28: ; preds = %25
%29 = and i32 %0, 256
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %53
31: ; preds = %28
%32 = and i32 %0, 512
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %53
34: ; preds = %31
%35 = and i32 %0, 1024
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %53
37: ; preds = %34
%38 = and i32 %0, 2048
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %53
40: ; preds = %37
%41 = and i32 %0, 4096
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %53
43: ; preds = %40
%44 = and i32 %0, 8192
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = and i32 %0, 16384
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = and i32 %0, 32768
%51 = icmp eq i32 %50, 0
%52 = select i1 %51, i32 0, i32 15
br label %53
53: ; preds = %49, %4, %7, %10, %13, %16, %19, %22, %25, %28, %31, %34, %37, %40, %43, %46, %1
%54 = phi i32 [ -1, %1 ], [ 0, %4 ], [ 1, %7 ], [ 2, %10 ], [ 3, %13 ], [ 4, %16 ], [ 5, %19 ], [ 6, %22 ], [ 7, %25 ], [ 8, %28 ], [ 9, %31 ], [ 10, %34 ], [ 11, %37 ], [ 12, %40 ], [ 13, %43 ], [ 14, %46 ], [ %52, %49 ]
ret i32 %54
}