#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_of_2(size_t x) {
  if (x == 0)
    return 1;
  if (x == (x & (x >> 1)))
    return x;
  size_t y = x;
  size_t z = x >> 1;
  while (z) {
    y |= z;
    z >>= 1;
  }
  return y + 1;
}


x86 assembly (clang, -O0):
<next_power_of_2>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1120 <next_power_of_2+0x20>
movq   $0x1,-0x8(%rbp)
jmp    1191 <next_power_of_2+0x91>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x10(%rbp),%rdx
shr    $0x1,%rdx
and    %rdx,%rcx
cmp    %rcx,%rax
jne    1149 <next_power_of_2+0x49>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1191 <next_power_of_2+0x91>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1185 <next_power_of_2+0x85>
mov    -0x20(%rbp),%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <next_power_of_2+0x5d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_power_of_2>:
test   %rdi,%rdi
je     1147 <next_power_of_2+0x47>
mov    %rdi,%rcx
shr    %rcx
mov    %rcx,%rax
not    %rax
test   %rax,%rdi
je     1143 <next_power_of_2+0x43>
mov    $0x2,%eax
cmp    $0x2,%rdi
jb     1146 <next_power_of_2+0x46>
mov    %rcx,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
or     %rcx,%rdi
shr    %rax
cmp    $0x1,%rcx
mov    %rax,%rcx
ja     1130 <next_power_of_2+0x30>
add    $0x1,%rdi
mov    %rdi,%rax
ret
mov    $0x1,%eax
ret

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

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