#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 */
size_t next_power(size_t size) {
  if ((size & (size - 1)) != 0) {
    --size;
    size |= size >> 1;
    size |= size >> 2;
    size |= size >> 4;
    size |= size >> 8;
    size |= size >> 16;
    ++size;
  } else if (size == 0) {
    ++size;
  }
  return size;
}


x86 assembly (clang, -O0):
<next_power>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     118e <next_power+0x8e>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x2,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x4,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x8,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x10,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <next_power+0xaa>
cmpq   $0x0,-0x8(%rbp)
jne    11a5 <next_power+0xa5>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <next_power+0xaa>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_power>:
lea    -0x1(%rdi),%rax
test   %rax,%rdi
jne    1116 <next_power+0x16>
test   %rdi,%rdi
mov    $0x1,%eax
cmovne %rdi,%rax
ret
mov    %rax,%rcx
shr    %rcx
or     %rax,%rcx
mov    %rcx,%rax
shr    $0x2,%rax
or     %rcx,%rax
mov    %rax,%rcx
shr    $0x4,%rcx
or     %rax,%rcx
mov    %rcx,%rdx
shr    $0x8,%rdx
or     %rcx,%rdx
mov    %rdx,%rax
shr    $0x10,%rax
or     %rdx,%rax
add    $0x1,%rax
ret

LLVM IR (-O0):
define i64 @next_power(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = load i64, i64* %2
%5 = sub i64 %4, 1
%6 = and i64 %3, %5
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %33
8: ; preds = %1
%9 = load i64, i64* %2
%10 = add i64 %9, -1
store i64 %10, i64* %2
%11 = load i64, i64* %2
%12 = lshr i64 %11, 1
%13 = load i64, i64* %2
%14 = or i64 %13, %12
store i64 %14, i64* %2
%15 = load i64, i64* %2
%16 = lshr i64 %15, 2
%17 = load i64, i64* %2
%18 = or i64 %17, %16
store i64 %18, i64* %2
%19 = load i64, i64* %2
%20 = lshr i64 %19, 4
%21 = load i64, i64* %2
%22 = or i64 %21, %20
store i64 %22, i64* %2
%23 = load i64, i64* %2
%24 = lshr i64 %23, 8
%25 = load i64, i64* %2
%26 = or i64 %25, %24
store i64 %26, i64* %2
%27 = load i64, i64* %2
%28 = lshr i64 %27, 16
%29 = load i64, i64* %2
%30 = or i64 %29, %28
store i64 %30, i64* %2
%31 = load i64, i64* %2
%32 = add i64 %31, 1
store i64 %32, i64* %2
br label %40
33: ; preds = %1
%34 = load i64, i64* %2
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i64, i64* %2
%38 = add i64 %37, 1
store i64 %38, i64* %2
br label %39
39: ; preds = %36, %33
br label %40
40: ; preds = %39, %8
%41 = load i64, i64* %2
ret i64 %41
}

LLVM IR (-O2):
define i64 @next_power(i64 %0) {
%2 = tail call i64 @llvm.ctpop.i64(i64 %0)
%3 = icmp ult i64 %2, 2
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = add i64 %0, -1
%6 = lshr i64 %5, 1
%7 = or i64 %6, %5
%8 = lshr i64 %7, 2
%9 = or i64 %8, %7
%10 = lshr i64 %9, 4
%11 = or i64 %10, %9
%12 = lshr i64 %11, 8
%13 = or i64 %12, %11
%14 = lshr i64 %13, 16
%15 = or i64 %14, %13
%16 = add i64 %15, 1
br label %20
17: ; preds = %1
%18 = icmp eq i64 %0, 0
%19 = select i1 %18, i64 1, i64 %0
br label %20
20: ; preds = %17, %4
%21 = phi i64 [ %16, %4 ], [ %19, %17 ]
ret i64 %21
}