#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 IPC_CREAT;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ SHM_RDONLY;
int /*<<< orphan*/ getc(int /*<<< orphan*/);
int getpid();
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(void *, int, int);
void *shmat(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ shmctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int shmget(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  void *addr, *memblock = NULL;
  int shmid, counter = 0;
  char cmd[64];
  while (1) {
    memblock = (void *)malloc(1024 * 1024);
    if (!memblock || counter == 6144)
      break;
    if (counter % 6 == 0)
      memset(memblock, 1, 1024 * 1024);
    counter++;
  }
  shmid = shmget(IPC_PRIVATE, 42, IPC_CREAT | 0666);
  if (shmid == -1)
    return -1;
  addr = shmat(shmid, NULL, SHM_RDONLY);
  sprintf(cmd, "grep -E \"Vm(Size|RSS|PTE)|Name|Pid\" /proc/%d/status",
          getpid());
  system(cmd);
  getc(stdin);
  shmctl(shmid, IPC_RMID, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    $0x100000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11de <main+0x4e>
cmpl   $0x1800,-0x28(%rbp)
jne    11e3 <main+0x53>
jmp    1218 <main+0x88>
mov    -0x28(%rbp),%eax
mov    $0x6,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    120a <main+0x7a>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
call   1050 <memset@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b8 <main+0x28>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
mov    0x2d98(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x2a,%esi
call   1090 <shmget@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1253 <main+0xc3>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c0 <main+0x130>
mov    -0x24(%rbp),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <shmat@plt>
mov    %rax,-0x18(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%edx
lea    0xd78(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <system@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10b0 <getc@plt>
mov    -0x24(%rbp),%edi
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <shmctl@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    $0x100000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1204 <main+0x74>
xor    %ebp,%ebp
mov    $0xaaaaaaab,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%ecx
imul   %r14,%rcx
shr    $0x22,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%ecx
add    %ebp,%ecx
jne    11e5 <main+0x55>
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
call   1050 <memset@plt>
mov    $0x100000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1204 <main+0x74>
add    $0x1,%ebx
lea    -0x1(%rbp),%ecx
cmp    $0xffffe801,%ebp
mov    %ecx,%ebp
jne    11c0 <main+0x30>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    0x2dac(%rip),%rax
mov    $0x1b6,%edx
or     (%rax),%edx
mov    $0x2a,%esi
call   1090 <shmget@plt>
cmp    $0xffffffff,%eax
je     1286 <main+0xf6>
mov    %eax,%ebp
mov    0x2d9d(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %ebp,%edi
xor    %esi,%esi
call   1080 <shmat@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdb1(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
call   10b0 <getc@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1070 <shmctl@plt>
jmp    128c <main+0xfc>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@SHM_RDONLY = global i32 0
@.str = [52 x i8] c"grep -E \22Vm(Size|RSS|PTE)|Name|Pid\22 /proc/%d/status\00"
@stdin = global i32 0
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i32 0, i32* %9
br label %11
11: ; preds = %2, %27
%12 = call i64 @malloc(i32 1048576)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %9
%18 = icmp eq i32 %17, 6144
br i1 %18, label %19, label %20
19: ; preds = %16, %11
br label %30
20: ; preds = %16
%21 = load i32, i32* %9
%22 = srem i32 %21, 6
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i8*, i8** %7
%26 = call i32 @memset(i8* %25, i32 1, i32 1048576)
br label %27
27: ; preds = %24, %20
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
br label %11
30: ; preds = %19
%31 = load i32, i32* @IPC_PRIVATE
%32 = load i32, i32* @IPC_CREAT
%33 = or i32 %32, 438
%34 = call i32 @shmget(i32 %31, i32 42, i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %30
store i32 -1, i32* %3
br label %52
38: ; preds = %30
%39 = load i32, i32* %8
%40 = load i32, i32* @SHM_RDONLY
%41 = call i8* @shmat(i32 %39, i32* null, i32 %40)
store i8* %41, i8** %6
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%43 = call i32 (...) @getpid()
%44 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%46 = call i32 @system(i8* %45)
%47 = load i32, i32* @stdin
%48 = call i32 @getc(i32 %47)
%49 = load i32, i32* %8
%50 = load i32, i32* @IPC_RMID
%51 = call i32 @shmctl(i32 %49, i32 %50, i32* null)
store i32 0, i32* %3
br label %52
52: ; preds = %38, %37
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@IPC_PRIVATE = global i32 0
@IPC_CREAT = global i32 0
@SHM_RDONLY = global i32 0
@.str = [52 x i8] c"grep -E \22Vm(Size|RSS|PTE)|Name|Pid\22 /proc/%d/status\00"
@stdin = global i32 0
@IPC_RMID = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @malloc(i32 1048576)
%6 = icmp eq i64 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %2, %15
%8 = phi i64 [ %17, %15 ], [ %5, %2 ]
%9 = phi i32 [ %16, %15 ], [ 0, %2 ]
%10 = urem i32 %9, 6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = inttoptr i64 %8 to i8*
%14 = tail call i32 @memset(i8* %13, i32 1, i32 1048576)
br label %15
15: ; preds = %12, %7
%16 = add nuw nsw i32 %9, 1
%17 = tail call i64 @malloc(i32 1048576)
%18 = icmp eq i64 %17, 0
%19 = icmp eq i32 %16, 6144
%20 = select i1 %18, i1 true, i1 %19
br i1 %20, label %21, label %7
21: ; preds = %15, %2
%22 = load i32, i32* @IPC_PRIVATE
%23 = load i32, i32* @IPC_CREAT
%24 = or i32 %23, 438
%25 = tail call i32 @shmget(i32 %22, i32 42, i32 %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %37, label %27
27: ; preds = %21
%28 = load i32, i32* @SHM_RDONLY
%29 = tail call i8* @shmat(i32 %25, i32* null, i32 %28)
%30 = tail call i32 (...) @getpid()
%31 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i32 %30)
%32 = call i32 @system(i8* %4)
%33 = load i32, i32* @stdin
%34 = tail call i32 @getc(i32 %33)
%35 = load i32, i32* @IPC_RMID
%36 = tail call i32 @shmctl(i32 %25, i32 %35, i32* null)
br label %37
37: ; preds = %21, %27
%38 = phi i32 [ 0, %27 ], [ -1, %21 ]
ret i32 %38
}