#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
double strtod(char *, int /*<<< orphan*/ *);
double get_huge_page_size_in_bytes() {
  double huge_page_size = 0;
  ;
  FILE *fs = fopen("/proc/meminfo", "r");
  if (!fs) {
    perror("Can't open /proc/meminfo");
    exit(EXIT_FAILURE);
  }
  char buf[128];
  while (fgets(buf, 128, fs)) {
    if (!strncmp("Hugepagesize", buf, 12)) {
      char *p = &buf[12];
      while ((!isdigit(*p)) && (p < buf + 128)) {
        p++;
      }
      huge_page_size = strtod(p, NULL);
      break;
    }
  }
  fclose(fs);
  return huge_page_size * (1024);
}


x86 assembly (clang, -O0):
<get_huge_page_size_in_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
lea    0xe7b(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cf <get_huge_page_size_in_bytes+0x4f>
lea    0xe4e(%rip),%rdi
call   1090 <perror@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    11d4 <get_huge_page_size_in_bytes+0x54>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12b2 <get_huge_page_size_in_bytes+0x132>
lea    -0x90(%rbp),%rsi
lea    0xe22(%rip),%rdi
mov    $0xc,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12ad <get_huge_page_size_in_bytes+0x12d>
lea    -0x90(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x99(%rbp)
jne    1269 <get_huge_page_size_in_bytes+0xe9>
mov    -0x98(%rbp),%rax
lea    -0x90(%rbp),%rcx
add    $0x80,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x99(%rbp)
mov    -0x99(%rbp),%al
test   $0x1,%al
jne    127c <get_huge_page_size_in_bytes+0xfc>
jmp    1293 <get_huge_page_size_in_bytes+0x113>
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
jmp    1226 <get_huge_page_size_in_bytes+0xa6>
mov    -0x98(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <strtod@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    12b2 <get_huge_page_size_in_bytes+0x132>
jmp    11d4 <get_huge_page_size_in_bytes+0x54>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
movsd  0xd3d(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_huge_page_size_in_bytes>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
lea    0xe82(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1252 <get_huge_page_size_in_bytes+0xd2>
mov    %rax,%r14
lea    0x10(%rsp),%rbx
lea    0xe6c(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     122d <get_huge_page_size_in_bytes+0xad>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11c0 <get_huge_page_size_in_bytes+0x40>
lea    0x1c(%rsp),%rbx
lea    0x90(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <isdigit@plt>
lea    0x1(%rbx),%rdi
test   %eax,%eax
jne    1218 <get_huge_page_size_in_bytes+0x98>
cmp    %r15,%rbx
mov    %rdi,%rbx
jb     1200 <get_huge_page_size_in_bytes+0x80>
add    $0xffffffffffffffff,%rdi
xor    %esi,%esi
call   1050 <strtod@plt>
mulsd  0xdd5(%rip),%xmm0
jmp    1231 <get_huge_page_size_in_bytes+0xb1>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
call   1060 <fclose@plt>
movsd  0x8(%rsp),%xmm0
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdb1(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Can't open /proc/meminfo\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"Hugepagesize\00"
define double @get_huge_page_size_in_bytes() {
%1 = alloca double
%2 = alloca i32*
%3 = alloca [128 x i8]
%4 = alloca i8*
store double 0.000000e+00, double* %1
%5 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
br label %13
13: ; preds = %42, %12
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%15 = load i32*, i32** %2
%16 = call i64 @fgets(i8* %14, i32 128, i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %43
18: ; preds = %13
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%20 = call i32 @strncmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %19, i32 12)
%21 = icmp ne i32 %20, 0
br i1 %21, label %42, label %22
22: ; preds = %18
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 12
store i8* %23, i8** %4
br label %24
24: ; preds = %36, %22
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = call i32 @isdigit(i8 signext %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%32 = getelementptr inbounds i8, i8* %31, i64 128
%33 = icmp ult i8* %30, %32
br label %34
34: ; preds = %29, %24
%35 = phi i1 [ false, %24 ], [ %33, %29 ]
br i1 %35, label %36, label %39
36: ; preds = %34
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
br label %24
39: ; preds = %34
%40 = load i8*, i8** %4
%41 = call double @strtod(i8* %40, i32* null)
store double %41, double* %1
br label %43
42: ; preds = %18
br label %13
43: ; preds = %39, %13
%44 = load i32*, i32** %2
%45 = call i32 @fclose(i32* %44)
%46 = load double, double* %1
%47 = fmul double %46, 1.024000e+03
ret double %47
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Can't open /proc/meminfo\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"Hugepagesize\00"
define double @get_huge_page_size_in_bytes() {
%1 = alloca [128 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
br label %10
10: ; preds = %13, %8
%11 = call i64 @fgets(i8* %9, i32 128, i32* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %30, label %13
13: ; preds = %10
%14 = call i32 @strncmp(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %9, i32 12)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %10
16: ; preds = %13
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 12
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 128
br label %19
19: ; preds = %19, %16
%20 = phi i8* [ %17, %16 ], [ %26, %19 ]
%21 = load i8, i8* %20
%22 = call i32 @isdigit(i8 signext %21)
%23 = icmp eq i32 %22, 0
%24 = icmp ult i8* %20, %18
%25 = select i1 %23, i1 %24, i1 false
%26 = getelementptr inbounds i8, i8* %20, i64 1
br i1 %25, label %19, label %27
27: ; preds = %19
%28 = call double @strtod(i8* nocapture %20, i32* null)
%29 = fmul double %28, 1.024000e+03
br label %30
30: ; preds = %10, %27
%31 = phi double [ %29, %27 ], [ 0.000000e+00, %10 ]
%32 = call i32 @fclose(i32* %2)
ret double %31
}