#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 _bitcount(int);
scalar_t__ _power2p(int);
int _ceil_power2(int value) {
  if (_power2p(value))
    return value;
  if (value == 1)
    return 2;
  int j, i = _bitcount(value);
  int res = 1;
  for (j = 0; j < i; j++)
    res <<= 1;
  return res;
}


x86 assembly (clang, -O0):
<_ceil_power2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <_power2p@plt>
cmp    $0x0,%rax
je     1148 <_ceil_power2+0x28>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11a0 <_ceil_power2+0x80>
cmpl   $0x1,-0x8(%rbp)
jne    115e <_ceil_power2+0x3e>
movl   $0x2,-0x4(%rbp)
jmp    11a0 <_ceil_power2+0x80>
mov    -0x8(%rbp),%edi
call   1040 <_bitcount@plt>
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    119a <_ceil_power2+0x7a>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1177 <_ceil_power2+0x57>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ceil_power2>:
push   %rbx
mov    %edi,%ebx
call   1030 <_power2p@plt>
test   %rax,%rax
je     1131 <_ceil_power2+0x11>
mov    %ebx,%eax
pop    %rbx
ret
mov    $0x2,%eax
cmp    $0x1,%ebx
je     1187 <_ceil_power2+0x67>
mov    %ebx,%edi
call   1040 <_bitcount@plt>
test   %eax,%eax
jle    115c <_ceil_power2+0x3c>
mov    %eax,%ecx
lea    -0x1(%rcx),%eax
mov    %ecx,%edx
and    $0x7,%edx
cmp    $0x7,%eax
jae    1163 <_ceil_power2+0x43>
mov    $0x1,%eax
jmp    1178 <_ceil_power2+0x58>
mov    $0x1,%eax
pop    %rbx
ret
and    $0xfffffff8,%ecx
mov    $0x1,%eax
nopl   0x0(%rax,%rax,1)
shl    $0x8,%eax
add    $0xfffffff8,%ecx
jne    1170 <_ceil_power2+0x50>
test   %edx,%edx
je     1187 <_ceil_power2+0x67>
nopl   0x0(%rax)
add    %eax,%eax
add    $0xffffffff,%edx
jne    1180 <_ceil_power2+0x60>
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @_ceil_power2(i32 %0) {
%2 = tail call i64 @_power2p(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %31
4: ; preds = %1
%5 = icmp eq i32 %0, 1
br i1 %5, label %31, label %6
6: ; preds = %4
%7 = tail call i32 @_bitcount(i32 %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %31
9: ; preds = %6
%10 = add i32 %7, -1
%11 = and i32 %7, 7
%12 = icmp ult i32 %10, 7
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = and i32 %7, -8
br label %15
15: ; preds = %15, %13
%16 = phi i32 [ 1, %13 ], [ %18, %15 ]
%17 = phi i32 [ 0, %13 ], [ %19, %15 ]
%18 = shl i32 %16, 8
%19 = add i32 %17, 8
%20 = icmp eq i32 %19, %14
br i1 %20, label %21, label %15
21: ; preds = %15, %9
%22 = phi i32 [ undef, %9 ], [ %18, %15 ]
%23 = phi i32 [ 1, %9 ], [ %18, %15 ]
%24 = icmp eq i32 %11, 0
br i1 %24, label %31, label %25
25: ; preds = %21, %25
%26 = phi i32 [ %28, %25 ], [ %23, %21 ]
%27 = phi i32 [ %29, %25 ], [ 0, %21 ]
%28 = shl i32 %26, 1
%29 = add i32 %27, 1
%30 = icmp eq i32 %29, %11
br i1 %30, label %31, label %25
31: ; preds = %21, %25, %6, %4, %1
%32 = phi i32 [ %0, %1 ], [ 2, %4 ], [ 1, %6 ], [ %22, %21 ], [ %28, %25 ]
ret i32 %32
}