#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ getdelim(char **, size_t *, char, int /*<<< orphan*/ *);
long getpagesize();
int sscanf(char *, char *, int *);
long huge_page_size(void) {
  size_t len = 0;
  char *line = NULL;
  FILE *f = fopen("/proc/meminfo", "r");
  if (f != NULL) {
    while (getdelim(&line, &len, '\n', f) > 0) {
      int ps;
      if (sscanf(line, "Hugepagesize: %d kB", &ps) == 1)
        return ps * 1024;
    }
    free(line);
    fclose(f);
  }
  return getpagesize();
}


x86 assembly (clang, -O0):
<huge_page_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe81(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1204 <huge_page_size+0xa4>
jmp    119f <huge_page_size+0x3f>
mov    -0x20(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1080 <getdelim@plt>
cmp    $0x0,%rax
jle    11f2 <huge_page_size+0x92>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11ed <huge_page_size+0x8d>
mov    -0x24(%rbp),%eax
shl    $0xa,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    120f <huge_page_size+0xaf>
jmp    119f <huge_page_size+0x3f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   1070 <getpagesize@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<huge_page_size>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x18(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe7a(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fa <huge_page_size+0x9a>
mov    %rax,%rbx
lea    0x8(%rsp),%r14
lea    0x18(%rsp),%r15
lea    0xe65(%rip),%r12
lea    0x14(%rsp),%r13
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
mov    %rbx,%rcx
call   1080 <getdelim@plt>
test   %rax,%rax
jle    11e8 <huge_page_size+0x88>
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11b0 <huge_page_size+0x50>
movslq 0x14(%rsp),%rax
shl    $0xa,%rax
jmp    1201 <huge_page_size+0xa1>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
call   1070 <getpagesize@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"Hugepagesize: %d kB\00"
define i64 @huge_page_size() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i64 0, i64* %2
store i8* null, i8** %3
%6 = 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* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %28
9: ; preds = %0
br label %10
10: ; preds = %22, %9
%11 = load i32*, i32** %4
%12 = call i64 @getdelim(i8** %3, i64* %2, i8 signext 10, i32* %11)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, 1024
%21 = sext i32 %20 to i64
store i64 %21, i64* %1
br label %30
22: ; preds = %14
br label %10
23: ; preds = %10
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = load i32*, i32** %4
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %23, %0
%29 = call i64 (...) @getpagesize()
store i64 %29, i64* %1
br label %30
30: ; preds = %28, %18
%31 = load i64, i64* %1
ret i64 %31
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [20 x i8] c"Hugepagesize: %d kB\00"
define i64 @huge_page_size() {
%1 = alloca i64
%2 = alloca i8*
%3 = alloca i32
%4 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%5 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%6 = 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))
%7 = icmp eq i32* %6, null
br i1 %7, label %22, label %8
8: ; preds = %0
%9 = bitcast i32* %3 to i8*
br label %10
10: ; preds = %8, %13
%11 = call i64 @getdelim(i8** %2, i64* %1, i8 signext 10, i32* %6)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i8*, i8** %2
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%16 = icmp eq i32 %15, 1
%17 = load i32, i32* %3
br i1 %16, label %24, label %10
18: ; preds = %10
%19 = load i8*, i8** %2
%20 = call i32 @free(i8* %19)
%21 = call i32 @fclose(i32* %6)
br label %22
22: ; preds = %18, %0
%23 = call i64 (...) @getpagesize()
br label %27
24: ; preds = %13
%25 = shl nsw i32 %17, 10
%26 = sext i32 %25 to i64
br label %27
27: ; preds = %24, %22
%28 = phi i64 [ %23, %22 ], [ %26, %24 ]
ret i64 %28
}