#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*/ *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);
  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    0xe99(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118f <default_huge_page_size+0x4f>
movq   $0x0,-0x8(%rbp)
jmp    11f3 <default_huge_page_size+0xb3>
jmp    1194 <default_huge_page_size+0x54>
mov    -0x28(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <getline@plt>
cmp    $0x0,%rax
jle    11e2 <default_huge_page_size+0xa2>
mov    -0x18(%rbp),%rdi
lea    0xe56(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11dd <default_huge_page_size+0x9d>
mov    -0x10(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x10(%rbp)
jmp    11e2 <default_huge_page_size+0xa2>
jmp    1194 <default_huge_page_size+0x54>
mov    -0x18(%rbp),%rdi
call   1030 <free@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    0xe91(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11df <default_huge_page_size+0x9f>
mov    %rax,%rbx
lea    0x8(%rsp),%r14
lea    0x18(%rsp),%r15
lea    0xe7c(%rip),%r12
lea    0x10(%rsp),%r13
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <getline@plt>
test   %rax,%rax
jle    11ce <default_huge_page_size+0x8e>
mov    0x8(%rsp),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11a0 <default_huge_page_size+0x60>
shlq   $0xa,0x10(%rsp)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rax
jmp    11e1 <default_huge_page_size+0xa1>
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 %27
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 i64, i64* %2
store i64 %26, i64* %1
br label %27
27: ; preds = %23, %9
%28 = load i64, i64* %1
ret i64 %28
}

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 %23, 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 = load i64, i64* %1
br label %23
23: ; preds = %0, %19
%24 = phi i64 [ %22, %19 ], [ 0, %0 ]
ret i64 %24
}