#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 MAP_HUGETLB;
int MAP_HUGE_SHIFT;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t);
int /*<<< orphan*/ page_size_is_huge(size_t);
int /*<<< orphan*/ stderr;
int get_page_size_flags(size_t page_size) {
  int lg = 0;
  if (!page_size || (page_size & (page_size - 1))) {
    fprintf(stderr, "page size must be a power of 2: %zu\n", page_size);
    exit(1);
  }
  if (!page_size_is_huge(page_size)) {
    return 0;
  }
  while (page_size >>= 1) {
    ++lg;
  }
  return MAP_HUGETLB | (lg << MAP_HUGE_SHIFT);
}


x86 assembly (clang, -O0):
<get_page_size_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1167 <get_page_size_flags+0x37>
mov    -0x10(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     118a <get_page_size_flags+0x5a>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <page_size_is_huge@plt>
cmp    $0x0,%eax
jne    11a8 <get_page_size_flags+0x78>
movl   $0x0,-0x4(%rbp)
jmp    11ef <get_page_size_flags+0xbf>
jmp    11ad <get_page_size_flags+0x7d>
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11d1 <get_page_size_flags+0xa1>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ad <get_page_size_flags+0x7d>
mov    0x2e10(%rip),%rax
mov    (%rax),%eax
mov    -0x14(%rbp),%edx
mov    0x2e0c(%rip),%rcx
mov    (%rcx),%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_page_size_flags>:
push   %rbx
mov    %rdi,%rbx
lea    -0x1(%rdi),%rax
test   %rax,%rdi
sete   %al
test   %rdi,%rdi
setne  %cl
test   %al,%cl
je     1199 <get_page_size_flags+0x69>
mov    %rbx,%rdi
call   1030 <page_size_is_huge@plt>
test   %eax,%eax
je     1195 <get_page_size_flags+0x65>
xor    %eax,%eax
cmp    $0x2,%rbx
jb     117f <get_page_size_flags+0x4f>
xor    %eax,%eax
mov    %rbx,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
shr    %rcx
add    $0x1,%eax
cmp    $0x3,%rbx
mov    %rcx,%rbx
ja     1170 <get_page_size_flags+0x40>
mov    0x2e6a(%rip),%rcx
mov    (%rcx),%cl
shl    %cl,%eax
mov    0x2e57(%rip),%rcx
or     (%rcx),%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"page size must be a power of 2: %zu\0A\00"
@MAP_HUGETLB = global i32 0
@MAP_HUGE_SHIFT = global i32 0
define i32 @get_page_size_flags(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
store i64 %0, i64* %3
store i32 0, i32* %4
%5 = load i64, i64* %3
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i64, i64* %3
%9 = load i64, i64* %3
%10 = sub i64 %9, 1
%11 = and i64 %8, %10
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %7, %1
%14 = load i32, i32* @stderr
%15 = load i64, i64* %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %7
%19 = load i64, i64* %3
%20 = call i32 @page_size_is_huge(i64 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %18
store i32 0, i32* %2
br label %37
23: ; preds = %18
br label %24
24: ; preds = %28, %23
%25 = load i64, i64* %3
%26 = lshr i64 %25, 1
store i64 %26, i64* %3
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %24
31: ; preds = %24
%32 = load i32, i32* @MAP_HUGETLB
%33 = load i32, i32* %4
%34 = load i32, i32* @MAP_HUGE_SHIFT
%35 = shl i32 %33, %34
%36 = or i32 %32, %35
store i32 %36, i32* %2
br label %37
37: ; preds = %31, %22
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"page size must be a power of 2: %zu\0A\00"
@MAP_HUGETLB = global i32 0
@MAP_HUGE_SHIFT = global i32 0
define i32 @get_page_size_flags(i64 %0) {
%2 = tail call i64 @llvm.ctpop.i64(i64 %0)
%3 = icmp eq i64 %2, 1
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i64 %0)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i32 @page_size_is_huge(i64 %0)
%10 = icmp eq i32 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %8
%12 = icmp ult i64 %0, 2
br i1 %12, label %19, label %13
13: ; preds = %11, %13
%14 = phi i32 [ %17, %13 ], [ 0, %11 ]
%15 = phi i64 [ %16, %13 ], [ %0, %11 ]
%16 = lshr i64 %15, 1
%17 = add nuw nsw i32 %14, 1
%18 = icmp ult i64 %15, 4
br i1 %18, label %19, label %13
19: ; preds = %13, %11
%20 = phi i32 [ 0, %11 ], [ %17, %13 ]
%21 = load i32, i32* @MAP_HUGETLB
%22 = load i32, i32* @MAP_HUGE_SHIFT
%23 = shl i32 %20, %22
%24 = or i32 %23, %21
br label %25
25: ; preds = %8, %19
%26 = phi i32 [ %24, %19 ], [ 0, %8 ]
ret i32 %26
}