#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 PAGE_SIZE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *, int *);
int virtual_size(char *statm_name) {
  FILE *statm = fopen(statm_name, "r");
  if (statm != NULL) {
    int vm, rss, res = fscanf(statm, "%d %d", &vm, &rss);
    fclose(statm);
    if (res == 2)
      return vm * PAGE_SIZE;
  }
  return 0;
}


x86 assembly (clang, -O0):
<virtual_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a3 <virtual_size+0x73>
mov    -0x18(%rbp),%rdi
lea    0xe9c(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1040 <fscanf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x2,-0x24(%rbp)
jne    119e <virtual_size+0x6e>
mov    -0x1c(%rbp),%eax
mov    0x2e55(%rip),%rcx
imul   (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <virtual_size+0x7a>
jmp    11a3 <virtual_size+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<virtual_size>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     117c <virtual_size+0x4c>
mov    %rax,%rbx
lea    0xeb4(%rip),%rsi
mov    %rsp,%rdx
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x2,%ebp
jne    117c <virtual_size+0x4c>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
imul   (%rsp),%eax
jmp    117e <virtual_size+0x4e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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