#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 */
struct dirent {
  char *d_name;
  int d_type;
};
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ CheckUsage(char *);
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ basename(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char const *);
int strlen(char *);
int main(int ac, char *av[]) {
  const char *AppName = av[1];
  if (AppName == NULL) {
    fprintf(stderr, "Usage %s Appname\n", (char *)basename(av[0]));
    exit(EXIT_FAILURE);
  }
  DIR *ProcDir = NULL;
  DIR *ProcDirDir = NULL;
  struct dirent *pDir = NULL;
  struct dirent *pDirDir = NULL;
  ProcDir = opendir("/proc");
  if (ProcDir == NULL) {
    fprintf(stderr, "Can't Open /proc directory \n");
    return 1;
  }
  char buf[128] = "";
  while ((pDir = readdir(ProcDir)) != NULL) {
    if (strlen(pDir->d_name) <= 2)
      continue;
    if (((int)pDir->d_type == 8) || ((int)pDir->d_type == 10))
      continue;
    sprintf(buf, "/proc/%s", pDir->d_name);
    ProcDirDir = opendir(buf);
    while ((pDirDir = readdir(ProcDirDir)) != NULL) {
      if (strlen(pDirDir->d_name) <= 2)
        continue;
      if ((pDirDir->d_type == 4) || (pDirDir->d_type == 10))
        continue;
      if (strcmp(pDirDir->d_name, "cmdline") == 0) {
        char cmdline[128] = "";
        sprintf(cmdline, "/proc/%s/%s", pDir->d_name, pDirDir->d_name);
        FILE *fp;
        fp = fopen(cmdline, "r");
        if (fp == NULL) {
          fprintf(stderr, "Can't open file %s \n", cmdline);
          closedir(ProcDirDir);
          closedir(ProcDir);
          exit(EXIT_FAILURE);
        }
        char *data = malloc(512 * sizeof(char));
        fgets(data, 512, fp);
        const char *cmd = (const char *)basename(data);
        free(data);
        if (strcmp(cmd, AppName) == 0) {
          sprintf(cmdline, "/proc/%s/statm", pDir->d_name);
          CheckUsage(cmdline);
        }
        fclose(fp);
      }
    }
    closedir(ProcDirDir);
  }
  closedir(ProcDir);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1270 <main+0x70>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x15c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10d0 <basename@plt>
mov    -0x15c(%rbp),%edi
mov    %rax,%rdx
lea    0xda5(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
lea    0xd7b(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12ce <main+0xce>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1528 <main+0x328>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1513 <main+0x313>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jg     1312 <main+0x112>
jmp    12e1 <main+0xe1>
mov    -0x30(%rbp),%rax
cmpl   $0x8,0x8(%rax)
je     132e <main+0x12e>
mov    -0x30(%rbp),%rax
cmpl   $0xa,0x8(%rax)
jne    1333 <main+0x133>
jmp    12e1 <main+0xe1>
lea    -0xc0(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
lea    0xced(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
lea    -0xc0(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10e0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1505 <main+0x305>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
cmp    $0x2,%eax
jg     1390 <main+0x190>
jmp    135f <main+0x15f>
mov    -0x38(%rbp),%rax
cmpl   $0x4,0x8(%rax)
je     13ac <main+0x1ac>
mov    -0x38(%rbp),%rax
cmpl   $0xa,0x8(%rax)
jne    13b1 <main+0x1b1>
jmp    135f <main+0x15f>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xc7f(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    1500 <main+0x300>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1070 <memset@plt>
lea    -0x140(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
mov    -0x38(%rbp),%rax
mov    (%rax),%rcx
lea    0xc49(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
lea    -0x140(%rbp),%rdi
lea    0xc40(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    146a <main+0x26a>
mov    0x2bad(%rip),%rax
mov    (%rax),%edi
lea    -0x140(%rbp),%rdx
lea    0xc11(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x20(%rbp),%rdi
call   1090 <closedir@plt>
mov    0x2b75(%rip),%rax
mov    (%rax),%edi
call   1120 <exit@plt>
mov    $0x200,%edi
call   10f0 <malloc@plt>
mov    %rax,-0x150(%rbp)
mov    -0x150(%rbp),%rdi
mov    -0x148(%rbp),%rdx
mov    $0x200,%esi
call   10a0 <fgets@plt>
mov    -0x150(%rbp),%rdi
call   10d0 <basename@plt>
mov    %rax,-0x158(%rbp)
mov    -0x150(%rbp),%rdi
call   1030 <free@plt>
mov    -0x158(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    14f4 <main+0x2f4>
lea    -0x140(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
lea    0xb88(%rip),%rsi
mov    $0x0,%al
call   1110 <sprintf@plt>
lea    -0x140(%rbp),%rdi
call   1080 <CheckUsage@plt>
mov    -0x148(%rbp),%rdi
call   1040 <fclose@plt>
jmp    135f <main+0x15f>
mov    -0x28(%rbp),%rdi
call   1090 <closedir@plt>
jmp    12e1 <main+0xe1>
mov    -0x20(%rbp),%rdi
call   1090 <closedir@plt>
mov    0x2aad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    0x8(%rsi),%rax
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1495 <main+0x2a5>
lea    0xdf8(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     1438 <main+0x248>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
mov    %rax,%rdi
call   10d0 <readdir@plt>
test   %rax,%rax
je     1425 <main+0x235>
mov    %rax,%rbp
lea    0xdb5(%rip),%r15
mov    %rbx,(%rsp)
jmp    12b4 <main+0xc4>
mov    %r12,%rdi
call   1080 <closedir@plt>
mov    (%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10d0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1425 <main+0x235>
mov    0x0(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x3,%eax
jl     12a0 <main+0xb0>
mov    0x8(%rbp),%eax
or     $0x2,%eax
cmp    $0xa,%eax
je     12a0 <main+0xb0>
mov    0x0(%rbp),%rdx
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
lea    0xd52(%rip),%rsi
xor    %eax,%eax
call   1100 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <opendir@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   10d0 <readdir@plt>
test   %rax,%rax
je     128f <main+0x9f>
mov    %rax,%r13
jmp    1324 <main+0x134>
mov    %r13,%rdi
call   1040 <fclose@plt>
nop
mov    %r12,%rdi
call   10d0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     128f <main+0x9f>
mov    0x0(%r13),%rdi
call   1060 <strlen@plt>
cmp    $0x3,%eax
jl     1310 <main+0x120>
mov    0x8(%r13),%eax
cmp    $0xa,%eax
je     1310 <main+0x120>
cmp    $0x4,%eax
je     1310 <main+0x120>
mov    0x0(%r13),%rdi
mov    %r15,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1310 <main+0x120>
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
mov    0x0(%rbp),%rdx
mov    0x0(%r13),%rcx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
lea    0xcb0(%rip),%rsi
xor    %eax,%eax
call   1100 <sprintf@plt>
mov    %rbx,%rdi
lea    0xcab(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1466 <main+0x276>
mov    %rax,%r13
mov    $0x200,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x200,%esi
mov    %r13,%rdx
call   1090 <fgets@plt>
mov    %rbx,%rdi
call   10c0 <basename@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
mov    0x8(%rsp),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1307 <main+0x117>
mov    0x0(%rbp),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
lea    0xc58(%rip),%rsi
xor    %eax,%eax
call   1100 <sprintf@plt>
mov    %rbx,%rdi
call   1070 <CheckUsage@plt>
jmp    1307 <main+0x117>
mov    %rbx,%rdi
call   1080 <closedir@plt>
mov    0x2b9c(%rip),%rax
mov    (%rax),%eax
jmp    1454 <main+0x264>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
lea    0xbd0(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
lea    0xbde(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r12,%rdi
call   1080 <closedir@plt>
mov    (%rsp),%rdi
call   1080 <closedir@plt>
jmp    14b9 <main+0x2c9>
mov    0x2b44(%rip),%rax
mov    (%rax),%ebx
mov    (%rsi),%rdi
call   10c0 <basename@plt>
lea    0xb53(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x2b18(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8*, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage %s Appname\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [29 x i8] c"Can't Open /proc directory \0A\00"
@.str.3 = [9 x i8] c"/proc/%s\00"
@.str.4 = [8 x i8] c"cmdline\00"
@.str.5 = [12 x i8] c"/proc/%s/%s\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [21 x i8] c"Can't open file %s \0A\00"
@.str.8 = [15 x i8] c"/proc/%s/statm\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca %struct.dirent*
%10 = alloca %struct.dirent*
%11 = alloca [128 x i8]
%12 = alloca [128 x i8]
%13 = alloca i32*
%14 = alloca i8*
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %31
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i64 @basename(i8* %25)
%27 = inttoptr i64 %26 to i8*
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %2
store i32* null, i32** %7
store i32* null, i32** %8
store %struct.dirent* null, %struct.dirent** %9
store %struct.dirent* null, %struct.dirent** %10
%32 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %7
%33 = load i32*, i32** %7
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %155
38: ; preds = %31
%39 = bitcast [128 x i8]* %11 to i8*
br label %40
40: ; preds = %148, %61, %50, %38
%41 = load i32*, i32** %7
%42 = call %struct.dirent* @readdir(i32* %41)
store %struct.dirent* %42, %struct.dirent** %9
%43 = icmp ne %struct.dirent* %42, null
br i1 %43, label %44, label %151
44: ; preds = %40
%45 = load %struct.dirent*, %struct.dirent** %9
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = call i32 @strlen(i8* %47)
%49 = icmp sle i32 %48, 2
br i1 %49, label %50, label %51
50: ; preds = %44
br label %40
51: ; preds = %44
%52 = load %struct.dirent*, %struct.dirent** %9
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = icmp eq i32 %54, 8
br i1 %55, label %61, label %56
56: ; preds = %51
%57 = load %struct.dirent*, %struct.dirent** %9
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 1
%59 = load i32, i32* %58
%60 = icmp eq i32 %59, 10
br i1 %60, label %61, label %62
61: ; preds = %56, %51
br label %40
62: ; preds = %56
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%64 = load %struct.dirent*, %struct.dirent** %9
%65 = getelementptr inbounds %struct.dirent, %struct.dirent* %64, i32 0, i32 0
%66 = load i8*, i8** %65
%67 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %63, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %66)
%68 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%69 = call i32* @opendir(i8* %68)
store i32* %69, i32** %8
br label %70
70: ; preds = %147, %91, %80, %62
%71 = load i32*, i32** %8
%72 = call %struct.dirent* @readdir(i32* %71)
store %struct.dirent* %72, %struct.dirent** %10
%73 = icmp ne %struct.dirent* %72, null
br i1 %73, label %74, label %148
74: ; preds = %70
%75 = load %struct.dirent*, %struct.dirent** %10
%76 = getelementptr inbounds %struct.dirent, %struct.dirent* %75, i32 0, i32 0
%77 = load i8*, i8** %76
%78 = call i32 @strlen(i8* %77)
%79 = icmp sle i32 %78, 2
br i1 %79, label %80, label %81
80: ; preds = %74
br label %70
81: ; preds = %74
%82 = load %struct.dirent*, %struct.dirent** %10
%83 = getelementptr inbounds %struct.dirent, %struct.dirent* %82, i32 0, i32 1
%84 = load i32, i32* %83
%85 = icmp eq i32 %84, 4
br i1 %85, label %91, label %86
86: ; preds = %81
%87 = load %struct.dirent*, %struct.dirent** %10
%88 = getelementptr inbounds %struct.dirent, %struct.dirent* %87, i32 0, i32 1
%89 = load i32, i32* %88
%90 = icmp eq i32 %89, 10
br i1 %90, label %91, label %92
91: ; preds = %86, %81
br label %70
92: ; preds = %86
%93 = load %struct.dirent*, %struct.dirent** %10
%94 = getelementptr inbounds %struct.dirent, %struct.dirent* %93, i32 0, i32 0
%95 = load i8*, i8** %94
%96 = call i64 @strcmp(i8* %95, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %147
98: ; preds = %92
%99 = bitcast [128 x i8]* %12 to i8*
%100 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%101 = load %struct.dirent*, %struct.dirent** %9
%102 = getelementptr inbounds %struct.dirent, %struct.dirent* %101, i32 0, i32 0
%103 = load i8*, i8** %102
%104 = load %struct.dirent*, %struct.dirent** %10
%105 = getelementptr inbounds %struct.dirent, %struct.dirent* %104, i32 0, i32 0
%106 = load i8*, i8** %105
%107 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %100, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %103, i8* %106)
%108 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%109 = call i32* @fopen(i8* %108, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %109, i32** %13
%110 = load i32*, i32** %13
%111 = icmp eq i32* %110, null
br i1 %111, label %112, label %122
112: ; preds = %98
%113 = load i32, i32* @stderr
%114 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %113, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %114)
%116 = load i32*, i32** %8
%117 = call i32 @closedir(i32* %116)
%118 = load i32*, i32** %7
%119 = call i32 @closedir(i32* %118)
%120 = load i32, i32* @EXIT_FAILURE
%121 = call i32 @exit(i32 %120)
unreachable
122: ; preds = %98
%123 = call i8* @malloc(i32 512)
store i8* %123, i8** %14
%124 = load i8*, i8** %14
%125 = load i32*, i32** %13
%126 = call i32 @fgets(i8* %124, i32 512, i32* %125)
%127 = load i8*, i8** %14
%128 = call i64 @basename(i8* %127)
%129 = inttoptr i64 %128 to i8*
store i8* %129, i8** %15
%130 = load i8*, i8** %14
%131 = call i32 @free(i8* %130)
%132 = load i8*, i8** %15
%133 = load i8*, i8** %6
%134 = call i64 @strcmp(i8* %132, i8* %133)
%135 = icmp eq i64 %134, 0
br i1 %135, label %136, label %144
136: ; preds = %122
%137 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%138 = load %struct.dirent*, %struct.dirent** %9
%139 = getelementptr inbounds %struct.dirent, %struct.dirent* %138, i32 0, i32 0
%140 = load i8*, i8** %139
%141 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %137, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %140)
%142 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%143 = call i32 @CheckUsage(i8* %142)
br label %144
144: ; preds = %136, %122
%145 = load i32*, i32** %13
%146 = call i32 @fclose(i32* %145)
br label %147
147: ; preds = %144, %92
br label %70
148: ; preds = %70
%149 = load i32*, i32** %8
%150 = call i32 @closedir(i32* %149)
br label %40
151: ; preds = %40
%152 = load i32*, i32** %7
%153 = call i32 @closedir(i32* %152)
%154 = load i32, i32* @EXIT_SUCCESS
store i32 %154, i32* %3
br label %155
155: ; preds = %151, %35
%156 = load i32, i32* %3
ret i32 %156
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage %s Appname\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"/proc\00"
@.str.2 = [29 x i8] c"Can't Open /proc directory \0A\00"
@.str.3 = [9 x i8] c"/proc/%s\00"
@.str.4 = [8 x i8] c"cmdline\00"
@.str.5 = [12 x i8] c"/proc/%s/%s\00"
@.str.6 = [2 x i8] c"r\00"
@.str.7 = [21 x i8] c"Can't open file %s \0A\00"
@.str.8 = [15 x i8] c"/proc/%s/statm\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %16
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i64 @basename(i8* %10)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %94
22: ; preds = %16
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%24 = call %struct.dirent* @readdir(i32* %17)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %91, label %26
26: ; preds = %22
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
br label %28
28: ; preds = %26, %37
%29 = phi %struct.dirent* [ %24, %26 ], [ %38, %37 ]
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @strlen(i8* %31)
%33 = icmp slt i32 %32, 3
br i1 %33, label %37, label %34
34: ; preds = %28
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i64 0, i32 1
%36 = load i32, i32* %35
switch i32 %36, label %40 [
i32 8, label %37
i32 10, label %37
]
37: ; preds = %34, %34, %89, %28
%38 = call %struct.dirent* @readdir(i32* %17)
%39 = icmp eq %struct.dirent* %38, null
br i1 %39, label %91, label %28
40: ; preds = %34
%41 = load i8*, i8** %30
%42 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = call i32* @opendir(i8* %23)
%44 = call %struct.dirent* @readdir(i32* %43)
%45 = icmp eq %struct.dirent* %44, null
br i1 %45, label %89, label %46
46: ; preds = %40, %55
%47 = phi %struct.dirent* [ %56, %55 ], [ %44, %40 ]
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i64 0, i32 0
%49 = load i8*, i8** %48
%50 = call i32 @strlen(i8* %49)
%51 = icmp slt i32 %50, 3
br i1 %51, label %55, label %52
52: ; preds = %46
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i64 0, i32 1
%54 = load i32, i32* %53
switch i32 %54, label %58 [
i32 4, label %55
i32 10, label %55
]
55: ; preds = %58, %87, %52, %52, %46
%56 = call %struct.dirent* @readdir(i32* %43)
%57 = icmp eq %struct.dirent* %56, null
br i1 %57, label %89, label %46
58: ; preds = %52
%59 = load i8*, i8** %48
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %55
62: ; preds = %58
%63 = load i8*, i8** %30
%64 = load i8*, i8** %48
%65 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %63, i8* %64)
%66 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%67 = icmp eq i32* %66, null
br i1 %67, label %68, label %75
68: ; preds = %62
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i8* %27)
%71 = call i32 @closedir(i32* %43)
%72 = call i32 @closedir(i32* %17)
%73 = load i32, i32* @EXIT_FAILURE
%74 = call i32 @exit(i32 %73)
unreachable
75: ; preds = %62
%76 = call dereferenceable_or_null(512) i8* @malloc(i32 512)
%77 = call i32 @fgets(i8* %76, i32 512, i32* %66)
%78 = call i64 @basename(i8* %76)
%79 = inttoptr i64 %78 to i8*
%80 = call i32 @free(i8* %76)
%81 = call i64 @strcmp(i8* %79, i8* %6)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %87
83: ; preds = %75
%84 = load i8*, i8** %30
%85 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i8* %84)
%86 = call i32 @CheckUsage(i8* %27)
br label %87
87: ; preds = %83, %75
%88 = call i32 @fclose(i32* %66)
br label %55
89: ; preds = %55, %40
%90 = call i32 @closedir(i32* %43)
br label %37
91: ; preds = %37, %22
%92 = call i32 @closedir(i32* %17)
%93 = load i32, i32* @EXIT_SUCCESS
br label %94
94: ; preds = %91, %19
%95 = phi i32 [ 1, %19 ], [ %93, %91 ]
ret i32 %95
}