#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__ getline(char **, size_t *, int /*<<< orphan*/ *);
int sscanf(char *, char *, unsigned long *);
unsigned long default_huge_page_size(void) {
  unsigned long hps = 0;
  char *line = NULL;
  size_t linelen = 0;
  FILE *f = fopen("/proc/meminfo", "r");
  if (!f)
    return 0;
  while (getline(&line, &linelen, f) > 0) {
    if (sscanf(line, "Hugepagesize:       %lu kB", &hps) == 1) {
      hps <<= 10;
      break;
    }
  }
  free(line);
  fclose(f);
  return hps;
}


x86 assembly (clang, -O0):
<default_huge_page_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe89(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119f <default_huge_page_size+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    120c <default_huge_page_size+0xbc>
jmp    11a4 <default_huge_page_size+0x54>
mov    -0x28(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0x0,%rax
jle    11f2 <default_huge_page_size+0xa2>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11ed <default_huge_page_size+0x9d>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    11f2 <default_huge_page_size+0xa2>
jmp    11a4 <default_huge_page_size+0x54>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<default_huge_page_size>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe81(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f7 <default_huge_page_size+0xa7>
mov    %rax,%rbx
lea    0x8(%rsp),%r14
lea    0x18(%rsp),%r15
lea    0xe6c(%rip),%r12
lea    0x10(%rsp),%r13
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
test   %rax,%rax
jle    11de <default_huge_page_size+0x8e>
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    11b0 <default_huge_page_size+0x60>
shlq   $0xa,0x10(%rsp)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x10(%rsp),%rax
jmp    11f9 <default_huge_page_size+0xa9>
xor    %eax,%eax
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 = [27 x i8] c"Hugepagesize: %lu kB\00"
define i64 @default_huge_page_size() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
store i64 0, i64* %2
store i8* null, i8** %3
store i64 0, i64* %4
%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** %5
%7 = load i32*, i32** %5
%8 = icmp ne i32* %7, null
br i1 %8, label %10, label %9
9: ; preds = %0
store i64 0, i64* %1
br label %29
10: ; preds = %0
br label %11
11: ; preds = %22, %10
%12 = load i32*, i32** %5
%13 = call i64 @getline(i8** %3, i64* %4, i32* %12)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i64, i64* %2
%21 = shl i64 %20, 10
store i64 %21, i64* %2
br label %23
22: ; preds = %15
br label %11
23: ; preds = %19, %11
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
%28 = load i64, i64* %2
store i64 %28, i64* %1
br label %29
29: ; preds = %23, %9
%30 = load i64, i64* %1
ret i64 %30
}

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