#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__ ENOSYS;
scalar_t__ EOVERFLOW;
int /*<<< orphan*/ cleanup();
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
long gethugepagesize();
int /*<<< orphan*/ printf(char *, ...);
char *strerror(scalar_t__);
long check_hugepagesize() {
  long hpage_size = gethugepagesize();
  if (hpage_size < 0) {
    if (errno == ENOSYS)
      do {
        cleanup();
        printf("Bad configuration: "
               "No hugepage kernel support\n"
               "\n");
        exit(1);
      } while (0);
    else if (errno == EOVERFLOW)
      do {
        cleanup();
        printf("Bad configuration: "
               "Hugepage size too large"
               "\n");
        exit(1);
      } while (0);
    else
      do {
        cleanup();
        printf("Bad configuration: "
               "Hugepage size (%s)"
               "\n",
               strerror(errno));
        exit(1);
      } while (0);
  }
  return hpage_size;
}


x86 assembly (clang, -O0):
<check_hugepagesize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <gethugepagesize@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1220 <check_hugepagesize+0xd0>
mov    0x2e5b(%rip),%rax
mov    (%rax),%rax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
jne    11ac <check_hugepagesize+0x5c>
jmp    118d <check_hugepagesize+0x3d>
mov    $0x0,%al
call   1050 <cleanup@plt>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%rax
jne    11ea <check_hugepagesize+0x9a>
jmp    11cb <check_hugepagesize+0x7b>
mov    $0x0,%al
call   1050 <cleanup@plt>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11ef <check_hugepagesize+0x9f>
mov    $0x0,%al
call   1050 <cleanup@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_hugepagesize>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <gethugepagesize@plt>
test   %rax,%rax
js     1177 <check_hugepagesize+0x17>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e52(%rip),%r14
mov    (%r14),%rbx
mov    0x2e58(%rip),%rax
cmp    (%rax),%rbx
jne    119d <check_hugepagesize+0x3d>
xor    %eax,%eax
call   1060 <cleanup@plt>
lea    0xeb7(%rip),%rdi
jmp    11ba <check_hugepagesize+0x5a>
mov    0x2e4c(%rip),%rax
mov    (%rax),%r15
xor    %eax,%eax
call   1060 <cleanup@plt>
cmp    %r15,%rbx
jne    11c9 <check_hugepagesize+0x69>
lea    0xe6d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    (%r14),%rdi
call   1080 <strerror@plt>
lea    0xe28(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ENOSYS = global i64 0
@.str = [48 x i8] c"Bad configuration: No hugepage kernel support\0A\0A\00"
@EOVERFLOW = global i64 0
@.str.1 = [44 x i8] c"Bad configuration: Hugepage size too large\0A\00"
@.str.2 = [39 x i8] c"Bad configuration: Hugepage size (%s)\0A\00"
define i64 @check_hugepagesize() {
%1 = alloca i64
%2 = call i64 (...) @gethugepagesize()
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %35
5: ; preds = %0
%6 = load i64, i64* @errno
%7 = load i64, i64* @ENOSYS
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %5
br label %10
10: ; preds = %9
%11 = call i32 (...) @cleanup()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; No predecessors!
br label %34
15: ; preds = %5
%16 = load i64, i64* @errno
%17 = load i64, i64* @EOVERFLOW
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %25
19: ; preds = %15
br label %20
20: ; preds = %19
%21 = call i32 (...) @cleanup()
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; No predecessors!
br label %33
25: ; preds = %15
br label %26
26: ; preds = %25
%27 = call i32 (...) @cleanup()
%28 = load i64, i64* @errno
%29 = call i8* @strerror(i64 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; No predecessors!
br label %33
33: ; preds = %32, %24
br label %34
34: ; preds = %33, %14
br label %35
35: ; preds = %34, %0
%36 = load i64, i64* %1
ret i64 %36
}

LLVM IR (-O2):
@errno = global i64 0
@ENOSYS = global i64 0
@EOVERFLOW = global i64 0
@.str.2 = [39 x i8] c"Bad configuration: Hugepage size (%s)\0A\00"
@str = [43 x i8] c"Bad configuration: Hugepage size too large\00"
@str.3 = [47 x i8] c"Bad configuration: No hugepage kernel support\0A\00"
define i64 @check_hugepagesize() {
%1 = tail call i64 (...) @gethugepagesize()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %23
3: ; preds = %0
%4 = load i64, i64* @errno
%5 = load i64, i64* @ENOSYS
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = tail call i32 (...) @cleanup()
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.3, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %3
%12 = load i64, i64* @EOVERFLOW
%13 = icmp eq i64 %4, %12
%14 = tail call i32 (...) @cleanup()
br i1 %13, label %15, label %18
15: ; preds = %11
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i64, i64* @errno
%20 = tail call i8* @strerror(i64 %19)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = tail call i32 @exit(i32 1)
unreachable
23: ; preds = %0
ret i64 %1
}