#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 fscanf(int /*<<< orphan*/ *, char *, long *);
long my_vm_size() {
  FILE *f;
  long ret;
  ret = -1;
  if (!(f = fopen("/proc/self/statm", "r")))
    goto out;
  if (fscanf(f, "%ld", &ret) == 1)
    ret *= 0x1000;
out:
  if (f)
    fclose(f);
  return ret;
}


x86 assembly (clang, -O0):
<my_vm_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0xffffffffffffffff,-0x10(%rbp)
ff
lea    0xeb9(%rip),%rdi
lea    0xec3(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1166 <my_vm_size+0x36>
jmp    1194 <my_vm_size+0x64>
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    118f <my_vm_size+0x5f>
mov    -0x10(%rbp),%rax
shl    $0xc,%rax
mov    %rax,-0x10(%rbp)
jmp    1194 <my_vm_size+0x64>
cmpq   $0x0,-0x8(%rbp)
je     11a8 <my_vm_size+0x78>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_vm_size>:
push   %rbx
sub    $0x10,%rsp
movq   $0xffffffffffffffff,0x8(%rsp)
ff ff
lea    0xebb(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1187 <my_vm_size+0x57>
mov    %rax,%rbx
lea    0xeb3(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
cmp    $0x1,%eax
jne    1178 <my_vm_size+0x48>
shlq   $0xc,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rax
jmp    118e <my_vm_size+0x5e>
mov    $0xffffffffffffffff,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/proc/self/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%ld\00"
define i64 @my_vm_size() {
%1 = alloca i32*
%2 = alloca i64
store i64 -1, i64* %2
%3 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = icmp ne i32* %3, null
br i1 %4, label %6, label %5
5: ; preds = %0
br label %14
6: ; preds = %0
%7 = load i32*, i32** %1
%8 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i64, i64* %2
%12 = mul nsw i64 %11, 4096
store i64 %12, i64* %2
br label %13
13: ; preds = %10, %6
br label %14
14: ; preds = %13, %5
%15 = load i32*, i32** %1
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32*, i32** %1
%19 = call i32 @fclose(i32* %18)
br label %20
20: ; preds = %17, %14
%21 = load i64, i64* %2
ret i64 %21
}

LLVM IR (-O2):
@.str = [17 x i8] c"/proc/self/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%ld\00"
define i64 @my_vm_size() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
store i64 -1, i64* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %14, label %5
5: ; preds = %0
%6 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i64, i64* %1
%10 = shl nsw i64 %9, 12
store i64 %10, i64* %1
br label %11
11: ; preds = %8, %5
%12 = call i32 @fclose(i32* %3)
%13 = load i64, i64* %1
br label %14
14: ; preds = %0, %11
%15 = phi i64 [ -1, %0 ], [ %13, %11 ]
ret i64 %15
}