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

/* Variables and functions */
scalar_t__ is_pow_of_2(int);
uint32_t next_pow_of_2(uint32_t x) {
  if (is_pow_of_2(x))
    return x;
  x |= x >> 1;
  x |= x >> 2;
  x |= x >> 4;
  x |= x >> 8;
  x |= x >> 16;
  return x + 1;
}


x86 assembly (clang, -O0):
<next_pow_of_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <is_pow_of_2@plt>
cmp    $0x0,%rax
je     1138 <next_pow_of_2+0x28>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    117d <next_pow_of_2+0x6d>
mov    -0x8(%rbp),%eax
sar    $0x1,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x2,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x4,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_pow_of_2>:
push   %rbx
mov    %edi,%ebx
call   1030 <is_pow_of_2@plt>
test   %rax,%rax
jne    1142 <next_pow_of_2+0x32>
mov    %ebx,%eax
sar    %eax
or     %ebx,%eax
mov    %eax,%ecx
sar    $0x2,%ecx
or     %eax,%ecx
mov    %ecx,%eax
sar    $0x4,%eax
or     %ecx,%eax
mov    %eax,%ecx
sar    $0x8,%ecx
or     %eax,%ecx
mov    %ecx,%ebx
sar    $0x10,%ebx
or     %ecx,%ebx
add    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @next_pow_of_2(i32 %0) {
%2 = tail call i64 @is_pow_of_2(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = ashr i32 %0, 1
%6 = or i32 %5, %0
%7 = ashr i32 %6, 2
%8 = or i32 %7, %6
%9 = ashr i32 %8, 4
%10 = or i32 %9, %8
%11 = ashr i32 %10, 8
%12 = or i32 %11, %10
%13 = ashr i32 %12, 16
%14 = or i32 %13, %12
%15 = add nsw i32 %14, 1
br label %16
16: ; preds = %1, %4
%17 = phi i32 [ %15, %4 ], [ %0, %1 ]
ret i32 %17
}