#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*/ NAME_MAX;
int /*<<< orphan*/ _SC_PAGE_SIZE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, unsigned long *);
int /*<<< orphan*/ sprintf(char *, char *, int);
unsigned long sysconf(int /*<<< orphan*/);
void get_mem(int c_pid, unsigned long *vsize) {
  char filename[NAME_MAX + 12];
  sprintf(filename, "/proc/%d/statm", c_pid);
  FILE *pst = fopen(filename, "r");
  int i;
  for (i = 0; i < 6; ++i)
    fscanf(pst, "%lu", vsize);
  *vsize *= sysconf(_SC_PAGE_SIZE);
  fclose(pst);
}


x86 assembly (clang, -O0):
<get_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
add    $0xc,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edx
lea    0xe68(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x6,-0x2c(%rbp)
jge    11e4 <get_mem+0x94>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe40(%rip),%rsi
call   1040 <fscanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b8 <get_mem+0x68>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
imul   (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mem>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%edx
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
add    $0xc,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
lea    0xe6d(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <fscanf@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
imul   (%r14),%rax
mov    %rax,(%r14)
mov    %rbx,%rdi
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

LLVM IR (-O0):
@NAME_MAX = global i32 0
@.str = [15 x i8] c"/proc/%d/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%lu\00"
@_SC_PAGE_SIZE = global i32 0
define void @get_mem(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i32
store i32 %0, i32* %3
store i64* %1, i64** %4
%9 = load i32, i32* @NAME_MAX
%10 = add nsw i32 %9, 12
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i8, i64 %11
store i64 %11, i64* %6
%14 = load i32, i32* %3
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %7
store i32 0, i32* %8
br label %17
17: ; preds = %24, %2
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 6
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32*, i32** %7
%22 = load i64*, i64** %4
%23 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %22)
br label %24
24: ; preds = %20
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %8
br label %17
27: ; preds = %17
%28 = load i32, i32* @_SC_PAGE_SIZE
%29 = call i64 @sysconf(i32 %28)
%30 = load i64*, i64** %4
%31 = load i64, i64* %30
%32 = mul i64 %31, %29
store i64 %32, i64* %30
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
%35 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
@NAME_MAX = global i32 0
@.str = [15 x i8] c"/proc/%d/statm\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [4 x i8] c"%lu\00"
@_SC_PAGE_SIZE = global i32 0
define void @get_mem(i32 %0, i64* %1) {
%3 = load i32, i32* @NAME_MAX
%4 = add nsw i32 %3, 12
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%10 = tail call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%11 = tail call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%12 = tail call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%13 = tail call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%14 = tail call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64* %1)
%15 = load i32, i32* @_SC_PAGE_SIZE
%16 = tail call i64 @sysconf(i32 %15)
%17 = load i64, i64* %1
%18 = mul i64 %17, %16
store i64 %18, i64* %1
%19 = tail call i32 @fclose(i32* %8)
ret void
}