#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*/ O_RDONLY;
int /*<<< orphan*/ _SC_PAGESIZE;
int /*<<< orphan*/ close(int);
int getpid();
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *strchr(char *, char);
size_t strtoll(char *, int /*<<< orphan*/ *, int);
int sysconf(int /*<<< orphan*/);
size_t pmalloc_get_rss(void) {
  int page = sysconf(_SC_PAGESIZE), fd, count;
  size_t rss;
  char buf[4096], filename[256], *p, *x;
  snprintf(filename, 256, "/proc/%d/stat", getpid());
  if ((fd = open(filename, O_RDONLY)) == -1)
    return 0;
  if (read(fd, buf, 4096) <= 0) {
    close(fd);
    return 0;
  }
  close(fd);
  p = buf;
  count = 23;
  while (p && count--) {
    p = strchr(p, ' ');
    if (p)
      p++;
  }
  if (!p)
    return 0;
  x = strchr(p, ' ');
  if (!x)
    return 0;
  *x = '\0';
  rss = strtoll(p, NULL, 10);
  rss *= page;
  return rss;
}


x86 assembly (clang, -O0):
<pmalloc_get_rss>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1140,%rsp
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   10a0 <sysconf@plt>
mov    %eax,-0xc(%rbp)
lea    -0x1120(%rbp),%rax
mov    %rax,-0x1138(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x1138(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xe3a(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x1120(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    11f9 <pmalloc_get_rss+0x79>
movq   $0x0,-0x8(%rbp)
jmp    134c <pmalloc_get_rss+0x1cc>
mov    -0x10(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
cmp    $0x0,%rax
jg     122c <pmalloc_get_rss+0xac>
mov    -0x10(%rbp),%edi
call   1060 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    134c <pmalloc_get_rss+0x1cc>
mov    -0x10(%rbp),%edi
call   1060 <close@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1128(%rbp)
movl   $0x17,-0x14(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x1128(%rbp)
mov    %al,-0x1139(%rbp)
je     1276 <pmalloc_get_rss+0xf6>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1139(%rbp)
mov    -0x1139(%rbp),%al
test   $0x1,%al
jne    1289 <pmalloc_get_rss+0x109>
jmp    12c6 <pmalloc_get_rss+0x146>
mov    -0x1128(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x1128(%rbp)
cmpq   $0x0,-0x1128(%rbp)
je     12c1 <pmalloc_get_rss+0x141>
mov    -0x1128(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1128(%rbp)
jmp    1249 <pmalloc_get_rss+0xc9>
cmpq   $0x0,-0x1128(%rbp)
jne    12e1 <pmalloc_get_rss+0x161>
movq   $0x0,-0x8(%rbp)
jmp    134c <pmalloc_get_rss+0x1cc>
mov    -0x1128(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
mov    %rax,-0x1130(%rbp)
cmpq   $0x0,-0x1130(%rbp)
jne    1314 <pmalloc_get_rss+0x194>
movq   $0x0,-0x8(%rbp)
jmp    134c <pmalloc_get_rss+0x1cc>
mov    -0x1130(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1128(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtoll@plt>
mov    %rax,-0x20(%rbp)
movslq -0xc(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pmalloc_get_rss>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1100,%rsp
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   10a0 <sysconf@plt>
mov    %eax,%r14d
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe54(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1050 <snprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     147e <pmalloc_get_rss+0x2fe>
mov    %eax,%ebp
lea    0x100(%rsp),%rsi
mov    %eax,%edi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1060 <close@plt>
test   %rbx,%rbx
jle    147c <pmalloc_get_rss+0x2fc>
lea    0x100(%rsp),%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     147c <pmalloc_get_rss+0x2fc>
movb   $0x0,(%rax)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtoll@plt>
movslq %r14d,%rbx
imul   %rax,%rbx
jmp    147e <pmalloc_get_rss+0x2fe>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x1100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@_SC_PAGESIZE = global i32 0
@.str = [14 x i8] c"/proc/%d/stat\00"
@O_RDONLY = global i32 0
define i64 @pmalloc_get_rss() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca [4096 x i8]
%7 = alloca [256 x i8]
%8 = alloca i8*
%9 = alloca i8*
%10 = load i32, i32* @_SC_PAGESIZE
%11 = call i32 @sysconf(i32 %10)
store i32 %11, i32* %2
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%13 = call i32 (...) @getpid()
%14 = call i32 @snprintf(i8* %12, i32 256, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
store i32 %17, i32* %3
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %0
store i64 0, i64* %1
br label %69
20: ; preds = %0
%21 = load i32, i32* %3
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%23 = call i64 @read(i32 %21, i8* %22, i32 4096)
%24 = icmp sle i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* %3
%27 = call i32 @close(i32 %26)
store i64 0, i64* %1
br label %69
28: ; preds = %20
%29 = load i32, i32* %3
%30 = call i32 @close(i32 %29)
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
store i8* %31, i8** %8
store i32 23, i32* %4
br label %32
32: ; preds = %49, %28
%33 = load i8*, i8** %8
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* %4
%37 = add nsw i32 %36, -1
store i32 %37, i32* %4
%38 = icmp ne i32 %36, 0
br label %39
39: ; preds = %35, %32
%40 = phi i1 [ false, %32 ], [ %38, %35 ]
br i1 %40, label %41, label %50
41: ; preds = %39
%42 = load i8*, i8** %8
%43 = call i8* @strchr(i8* %42, i8 signext 32)
store i8* %43, i8** %8
%44 = load i8*, i8** %8
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i8*, i8** %8
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %8
br label %49
49: ; preds = %46, %41
br label %32
50: ; preds = %39
%51 = load i8*, i8** %8
%52 = icmp ne i8* %51, null
br i1 %52, label %54, label %53
53: ; preds = %50
store i64 0, i64* %1
br label %69
54: ; preds = %50
%55 = load i8*, i8** %8
%56 = call i8* @strchr(i8* %55, i8 signext 32)
store i8* %56, i8** %9
%57 = load i8*, i8** %9
%58 = icmp ne i8* %57, null
br i1 %58, label %60, label %59
59: ; preds = %54
store i64 0, i64* %1
br label %69
60: ; preds = %54
%61 = load i8*, i8** %9
store i8 0, i8* %61
%62 = load i8*, i8** %8
%63 = call i64 @strtoll(i8* %62, i32* null, i32 10)
store i64 %63, i64* %5
%64 = load i32, i32* %2
%65 = sext i32 %64 to i64
%66 = load i64, i64* %5
%67 = mul i64 %66, %65
store i64 %67, i64* %5
%68 = load i64, i64* %5
store i64 %68, i64* %1
br label %69
69: ; preds = %60, %59, %53, %25, %19
%70 = load i64, i64* %1
ret i64 %70
}

LLVM IR (-O2):
@_SC_PAGESIZE = global i32 0
@.str = [14 x i8] c"/proc/%d/stat\00"
@O_RDONLY = global i32 0
define i64 @pmalloc_get_rss() {
%1 = alloca [4096 x i8]
%2 = alloca [256 x i8]
%3 = load i32, i32* @_SC_PAGESIZE
%4 = tail call i32 @sysconf(i32 %3)
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = tail call i32 (...) @getpid()
%8 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* %6, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %115, label %12
12: ; preds = %0
%13 = call i64 @read(i32 %10, i8* %5, i32 4096)
%14 = icmp slt i64 %13, 1
%15 = call i32 @close(i32 %10)
br i1 %14, label %115, label %16
16: ; preds = %12
%17 = call i8* @strchr(i8* %5, i8 signext 32)
%18 = icmp eq i8* %17, null
%19 = getelementptr inbounds i8, i8* %17, i64 1
br i1 %18, label %115, label %20
20: ; preds = %16
%21 = call i8* @strchr(i8* %19, i8 signext 32)
%22 = icmp eq i8* %21, null
%23 = getelementptr inbounds i8, i8* %21, i64 1
br i1 %22, label %115, label %24
24: ; preds = %20
%25 = call i8* @strchr(i8* %23, i8 signext 32)
%26 = icmp eq i8* %25, null
%27 = getelementptr inbounds i8, i8* %25, i64 1
br i1 %26, label %115, label %28
28: ; preds = %24
%29 = call i8* @strchr(i8* %27, i8 signext 32)
%30 = icmp eq i8* %29, null
%31 = getelementptr inbounds i8, i8* %29, i64 1
br i1 %30, label %115, label %32
32: ; preds = %28
%33 = call i8* @strchr(i8* %31, i8 signext 32)
%34 = icmp eq i8* %33, null
%35 = getelementptr inbounds i8, i8* %33, i64 1
br i1 %34, label %115, label %36
36: ; preds = %32
%37 = call i8* @strchr(i8* %35, i8 signext 32)
%38 = icmp eq i8* %37, null
%39 = getelementptr inbounds i8, i8* %37, i64 1
br i1 %38, label %115, label %40
40: ; preds = %36
%41 = call i8* @strchr(i8* %39, i8 signext 32)
%42 = icmp eq i8* %41, null
%43 = getelementptr inbounds i8, i8* %41, i64 1
br i1 %42, label %115, label %44
44: ; preds = %40
%45 = call i8* @strchr(i8* %43, i8 signext 32)
%46 = icmp eq i8* %45, null
%47 = getelementptr inbounds i8, i8* %45, i64 1
br i1 %46, label %115, label %48
48: ; preds = %44
%49 = call i8* @strchr(i8* %47, i8 signext 32)
%50 = icmp eq i8* %49, null
%51 = getelementptr inbounds i8, i8* %49, i64 1
br i1 %50, label %115, label %52
52: ; preds = %48
%53 = call i8* @strchr(i8* %51, i8 signext 32)
%54 = icmp eq i8* %53, null
%55 = getelementptr inbounds i8, i8* %53, i64 1
br i1 %54, label %115, label %56
56: ; preds = %52
%57 = call i8* @strchr(i8* %55, i8 signext 32)
%58 = icmp eq i8* %57, null
%59 = getelementptr inbounds i8, i8* %57, i64 1
br i1 %58, label %115, label %60
60: ; preds = %56
%61 = call i8* @strchr(i8* %59, i8 signext 32)
%62 = icmp eq i8* %61, null
%63 = getelementptr inbounds i8, i8* %61, i64 1
br i1 %62, label %115, label %64
64: ; preds = %60
%65 = call i8* @strchr(i8* %63, i8 signext 32)
%66 = icmp eq i8* %65, null
%67 = getelementptr inbounds i8, i8* %65, i64 1
br i1 %66, label %115, label %68
68: ; preds = %64
%69 = call i8* @strchr(i8* %67, i8 signext 32)
%70 = icmp eq i8* %69, null
%71 = getelementptr inbounds i8, i8* %69, i64 1
br i1 %70, label %115, label %72
72: ; preds = %68
%73 = call i8* @strchr(i8* %71, i8 signext 32)
%74 = icmp eq i8* %73, null
%75 = getelementptr inbounds i8, i8* %73, i64 1
br i1 %74, label %115, label %76
76: ; preds = %72
%77 = call i8* @strchr(i8* %75, i8 signext 32)
%78 = icmp eq i8* %77, null
%79 = getelementptr inbounds i8, i8* %77, i64 1
br i1 %78, label %115, label %80
80: ; preds = %76
%81 = call i8* @strchr(i8* %79, i8 signext 32)
%82 = icmp eq i8* %81, null
%83 = getelementptr inbounds i8, i8* %81, i64 1
br i1 %82, label %115, label %84
84: ; preds = %80
%85 = call i8* @strchr(i8* %83, i8 signext 32)
%86 = icmp eq i8* %85, null
%87 = getelementptr inbounds i8, i8* %85, i64 1
br i1 %86, label %115, label %88
88: ; preds = %84
%89 = call i8* @strchr(i8* %87, i8 signext 32)
%90 = icmp eq i8* %89, null
%91 = getelementptr inbounds i8, i8* %89, i64 1
br i1 %90, label %115, label %92
92: ; preds = %88
%93 = call i8* @strchr(i8* %91, i8 signext 32)
%94 = icmp eq i8* %93, null
%95 = getelementptr inbounds i8, i8* %93, i64 1
br i1 %94, label %115, label %96
96: ; preds = %92
%97 = call i8* @strchr(i8* %95, i8 signext 32)
%98 = icmp eq i8* %97, null
%99 = getelementptr inbounds i8, i8* %97, i64 1
br i1 %98, label %115, label %100
100: ; preds = %96
%101 = call i8* @strchr(i8* %99, i8 signext 32)
%102 = icmp eq i8* %101, null
%103 = getelementptr inbounds i8, i8* %101, i64 1
br i1 %102, label %115, label %104
104: ; preds = %100
%105 = call i8* @strchr(i8* %103, i8 signext 32)
%106 = icmp eq i8* %105, null
br i1 %106, label %115, label %107
107: ; preds = %104
%108 = getelementptr inbounds i8, i8* %105, i64 1
%109 = call i8* @strchr(i8* %108, i8 signext 32)
%110 = icmp eq i8* %109, null
br i1 %110, label %115, label %111
111: ; preds = %107
store i8 0, i8* %109
%112 = call i64 @strtoll(i8* nocapture %108, i32* null, i32 10)
%113 = sext i32 %4 to i64
%114 = mul i64 %112, %113
br label %115
115: ; preds = %16, %20, %24, %28, %32, %36, %40, %44, %48, %52, %56, %60, %64, %68, %72, %76, %80, %84, %88, %92, %96, %100, %104, %12, %107, %0, %111
%116 = phi i64 [ %114, %111 ], [ 0, %0 ], [ 0, %107 ], [ 0, %12 ], [ 0, %104 ], [ 0, %100 ], [ 0, %96 ], [ 0, %92 ], [ 0, %88 ], [ 0, %84 ], [ 0, %80 ], [ 0, %76 ], [ 0, %72 ], [ 0, %68 ], [ 0, %64 ], [ 0, %60 ], [ 0, %56 ], [ 0, %52 ], [ 0, %48 ], [ 0, %44 ], [ 0, %40 ], [ 0, %36 ], [ 0, %32 ], [ 0, %28 ], [ 0, %24 ], [ 0, %20 ], [ 0, %16 ]
ret i64 %116
}