#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 pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
unsigned int atoi(char *);
int /*<<< orphan*/ buclose(int);
int bugets(int, int /*<<< orphan*/ *, int, char *);
int /*<<< orphan*/ buprintv(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int getpid();
int /*<<< orphan*/ o_pid(int);
int /*<<< orphan*/ o_s(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintv_dup(char **, int, char *, int /*<<< orphan*/);
int rmem(unsigned int *vsize, unsigned int *rss, pid_t pid) {
  int fd, n;
  char *mstr;
  char buf[256], *p;
  if (pid == -1)
    pid = getpid();
  sprintv_dup(&mstr, 1024, "/proc/%%/stat", o_pid(pid));
  fd = open(mstr, O_RDONLY);
  if (fd < 0) {
    buprintv(2, "ERR open %%\n", o_s(mstr));
    exit(1);
  }
  if (bugets(fd, NULL, sizeof(buf), buf) < 8) {
    buprintv(2, "ERR read %%\n", o_s(mstr));
    exit(1);
  }
  p = buf;
  for (n = 0; n < 22; n++) {
    while (*p && *p != ' ')
      p++;
    if (*p)
      p++;
  }
  *vsize = atoi(p);
  while (*p && *p != ' ')
    p++;
  if (*p)
    p++;
  *rss = atoi(p);
  buclose(fd);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<rmem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11da <rmem+0x2a>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <o_pid@plt>
mov    %eax,%ecx
lea    -0x28(%rbp),%rdi
mov    $0x400,%esi
lea    0xe0c(%rip),%rdx
call   10a0 <sprintv_dup@plt>
mov    -0x28(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    123e <rmem+0x8e>
mov    -0x28(%rbp),%rdi
call   1040 <o_s@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xddf(%rip),%rsi
call   10b0 <buprintv@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x130(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%esi
mov    $0x100,%edx
call   1070 <bugets@plt>
cmp    $0x8,%eax
jge    1285 <rmem+0xd5>
mov    -0x28(%rbp),%rdi
call   1040 <o_s@plt>
mov    %eax,%edx
mov    $0x2,%edi
lea    0xda5(%rip),%rsi
call   10b0 <buprintv@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x130(%rbp),%rax
mov    %rax,-0x138(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x16,-0x1c(%rbp)
jge    1339 <rmem+0x189>
jmp    12a9 <rmem+0xf9>
mov    -0x138(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x139(%rbp)
je     12da <rmem+0x12a>
mov    -0x138(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x139(%rbp)
mov    -0x139(%rbp),%al
test   $0x1,%al
jne    12ed <rmem+0x13d>
jmp    1304 <rmem+0x154>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    12a9 <rmem+0xf9>
mov    -0x138(%rbp),%rax
cmpb   $0x0,(%rax)
je     1326 <rmem+0x176>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    132b <rmem+0x17b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    129a <rmem+0xea>
mov    -0x138(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x138(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x13a(%rbp)
je     137e <rmem+0x1ce>
mov    -0x138(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x13a(%rbp)
mov    -0x13a(%rbp),%al
test   $0x1,%al
jne    1391 <rmem+0x1e1>
jmp    13a8 <rmem+0x1f8>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
jmp    134d <rmem+0x19d>
mov    -0x138(%rbp),%rax
cmpb   $0x0,(%rax)
je     13ca <rmem+0x21a>
mov    -0x138(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%edi
call   1030 <buclose@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rmem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
cmp    $0xffffffff,%edx
jne    11d5 <rmem+0x25>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%edx
mov    %edx,%edi
call   1060 <o_pid@plt>
lea    0xe1d(%rip),%rdx
lea    0x8(%rsp),%rdi
mov    $0x400,%esi
mov    %eax,%ecx
call   10a0 <sprintv_dup@plt>
mov    0x8(%rsp),%rdi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
test   %eax,%eax
js     12f3 <rmem+0x143>
mov    %eax,%r12d
xor    %r13d,%r13d
lea    0x10(%rsp),%rbx
mov    %eax,%edi
xor    %esi,%esi
mov    $0x100,%edx
mov    %rbx,%rcx
call   1070 <bugets@plt>
cmp    $0x8,%eax
jge    1254 <rmem+0xa4>
mov    0x8(%rsp),%rdi
call   1040 <o_s@plt>
lea    0xdda(%rip),%rsi
jmp    1304 <rmem+0x154>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    (%rbx),%al
test   $0xdf,%al
jne    1250 <rmem+0xa0>
cmp    $0x1,%al
sbb    $0xffffffffffffffff,%rbx
mov    %rbx,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl 0x0(%rbp),%eax
test   $0xdf,%al
je     127e <rmem+0xce>
add    $0x1,%rbp
jmp    1270 <rmem+0xc0>
cmp    $0x1,%al
mov    %rbp,%rbx
sbb    $0xffffffffffffffff,%rbx
add    $0x2,%r13d
cmp    $0x16,%r13d
jne    1254 <rmem+0xa4>
cmp    $0x1,%al
sbb    $0xffffffffffffffff,%rbp
mov    %rbp,%rdi
call   10c0 <atoi@plt>
mov    %eax,(%r15)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0x0(%rbp),%eax
test   $0xdf,%al
je     12be <rmem+0x10e>
add    $0x1,%rbp
jmp    12b0 <rmem+0x100>
cmp    $0x1,%al
sbb    $0xffffffffffffffff,%rbp
mov    %rbp,%rdi
call   10c0 <atoi@plt>
mov    %eax,(%r14)
mov    %r12d,%edi
call   1030 <buclose@plt>
mov    %r12d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rsp),%rdi
call   1040 <o_s@plt>
lea    0xd0a(%rip),%rsi
mov    $0x2,%edi
mov    %eax,%edx
call   10b0 <buprintv@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/%%/stat\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"ERR open %%\0A\00"
@.str.2 = [13 x i8] c"ERR read %%\0A\00"
define i32 @rmem(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [256 x i8]
%11 = alloca i8*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = call i32 (...) @getpid()
store i32 %15, i32* %6
br label %16
16: ; preds = %14, %3
%17 = load i32, i32* %6
%18 = call i32 @o_pid(i32 %17)
%19 = call i32 @sprintv_dup(i8** %9, i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i8*, i8** %9
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %16
%26 = load i8*, i8** %9
%27 = call i32 @o_s(i8* %26)
%28 = call i32 @buprintv(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %16
%31 = load i32, i32* %7
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%33 = call i32 @bugets(i32 %31, i32* null, i32 256, i8* %32)
%34 = icmp slt i32 %33, 8
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i8*, i8** %9
%37 = call i32 @o_s(i8* %36)
%38 = call i32 @buprintv(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %30
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
store i8* %41, i8** %11
store i32 0, i32* %8
br label %42
42: ; preds = %69, %40
%43 = load i32, i32* %8
%44 = icmp slt i32 %43, 22
br i1 %44, label %45, label %72
45: ; preds = %42
br label %46
46: ; preds = %58, %45
%47 = load i8*, i8** %11
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %46
%52 = load i8*, i8** %11
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp ne i32 %54, 32
br label %56
56: ; preds = %51, %46
%57 = phi i1 [ false, %46 ], [ %55, %51 ]
br i1 %57, label %58, label %61
58: ; preds = %56
%59 = load i8*, i8** %11
%60 = getelementptr inbounds i8, i8* %59, i32 1
store i8* %60, i8** %11
br label %46
61: ; preds = %56
%62 = load i8*, i8** %11
%63 = load i8, i8* %62
%64 = icmp ne i8 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %61
%66 = load i8*, i8** %11
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %11
br label %68
68: ; preds = %65, %61
br label %69
69: ; preds = %68
%70 = load i32, i32* %8
%71 = add nsw i32 %70, 1
store i32 %71, i32* %8
br label %42
72: ; preds = %42
%73 = load i8*, i8** %11
%74 = call i32 @atoi(i8* %73)
%75 = load i32*, i32** %4
store i32 %74, i32* %75
br label %76
76: ; preds = %88, %72
%77 = load i8*, i8** %11
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %86
81: ; preds = %76
%82 = load i8*, i8** %11
%83 = load i8, i8* %82
%84 = sext i8 %83 to i32
%85 = icmp ne i32 %84, 32
br label %86
86: ; preds = %81, %76
%87 = phi i1 [ false, %76 ], [ %85, %81 ]
br i1 %87, label %88, label %91
88: ; preds = %86
%89 = load i8*, i8** %11
%90 = getelementptr inbounds i8, i8* %89, i32 1
store i8* %90, i8** %11
br label %76
91: ; preds = %86
%92 = load i8*, i8** %11
%93 = load i8, i8* %92
%94 = icmp ne i8 %93, 0
br i1 %94, label %95, label %98
95: ; preds = %91
%96 = load i8*, i8** %11
%97 = getelementptr inbounds i8, i8* %96, i32 1
store i8* %97, i8** %11
br label %98
98: ; preds = %95, %91
%99 = load i8*, i8** %11
%100 = call i32 @atoi(i8* %99)
%101 = load i32*, i32** %5
store i32 %100, i32* %101
%102 = load i32, i32* %7
%103 = call i32 @buclose(i32 %102)
%104 = load i32, i32* %7
%105 = call i32 @close(i32 %104)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/%%/stat\00"
@O_RDONLY = global i32 0
@.str.1 = [13 x i8] c"ERR open %%\0A\00"
@.str.2 = [13 x i8] c"ERR read %%\0A\00"
define i32 @rmem(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca i8*
%5 = alloca [256 x i8]
%6 = bitcast i8** %4 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = icmp eq i32 %2, -1
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 (...) @getpid()
br label %11
11: ; preds = %9, %3
%12 = phi i32 [ %10, %9 ], [ %2, %3 ]
%13 = tail call i32 @o_pid(i32 %12)
%14 = call i32 @sprintv_dup(i8** %4, i32 1024, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %4
%16 = load i32, i32* @O_RDONLY
%17 = call i32 @open(i8* %15, i32 %16)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %11
%20 = load i8*, i8** %4
%21 = call i32 @o_s(i8* %20)
%22 = call i32 @buprintv(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %11
%25 = call i32 @bugets(i32 %17, i32* null, i32 256, i8* %7)
%26 = icmp slt i32 %25, 8
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i8*, i8** %4
%29 = call i32 @o_s(i8* %28)
%30 = call i32 @buprintv(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %24, %47
%33 = phi i8* [ %50, %47 ], [ %7, %24 ]
%34 = phi i32 [ %51, %47 ], [ 0, %24 ]
br label %35
35: ; preds = %32, %38
%36 = phi i8* [ %39, %38 ], [ %33, %32 ]
%37 = load i8, i8* %36
switch i8 %37, label %38 [
i8 0, label %40
i8 32, label %40
]
38: ; preds = %35
%39 = getelementptr inbounds i8, i8* %36, i64 1
br label %35
40: ; preds = %35, %35
%41 = icmp ne i8 %37, 0
%42 = zext i1 %41 to i64
%43 = getelementptr i8, i8* %36, i64 %42
br label %44
44: ; preds = %53, %40
%45 = phi i8* [ %54, %53 ], [ %43, %40 ]
%46 = load i8, i8* %45
switch i8 %46, label %53 [
i8 0, label %47
i8 32, label %47
]
47: ; preds = %44, %44
%48 = icmp ne i8 %46, 0
%49 = zext i1 %48 to i64
%50 = getelementptr i8, i8* %45, i64 %49
%51 = add nuw nsw i32 %34, 2
%52 = icmp eq i32 %51, 22
br i1 %52, label %55, label %32
53: ; preds = %44
%54 = getelementptr inbounds i8, i8* %45, i64 1
br label %44
55: ; preds = %47
%56 = call i32 @atoi(i8* %50)
store i32 %56, i32* %0
br label %57
57: ; preds = %60, %55
%58 = phi i8* [ %50, %55 ], [ %61, %60 ]
%59 = load i8, i8* %58
switch i8 %59, label %60 [
i8 0, label %62
i8 32, label %62
]
60: ; preds = %57
%61 = getelementptr inbounds i8, i8* %58, i64 1
br label %57
62: ; preds = %57, %57
%63 = icmp ne i8 %59, 0
%64 = zext i1 %63 to i64
%65 = getelementptr i8, i8* %58, i64 %64
%66 = call i32 @atoi(i8* %65)
store i32 %66, i32* %1
%67 = call i32 @buclose(i32 %17)
%68 = call i32 @close(i32 %17)
ret i32 0
}