#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 */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
unsigned long getpagesize();
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
void show(unsigned long ps) {
  char buf[100];
  if (ps == getpagesize()) {
    return;
  }
  printf("%luMB: ", ps >> 20);
  fflush(stdout);
  snprintf(buf, sizeof buf,
           "cat /sys/kernel/mm/hugepages/hugepages-%lukB/free_hugepages",
           ps >> 10);
  system(buf);
}


x86 assembly (clang, -O0):
<show>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1070 <getpagesize@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
cmp    %rcx,%rax
jne    1183 <show+0x33>
jmp    11cb <show+0x7b>
mov    -0x8(%rbp),%rsi
shr    $0x14,%rsi
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rcx
shr    $0xa,%rcx
mov    $0x64,%esi
lea    0xe4b(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <system@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <getpagesize@plt>
cmp    %rbx,%rax
je     11ad <show+0x5d>
mov    %rbx,%rsi
shr    $0x14,%rsi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
shr    $0xa,%rbx
lea    0xe76(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x64,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r14,%rdi
call   1030 <system@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%luMB: \00"
@stdout = global i32 0
@.str.1 = [60 x i8] c"cat /sys/kernel/mm/hugepages/hugepages-%lukB/free_hugepages\00"
define void @show(i64 %0) {
%2 = alloca i64
%3 = alloca [100 x i8]
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = call i64 (...) @getpagesize()
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %8
7: ; preds = %1
br label %20
8: ; preds = %1
%9 = load i64, i64* %2
%10 = lshr i64 %9, 20
%11 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = load i32, i32* @stdout
%13 = call i32 @fflush(i32 %12)
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%15 = load i64, i64* %2
%16 = lshr i64 %15, 10
%17 = call i32 @snprintf(i8* %14, i32 100, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i64 %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%19 = call i32 @system(i8* %18)
br label %20
20: ; preds = %8, %7
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%luMB: \00"
@stdout = global i32 0
@.str.1 = [60 x i8] c"cat /sys/kernel/mm/hugepages/hugepages-%lukB/free_hugepages\00"
define void @show(i64 %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i64 (...) @getpagesize()
%5 = icmp eq i64 %4, %0
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = lshr i64 %0, 20
%8 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
%11 = lshr i64 %0, 10
%12 = call i32 @snprintf(i8* %3, i32 100, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i64 %11)
%13 = call i32 @system(i8* %3)
br label %14
14: ; preds = %1, %6
ret void
}