#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 SIZE_MAX;
size_t ULONG_MAX;
int __builtin_clzl(unsigned long);
int /*<<< orphan*/ assert(int);
size_t small_round(size_t size) {
  if (size < 2)
    return size;
  assert(size <= SIZE_MAX / 2 + 1);
  assert(size - 1 <= ULONG_MAX);
  size_t r = 1;
  return r << (sizeof(unsigned long) * CHAR_BIT -
               __builtin_clzl((unsigned long)(size - 1)));
}


x86 assembly (clang, -O0):
<small_round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x2,-0x10(%rbp)
jae    1134 <small_round+0x24>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bf <small_round+0xaf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e45(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x3,%rcx
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
bsr    %rdx,%rdx
xor    $0x3f,%rdx
movslq %edx,%rdx
sub    %rdx,%rcx
shl    %cl,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<small_round>:
push   %rbx
mov    %rdi,%rbx
cmp    $0x2,%rdi
jb     1176 <small_round+0x66>
mov    0x2eaf(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
add    $0x1,%ecx
movslq %ecx,%rax
xor    %edi,%edi
cmp    %rbx,%rax
setae  %dil
call   1030 <assert@plt>
add    $0xffffffffffffffff,%rbx
mov    0x2e7d(%rip),%rax
xor    %edi,%edi
cmp    (%rax),%rbx
setbe  %dil
call   1030 <assert@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%ecx
shl    $0x3,%ecx
bsr    %rbx,%rax
xor    $0x3f,%eax
sub    %eax,%ecx
mov    $0x1,%ebx
shl    %cl,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@SIZE_MAX = global i32 0
@ULONG_MAX = global i64 0
@CHAR_BIT = global i32 0
define i64 @small_round(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = icmp ult i64 %5, 2
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i64, i64* %3
store i64 %8, i64* %2
br label %35
9: ; preds = %1
%10 = load i64, i64* %3
%11 = load i32, i32* @SIZE_MAX
%12 = sdiv i32 %11, 2
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = icmp ule i64 %10, %14
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i64, i64* %3
%19 = sub i64 %18, 1
%20 = load i64, i64* @ULONG_MAX
%21 = icmp ule i64 %19, %20
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
store i64 1, i64* %4
%24 = load i64, i64* %4
%25 = load i32, i32* @CHAR_BIT
%26 = sext i32 %25 to i64
%27 = mul i64 8, %26
%28 = load i64, i64* %3
%29 = sub i64 %28, 1
%30 = call i64 @llvm.ctlz.i64(i64 %29, i1 true)
%31 = trunc i64 %30 to i32
%32 = sext i32 %31 to i64
%33 = sub i64 %27, %32
%34 = shl i64 %24, %33
store i64 %34, i64* %2
br label %35
35: ; preds = %9, %7
%36 = load i64, i64* %2
ret i64 %36
}

LLVM IR (-O2):
@SIZE_MAX = global i32 0
@ULONG_MAX = global i64 0
@CHAR_BIT = global i32 0
define i64 @small_round(i64 %0) {
%2 = icmp ult i64 %0, 2
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = load i32, i32* @SIZE_MAX
%5 = sdiv i32 %4, 2
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = icmp uge i64 %7, %0
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = add i64 %0, -1
%12 = load i64, i64* @ULONG_MAX
%13 = icmp ule i64 %11, %12
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = load i32, i32* @CHAR_BIT
%17 = sext i32 %16 to i64
%18 = shl nsw i64 %17, 3
%19 = tail call i64 @llvm.ctlz.i64(i64 %11, i1 true)
%20 = sub nsw i64 %18, %19
%21 = shl nuw i64 1, %20
br label %22
22: ; preds = %1, %3
%23 = phi i64 [ %21, %3 ], [ %0, %1 ]
ret i64 %23
}