#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 INT_MAX;
int RoundUpToPowerOfTwo(int value) {
  if (value <= 0) {
    return 0;
  } else if (value > INT_MAX / 2) {
    value = INT_MAX / 2;
  }
  int result = 1;
  while (result < value) {
    result *= 2;
  }
  return result;
}


x86 assembly (clang, -O0):
<RoundUpToPowerOfTwo>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     111d <RoundUpToPowerOfTwo+0x1d>
movl   $0x0,-0x4(%rbp)
jmp    1181 <RoundUpToPowerOfTwo+0x81>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2ebe(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cmp    %ecx,%eax
jle    1155 <RoundUpToPowerOfTwo+0x55>
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    115a <RoundUpToPowerOfTwo+0x5a>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    117b <RoundUpToPowerOfTwo+0x7b>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1161 <RoundUpToPowerOfTwo+0x61>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<RoundUpToPowerOfTwo>:
test   %edi,%edi
jle    112a <RoundUpToPowerOfTwo+0x2a>
mov    0x2edd(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
cmp    %edi,%ecx
cmovge %edi,%ecx
mov    $0x1,%edx
mov    %edx,%eax
lea    (%rax,%rax,1),%edx
cmp    %ecx,%eax
jl     1120 <RoundUpToPowerOfTwo+0x20>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
define i32 @RoundUpToPowerOfTwo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp sle i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %27
8: ; preds = %1
%9 = load i32, i32* %3
%10 = load i32, i32* @INT_MAX
%11 = sdiv i32 %10, 2
%12 = icmp sgt i32 %9, %11
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @INT_MAX
%15 = sdiv i32 %14, 2
store i32 %15, i32* %3
br label %16
16: ; preds = %13, %8
br label %17
17: ; preds = %16
store i32 1, i32* %4
br label %18
18: ; preds = %22, %17
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %4
%24 = mul nsw i32 %23, 2
store i32 %24, i32* %4
br label %18
25: ; preds = %18
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %7
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@INT_MAX = global i32 0
define i32 @RoundUpToPowerOfTwo(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = load i32, i32* @INT_MAX
%5 = sdiv i32 %4, 2
%6 = icmp slt i32 %5, %0
%7 = select i1 %6, i32 %5, i32 %0
br label %8
8: ; preds = %8, %3
%9 = phi i32 [ 1, %3 ], [ %11, %8 ]
%10 = icmp slt i32 %9, %7
%11 = shl nsw i32 %9, 1
br i1 %10, label %8, label %12
12: ; preds = %8, %1
%13 = phi i32 [ 0, %1 ], [ %9, %8 ]
ret i32 %13
}