#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 */
scalar_t__ is_power_of_two(int);
int least_larger_power_of_two(int n) {
  int i;
  if (n < 0)
    return 1;
  if (is_power_of_two(n))
    return n;
  i = 0;
  while ((n >> i) != 0)
    i++;
  return (1 << i);
}


x86 assembly (clang, -O0):
<least_larger_power_of_two>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1131 <least_larger_power_of_two+0x21>
movl   $0x1,-0x4(%rbp)
jmp    1181 <least_larger_power_of_two+0x71>
mov    -0x8(%rbp),%edi
call   1030 <is_power_of_two@plt>
cmp    $0x0,%rax
je     114e <least_larger_power_of_two+0x3e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1181 <least_larger_power_of_two+0x71>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sar    %cl,%eax
cmp    $0x0,%eax
je     1174 <least_larger_power_of_two+0x64>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <least_larger_power_of_two+0x45>
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<least_larger_power_of_two>:
push   %rbx
test   %edi,%edi
js     1144 <least_larger_power_of_two+0x34>
mov    %edi,%ebx
call   1030 <is_power_of_two@plt>
test   %rax,%rax
jne    1149 <least_larger_power_of_two+0x39>
mov    $0xffffffff,%ecx
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ecx
mov    %ebx,%eax
sar    %cl,%eax
test   %eax,%eax
jne    1130 <least_larger_power_of_two+0x20>
mov    $0x1,%ebx
shl    %cl,%ebx
jmp    1149 <least_larger_power_of_two+0x39>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

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

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