#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 /*<<< orphan*/ abort();
int to_pow2(int i) {
  static const unsigned int pow2[] = {1,    2,    4,     8,     16,   32,
                                      64,   128,  256,   512,   1024, 2048,
                                      4096, 8192, 16384, 32768, 65536};
  int j;
  for (j = 0; j < (sizeof((pow2)) / sizeof((*pow2))); j++)
    if (pow2[j] >= i)
      return pow2[j];
  abort();
}


x86 assembly (clang, -O0):
<to_pow2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
cmp    $0x11,%rax
jae    116e <to_pow2+0x5e>
movslq -0x8(%rbp),%rcx
lea    0xec5(%rip),%rax
mov    (%rax,%rcx,4),%eax
cmp    -0x4(%rbp),%eax
jb     115b <to_pow2+0x4b>
movslq -0x8(%rbp),%rcx
lea    0xeae(%rip),%rax
mov    (%rax,%rcx,4),%eax
add    $0x10,%rsp
pop    %rbp
ret
jmp    1160 <to_pow2+0x50>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <to_pow2+0x12>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<to_pow2>:
mov    $0x1,%eax
cmp    $0x2,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x2,%eax
je     11f1 <to_pow2+0xe1>
mov    $0x4,%eax
cmp    $0x5,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x8,%eax
cmp    $0x9,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x10,%eax
cmp    $0x11,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x20,%eax
cmp    $0x21,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x40,%eax
cmp    $0x41,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x80,%eax
cmp    $0x81,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x100,%eax
cmp    $0x101,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x200,%eax
cmp    $0x201,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x400,%eax
cmp    $0x401,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x800,%eax
cmp    $0x801,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x1000,%eax
cmp    $0x1001,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x2000,%eax
cmp    $0x2001,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x4000,%eax
cmp    $0x4001,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x8000,%eax
cmp    $0x8001,%edi
jb     11f1 <to_pow2+0xe1>
mov    $0x10000,%eax
cmp    $0x10001,%edi
jae    11f2 <to_pow2+0xe2>
ret
push   %rax
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@to_pow2.pow2 = internal constant [17 x i32] [i32 1, i32 2, i32 4, i32 8, i32 16, i32 32, i32 64, i32 128, i32 256, i32 512, i32 1024, i32 2048, i32 4096, i32 8192, i32 16384, i32 32768, i32 65536]
define i32 @to_pow2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %4
4: ; preds = %21, %1
%5 = load i32, i32* %3
%6 = sext i32 %5 to i64
%7 = icmp ult i64 %6, 17
br i1 %7, label %8, label %24
8: ; preds = %4
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [17 x i32], [17 x i32]* @to_pow2.pow2, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = load i32, i32* %2
%14 = icmp uge i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [17 x i32], [17 x i32]* @to_pow2.pow2, i64 0, i64 %17
%19 = load i32, i32* %18
ret i32 %19
20: ; preds = %8
br label %21
21: ; preds = %20
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %4
24: ; preds = %4
%25 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
define i32 @to_pow2(i32 %0) {
%2 = icmp ugt i32 %0, 1
br i1 %2, label %3, label %37
3: ; preds = %1
%4 = icmp eq i32 %0, 2
br i1 %4, label %37, label %5
5: ; preds = %3
%6 = icmp ugt i32 %0, 4
br i1 %6, label %7, label %37
7: ; preds = %5
%8 = icmp ugt i32 %0, 8
br i1 %8, label %9, label %37
9: ; preds = %7
%10 = icmp ugt i32 %0, 16
br i1 %10, label %11, label %37
11: ; preds = %9
%12 = icmp ugt i32 %0, 32
br i1 %12, label %13, label %37
13: ; preds = %11
%14 = icmp ugt i32 %0, 64
br i1 %14, label %15, label %37
15: ; preds = %13
%16 = icmp ugt i32 %0, 128
br i1 %16, label %17, label %37
17: ; preds = %15
%18 = icmp ugt i32 %0, 256
br i1 %18, label %19, label %37
19: ; preds = %17
%20 = icmp ugt i32 %0, 512
br i1 %20, label %21, label %37
21: ; preds = %19
%22 = icmp ugt i32 %0, 1024
br i1 %22, label %23, label %37
23: ; preds = %21
%24 = icmp ugt i32 %0, 2048
br i1 %24, label %25, label %37
25: ; preds = %23
%26 = icmp ugt i32 %0, 4096
br i1 %26, label %27, label %37
27: ; preds = %25
%28 = icmp ugt i32 %0, 8192
br i1 %28, label %29, label %37
29: ; preds = %27
%30 = icmp ugt i32 %0, 16384
br i1 %30, label %31, label %37
31: ; preds = %29
%32 = icmp ugt i32 %0, 32768
br i1 %32, label %33, label %37
33: ; preds = %31
%34 = icmp ugt i32 %0, 65536
br i1 %34, label %35, label %37
35: ; preds = %33
%36 = tail call i32 (...) @abort()
unreachable
37: ; preds = %33, %31, %29, %27, %25, %23, %21, %19, %17, %15, %13, %11, %9, %7, %5, %3, %1
%38 = phi i32 [ 1, %1 ], [ 2, %3 ], [ 4, %5 ], [ 8, %7 ], [ 16, %9 ], [ 32, %11 ], [ 64, %13 ], [ 128, %15 ], [ 256, %17 ], [ 512, %19 ], [ 1024, %21 ], [ 2048, %23 ], [ 4096, %25 ], [ 8192, %27 ], [ 16384, %29 ], [ 32768, %31 ], [ 65536, %33 ]
ret i32 %38
}