#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 atoi(char *);
int /*<<< orphan*/ buprintv(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                            ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ leak(int);
int /*<<< orphan*/ o_d(int);
int /*<<< orphan*/ o_u(unsigned int);
int /*<<< orphan*/ rmem(unsigned int *, unsigned int *, int);
int main(int argc, char **argv) {
  unsigned int vsize, rss;
  if (argc > 1) {
    rmem(&vsize, &rss, atoi(argv[1]));
    buprintv(1, "%%: vsize=%% rss=%%\n", o_d(atoi(argv[1])), o_u(vsize),
             o_u(rss));
    exit(0);
  }
  leak(1000);
  rmem(&vsize, &rss, -1);
  rmem(&vsize, &rss, -1);
  buprintv(1, "START: vsize=%% rss=%%\n", o_u(vsize), o_u(rss));
  leak(60000);
  rmem(&vsize, &rss, -1);
  buprintv(1, "MID: vsize=%% rss=%%\n", o_u(vsize), o_u(rss));
  leak(60000);
  rmem(&vsize, &rss, -1);
  buprintv(1, "STOP: vsize=%% rss=%%\n", o_u(vsize), o_u(rss));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11f9 <main+0x89>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%edx
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <rmem@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1050 <o_d@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <o_u@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <o_u@plt>
mov    -0x20(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    %eax,%r8d
mov    $0x1,%edi
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1070 <buprintv@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x3e8,%edi
call   1040 <leak@plt>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xffffffff,%edx
call   1060 <rmem@plt>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xffffffff,%edx
call   1060 <rmem@plt>
mov    -0x14(%rbp),%edi
call   1030 <o_u@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <o_u@plt>
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1070 <buprintv@plt>
mov    $0xea60,%edi
call   1040 <leak@plt>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xffffffff,%edx
call   1060 <rmem@plt>
mov    -0x14(%rbp),%edi
call   1030 <o_u@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <o_u@plt>
mov    -0x28(%rbp),%edx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xd9b(%rip),%rsi
mov    $0x0,%al
call   1070 <buprintv@plt>
mov    $0xea60,%edi
call   1040 <leak@plt>
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xffffffff,%edx
call   1060 <rmem@plt>
mov    -0x14(%rbp),%edi
call   1030 <o_u@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <o_u@plt>
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
mov    $0x1,%edi
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1070 <buprintv@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jge    1275 <main+0x105>
mov    $0x3e8,%edi
call   1040 <leak@plt>
lea    0xc(%rsp),%rbx
lea    0x8(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xffffffff,%edx
call   1060 <rmem@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xffffffff,%edx
call   1060 <rmem@plt>
mov    0xc(%rsp),%edi
call   1030 <o_u@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%edi
call   1030 <o_u@plt>
lea    0xe45(%rip),%rsi
mov    $0x1,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <buprintv@plt>
mov    $0xea60,%edi
call   1040 <leak@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xffffffff,%edx
call   1060 <rmem@plt>
mov    0xc(%rsp),%edi
call   1030 <o_u@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%edi
call   1030 <o_u@plt>
lea    0xe18(%rip),%rsi
mov    $0x1,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <buprintv@plt>
mov    $0xea60,%edi
call   1040 <leak@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xffffffff,%edx
call   1060 <rmem@plt>
mov    0xc(%rsp),%edi
call   1030 <o_u@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%edi
call   1030 <o_u@plt>
lea    0xde9(%rip),%rsi
mov    $0x1,%edi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <buprintv@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %eax,%edx
call   1060 <rmem@plt>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1050 <o_d@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1030 <o_u@plt>
mov    %eax,%ebp
mov    0x8(%rsp),%edi
call   1030 <o_u@plt>
lea    0xd41(%rip),%rsi
mov    $0x1,%edi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <buprintv@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"%%: vsize=%% rss=%%\0A\00"
@.str.1 = [24 x i8] c"START: vsize=%% rss=%%\0A\00"
@.str.2 = [22 x i8] c"MID: vsize=%% rss=%%\0A\00"
@.str.3 = [23 x i8] c"STOP: vsize=%% rss=%%\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %27
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
%15 = call i32 @rmem(i32* %6, i32* %7, i32 %14)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
%20 = call i32 @o_d(i32 %19)
%21 = load i32, i32* %6
%22 = call i32 @o_u(i32 %21)
%23 = load i32, i32* %7
%24 = call i32 @o_u(i32 %23)
%25 = call i32 (i32, i8*, i32, i32, ...) @buprintv(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %22, i32 %24)
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %2
%28 = call i32 @leak(i32 1000)
%29 = call i32 @rmem(i32* %6, i32* %7, i32 -1)
%30 = call i32 @rmem(i32* %6, i32* %7, i32 -1)
%31 = load i32, i32* %6
%32 = call i32 @o_u(i32 %31)
%33 = load i32, i32* %7
%34 = call i32 @o_u(i32 %33)
%35 = call i32 (i32, i8*, i32, i32, ...) @buprintv(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %34)
%36 = call i32 @leak(i32 60000)
%37 = call i32 @rmem(i32* %6, i32* %7, i32 -1)
%38 = load i32, i32* %6
%39 = call i32 @o_u(i32 %38)
%40 = load i32, i32* %7
%41 = call i32 @o_u(i32 %40)
%42 = call i32 (i32, i8*, i32, i32, ...) @buprintv(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %39, i32 %41)
%43 = call i32 @leak(i32 60000)
%44 = call i32 @rmem(i32* %6, i32* %7, i32 -1)
%45 = load i32, i32* %6
%46 = call i32 @o_u(i32 %45)
%47 = load i32, i32* %7
%48 = call i32 @o_u(i32 %47)
%49 = call i32 (i32, i8*, i32, i32, ...) @buprintv(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %46, i32 %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"%%: vsize=%% rss=%%\0A\00"
@.str.1 = [24 x i8] c"START: vsize=%% rss=%%\0A\00"
@.str.2 = [22 x i8] c"MID: vsize=%% rss=%%\0A\00"
@.str.3 = [23 x i8] c"STOP: vsize=%% rss=%%\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %22
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = call i32 @rmem(i32* %3, i32* %4, i32 %11)
%13 = load i8*, i8** %9
%14 = call i32 @atoi(i8* %13)
%15 = call i32 @o_d(i32 %14)
%16 = load i32, i32* %3
%17 = call i32 @o_u(i32 %16)
%18 = load i32, i32* %4
%19 = call i32 @o_u(i32 %18)
%20 = call i32 (i32, i8*, i32, i32, ...) @buprintv(i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %17, i32 %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %2
%23 = tail call i32 @leak(i32 1000)
%24 = call i32 @rmem(i32* %3, i32* %4, i32 -1)
%25 = call i32 @rmem(i32* %3, i32* %4, i32 -1)
%26 = load i32, i32* %3
%27 = call i32 @o_u(i32 %26)
%28 = load i32, i32* %4
%29 = call i32 @o_u(i32 %28)
%30 = call i32 (i32, i8*, i32, i32, ...) @buprintv(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %29)
%31 = call i32 @leak(i32 60000)
%32 = call i32 @rmem(i32* %3, i32* %4, i32 -1)
%33 = load i32, i32* %3
%34 = call i32 @o_u(i32 %33)
%35 = load i32, i32* %4
%36 = call i32 @o_u(i32 %35)
%37 = call i32 (i32, i8*, i32, i32, ...) @buprintv(i32 1, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %36)
%38 = call i32 @leak(i32 60000)
%39 = call i32 @rmem(i32* %3, i32* %4, i32 -1)
%40 = load i32, i32* %3
%41 = call i32 @o_u(i32 %40)
%42 = load i32, i32* %4
%43 = call i32 @o_u(i32 %42)
%44 = call i32 (i32, i8*, i32, i32, ...) @buprintv(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %41, i32 %43)
ret i32 0
}