#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 const SIZE_MAX;
size_t upper_power_of_two(const size_t n) {
  size_t v = n;
  if (n <= 1)
    return 2;
  else if (SIZE_MAX == n)
    return SIZE_MAX;
  v--;
  v |= v >> 1;
  v |= v >> 2;
  v |= v >> 4;
  v |= v >> 8;
  v |= v >> 16;
  v++;
  return v;
}


x86 assembly (clang, -O0):
<upper_power_of_two>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x10(%rbp)
ja     1128 <upper_power_of_two+0x28>
movq   $0x2,-0x8(%rbp)
jmp    11c4 <upper_power_of_two+0xc4>
mov    0x2ea9(%rip),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
jne    114f <upper_power_of_two+0x4f>
mov    0x2e95(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11c4 <upper_power_of_two+0xc4>
jmp    1154 <upper_power_of_two+0x54>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x2,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x4,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x8,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x10,%rax
or     -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<upper_power_of_two>:
mov    $0x2,%eax
cmp    $0x2,%rdi
jb     1144 <upper_power_of_two+0x44>
add    $0xffffffffffffffff,%rdi
mov    %rdi,%rax
shr    %rax
or     %rdi,%rax
mov    %rax,%rcx
shr    $0x2,%rcx
or     %rax,%rcx
mov    %rcx,%rax
shr    $0x4,%rax
or     %rcx,%rax
mov    %rax,%rcx
shr    $0x8,%rcx
or     %rax,%rcx
mov    %rcx,%rax
shr    $0x10,%rax
or     %rcx,%rax
add    $0x1,%rax
ret

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

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