#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 CHAR_BIT;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
unsigned int log2_floor(unsigned int);
int /*<<< orphan*/ stderr;
unsigned int smallest_power_of_2_that_holds(unsigned int x) {
  unsigned int exp;
  if (x == 0)
    return 1;
  if (x > (1U << (sizeof(unsigned int) * CHAR_BIT - 1))) {
    fprintf(stderr,
            "error: %u doesn't fit in largest power of 2 an unsigned int can "
            "hold\n",
            x);
    exit(1);
  }
  exp = log2_floor(x);
  return 1U << exp == x ? x : 1U << (exp + 1);
}


x86 assembly (clang, -O0):
<smallest_power_of_2_that_holds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1151 <smallest_power_of_2_that_holds+0x21>
movl   $0x1,-0x4(%rbp)
jmp    11d8 <smallest_power_of_2_that_holds+0xa8>
mov    -0x8(%rbp),%eax
mov    0x2e85(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x2,%rcx
sub    $0x1,%rcx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jbe    1199 <smallest_power_of_2_that_holds+0x69>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%edi
call   1030 <log2_floor@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cmp    -0x8(%rbp),%eax
jne    11c2 <smallest_power_of_2_that_holds+0x92>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11d2 <smallest_power_of_2_that_holds+0xa2>
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smallest_power_of_2_that_holds>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
je     1174 <smallest_power_of_2_that_holds+0x44>
mov    %edi,%ebx
mov    0x2ea0(%rip),%rax
mov    (%rax),%cl
shl    $0x2,%cl
add    $0xff,%cl
mov    $0x1,%ebp
mov    $0x1,%eax
shl    %cl,%eax
cmp    %edi,%eax
jb     1182 <smallest_power_of_2_that_holds+0x52>
mov    %ebx,%edi
call   1030 <log2_floor@plt>
mov    $0x1,%edx
mov    %eax,%ecx
shl    %cl,%edx
lea    0x1(%rax),%ecx
shl    %cl,%ebp
cmp    %ebx,%edx
cmove  %ebx,%ebp
jmp    1179 <smallest_power_of_2_that_holds+0x49>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@stderr = global i32 0
@.str = [70 x i8] c"error: %u doesn't fit in largest power of 2 an unsigned int can hold\0A\00"
define i32 @smallest_power_of_2_that_holds(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %37
8: ; preds = %1
%9 = load i32, i32* %3
%10 = load i32, i32* @CHAR_BIT
%11 = sext i32 %10 to i64
%12 = mul i64 4, %11
%13 = sub i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = shl i32 1, %14
%16 = icmp ugt i32 %9, %15
br i1 %16, label %17, label %22
17: ; preds = %8
%18 = load i32, i32* @stderr
%19 = load i32, i32* %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %8
%23 = load i32, i32* %3
%24 = call i32 @log2_floor(i32 %23)
store i32 %24, i32* %4
%25 = load i32, i32* %4
%26 = shl i32 1, %25
%27 = load i32, i32* %3
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = load i32, i32* %3
br label %35
31: ; preds = %22
%32 = load i32, i32* %4
%33 = add i32 %32, 1
%34 = shl i32 1, %33
br label %35
35: ; preds = %31, %29
%36 = phi i32 [ %30, %29 ], [ %34, %31 ]
store i32 %36, i32* %2
br label %37
37: ; preds = %35, %7
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@stderr = global i32 0
@.str = [70 x i8] c"error: %u doesn't fit in largest power of 2 an unsigned int can hold\0A\00"
define i32 @smallest_power_of_2_that_holds(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %20, label %3
3: ; preds = %1
%4 = load i32, i32* @CHAR_BIT
%5 = shl i32 %4, 2
%6 = add i32 %5, -1
%7 = shl nuw i32 1, %6
%8 = icmp ult i32 %7, %0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %0)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %3
%14 = tail call i32 @log2_floor(i32 %0)
%15 = shl nuw i32 1, %14
%16 = icmp eq i32 %15, %0
%17 = add i32 %14, 1
%18 = shl nuw i32 1, %17
%19 = select i1 %16, i32 %0, i32 %18
br label %20
20: ; preds = %1, %13
%21 = phi i32 [ %19, %13 ], [ 1, %1 ]
ret i32 %21
}