#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;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ ENOTDIR;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int close(int);
int closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ helpAndLeave(char *, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ pexit(char *);
int /*<<< orphan*/ printProcessInfo(int, char *, char *);
int /*<<< orphan*/ printf(char *, char *, char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int readlink(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, ...);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    helpAndLeave(argv[0], EXIT_FAILURE);
  }
  char *filename = argv[1];
  char pathname[(512)], buf[(512)];
  int statusFd;
  ssize_t numRead;
  DIR *proc, *procpid;
  struct dirent *procpid_d, *procpidfd_d;
  proc = opendir(("/proc"));
  if (proc == NULL) {
    pexit("opendir");
  }
  printf("%8s%5s%20s\n", "PID", "FD", "COMMAND");
  for (errno = 0; (procpid_d = readdir(proc)) != NULL; errno = 0) {
    if (strncmp(procpid_d->d_name, "self", 4) == 0) {
      continue;
    }
    snprintf(buf, (512), "%s/%s/status", ("/proc"), procpid_d->d_name);
    statusFd = open(buf, O_RDONLY);
    if (statusFd == -1) {
      if (errno != ENOENT && errno != ENOTDIR) {
        pexit("open");
      }
      continue;
    }
    snprintf(buf, (512), "%s/%s/fd", ("/proc"), procpid_d->d_name);
    procpid = opendir(buf);
    if (procpid == NULL) {
      pexit("opendir");
    }
    for (errno = 0; (procpidfd_d = readdir(procpid)) != NULL; errno = 0) {
      if (strncmp(procpidfd_d->d_name, ".", 1) == 0 ||
          strncmp(procpidfd_d->d_name, "..", 2) == 0) {
        continue;
      }
      snprintf(pathname, (512), "%s/%s/fd/%s", ("/proc"), procpid_d->d_name,
               procpidfd_d->d_name);
      numRead = readlink(pathname, buf, (512));
      if (numRead == -1) {
        pexit("readlink");
      }
      buf[numRead] = '\0';
      if (strncmp(buf, filename, (512)) == 0) {
        printProcessInfo(statusFd, procpidfd_d->d_name, procpid_d->d_name);
      }
    }
    if (errno != 0) {
      pexit("readdir");
    }
    if (closedir(procpid) == -1) {
      pexit("closedir");
    }
    if (close(statusFd) == -1) {
      pexit("close");
    }
  }
  if (errno != 0) {
    pexit("readdir");
  }
  if (closedir(proc) == -1) {
    pexit("closedir");
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f8 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   10d0 <helpAndLeave@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
lea    0xdf5(%rip),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jne    1231 <main+0x71>
lea    0xdda(%rip),%rdi
call   10e0 <pexit@plt>
lea    0xdd6(%rip),%rdi
lea    0xddb(%rip),%rsi
lea    0xdd8(%rip),%rdx
lea    0xdd4(%rip),%rcx
call   1070 <printf@plt>
mov    0x2d77(%rip),%rax
movq   $0x0,(%rax)
mov    -0x430(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x440(%rbp)
cmp    $0x0,%rax
je     1558 <main+0x398>
mov    -0x440(%rbp),%rax
mov    (%rax),%rdi
lea    0xd9b(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12a7 <main+0xe7>
jmp    1545 <main+0x385>
lea    -0x420(%rbp),%rdi
mov    -0x440(%rbp),%rax
mov    (%rax),%r8
mov    $0x200,%esi
lea    0xd6a(%rip),%rdx
lea    0xd35(%rip),%rcx
mov    $0x0,%al
call   1080 <snprintf@plt>
lea    -0x420(%rbp),%rdi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    133f <main+0x17f>
mov    0x2ccf(%rip),%rax
mov    (%rax),%rax
mov    0x2ca5(%rip),%rcx
cmp    (%rcx),%rax
je     133a <main+0x17a>
mov    0x2cb5(%rip),%rax
mov    (%rax),%rax
mov    0x2cd3(%rip),%rcx
cmp    (%rcx),%rax
je     133a <main+0x17a>
lea    0xd06(%rip),%rdi
call   10e0 <pexit@plt>
jmp    1545 <main+0x385>
lea    -0x420(%rbp),%rdi
mov    -0x440(%rbp),%rax
mov    (%rax),%r8
mov    $0x200,%esi
lea    0xce4(%rip),%rdx
lea    0xc9d(%rip),%rcx
mov    $0x0,%al
call   1080 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    1397 <main+0x1d7>
lea    0xc74(%rip),%rdi
call   10e0 <pexit@plt>
mov    0x2c32(%rip),%rax
movq   $0x0,(%rax)
mov    -0x438(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x448(%rbp)
cmp    $0x0,%rax
je     14e2 <main+0x322>
mov    -0x448(%rbp),%rax
mov    (%rax),%rdi
lea    0xc77(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     140c <main+0x24c>
mov    -0x448(%rbp),%rax
mov    (%rax),%rdi
lea    0xc51(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1411 <main+0x251>
jmp    14cf <main+0x30f>
lea    -0x220(%rbp),%rdi
mov    -0x440(%rbp),%rax
mov    (%rax),%r8
mov    -0x448(%rbp),%rax
mov    (%rax),%r9
mov    $0x200,%esi
lea    0xc14(%rip),%rdx
lea    0xbc1(%rip),%rcx
mov    $0x0,%al
call   1080 <snprintf@plt>
lea    -0x220(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
call   1050 <readlink@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0xffffffff,-0x428(%rbp)
jne    147d <main+0x2bd>
lea    0xbe0(%rip),%rdi
call   10e0 <pexit@plt>
movslq -0x428(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x200,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    14ca <main+0x30a>
mov    -0x424(%rbp),%edi
mov    -0x448(%rbp),%rax
mov    (%rax),%rsi
mov    -0x440(%rbp),%rax
mov    (%rax),%rdx
call   1040 <printProcessInfo@plt>
jmp    14cf <main+0x30f>
mov    0x2afa(%rip),%rax
movq   $0x0,(%rax)
jmp    13a5 <main+0x1e5>
mov    0x2ae7(%rip),%rax
cmpq   $0x0,(%rax)
je     14ff <main+0x33f>
lea    0xb67(%rip),%rdi
call   10e0 <pexit@plt>
mov    -0x438(%rbp),%rdi
call   10a0 <closedir@plt>
cmp    $0xffffffff,%eax
jne    1520 <main+0x360>
lea    0xb4e(%rip),%rdi
call   10e0 <pexit@plt>
mov    -0x424(%rbp),%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
jne    1540 <main+0x380>
lea    0xb37(%rip),%rdi
call   10e0 <pexit@plt>
jmp    1545 <main+0x385>
mov    0x2a84(%rip),%rax
movq   $0x0,(%rax)
jmp    1260 <main+0xa0>
mov    0x2a71(%rip),%rax
cmpq   $0x0,(%rax)
je     1575 <main+0x3b5>
lea    0xaf1(%rip),%rdi
call   10e0 <pexit@plt>
mov    -0x430(%rbp),%rdi
call   10a0 <closedir@plt>
cmp    $0xffffffff,%eax
jne    1596 <main+0x3d6>
lea    0xad8(%rip),%rdi
call   10e0 <pexit@plt>
mov    0x2a23(%rip),%rax
mov    (%rax),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     11ea <main+0x2a>
mov    (%rbx),%rdi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
call   10d0 <helpAndLeave@plt>
mov    0x8(%rbx),%rax
mov    %rax,0x18(%rsp)
lea    0xe06(%rip),%rdi
call   1060 <opendir@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1213 <main+0x53>
lea    0xdf8(%rip),%rdi
call   10e0 <pexit@plt>
lea    0xdf4(%rip),%rdi
lea    0xdf9(%rip),%rsi
lea    0xdf6(%rip),%rdx
lea    0xdf2(%rip),%rcx
call   1070 <printf@plt>
mov    0x2d95(%rip),%rbx
movq   $0x0,(%rbx)
mov    %r15,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     14bf <main+0x2ff>
mov    %rax,%r13
lea    0xdcc(%rip),%r14
lea    0xd9c(%rip),%r12
mov    %r15,0x10(%rsp)
jmp    1290 <main+0xd0>
nopl   0x0(%rax,%rax,1)
call   10e0 <pexit@plt>
movq   $0x0,(%rbx)
mov    %r15,%rdi
call   10b0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     14bf <main+0x2ff>
mov    0x0(%r13),%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1275 <main+0xb5>
mov    0x0(%r13),%r8
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x200,%esi
lea    0xd70(%rip),%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10c0 <open@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     1490 <main+0x2d0>
mov    0x0(%r13),%r8
mov    %rbp,%rdi
mov    $0x200,%esi
lea    0xd47(%rip),%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    %rbp,%rdi
call   1060 <opendir@plt>
mov    %rax,%r15
test   %rax,%rax
mov    %rbp,%r12
jne    1322 <main+0x162>
lea    0xce9(%rip),%rdi
call   10e0 <pexit@plt>
movq   $0x0,(%rbx)
mov    %r15,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
lea    0xd0f(%rip),%rbp
je     1430 <main+0x270>
mov    %rax,%r14
jmp    136b <main+0x1ab>
cs nopw 0x0(%rax,%rax,1)
movq   $0x0,(%rbx)
mov    %r15,%rdi
call   10b0 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     1430 <main+0x270>
mov    (%r14),%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1350 <main+0x190>
mov    (%r14),%rdi
lea    0xcbf(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1350 <main+0x190>
mov    0x0(%r13),%r8
mov    (%r14),%r9
lea    0x220(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x200,%esi
lea    0xc95(%rip),%rdx
lea    0xc42(%rip),%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    $0x200,%edx
call   1050 <readlink@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    13e8 <main+0x228>
lea    0xc75(%rip),%rdi
call   10e0 <pexit@plt>
movslq %ebp,%rax
movb   $0x0,0x20(%rsp,%rax,1)
mov    %r12,%rdi
mov    0x18(%rsp),%rsi
mov    $0x200,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
lea    0xc3e(%rip),%rbp
jne    1350 <main+0x190>
mov    (%r14),%rsi
mov    0x0(%r13),%rdx
mov    0xc(%rsp),%edi
call   1040 <printProcessInfo@plt>
jmp    1350 <main+0x190>
nopw   0x0(%rax,%rax,1)
cmpq   $0x0,(%rbx)
lea    0xbee(%rip),%r14
je     1449 <main+0x289>
lea    0xc1d(%rip),%rdi
call   10e0 <pexit@plt>
mov    %r15,%rdi
call   10a0 <closedir@plt>
cmp    $0xffffffff,%eax
lea    0xba5(%rip),%r12
jne    1469 <main+0x2a9>
lea    0xc05(%rip),%rdi
call   10e0 <pexit@plt>
mov    0xc(%rsp),%edi
call   1090 <close@plt>
lea    0xbf9(%rip),%rdi
cmp    $0xffffffff,%eax
mov    0x10(%rsp),%r15
jne    1275 <main+0xb5>
jmp    1270 <main+0xb0>
nopl   0x0(%rax)
mov    (%rbx),%rax
mov    0x2b16(%rip),%rcx
cmp    (%rcx),%rax
je     1275 <main+0xb5>
lea    0xb91(%rip),%rdi
mov    0x2b47(%rip),%rcx
cmp    (%rcx),%rax
jne    1270 <main+0xb0>
jmp    1275 <main+0xb5>
cmpq   $0x0,(%rbx)
je     14d1 <main+0x311>
lea    0xb95(%rip),%rdi
call   10e0 <pexit@plt>
mov    %r15,%rdi
call   10a0 <closedir@plt>
cmp    $0xffffffff,%eax
jne    14ea <main+0x32a>
lea    0xb84(%rip),%rdi
call   10e0 <pexit@plt>
mov    0x2acf(%rip),%rax
mov    (%rax),%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@EXIT_FAILURE = global i32 0
@.str = [6 x i8] c"/proc\00"
@.str.1 = [8 x i8] c"opendir\00"
@.str.2 = [12 x i8] c"%8s%5s%20s\0A\00"
@.str.3 = [4 x i8] c"PID\00"
@.str.4 = [3 x i8] c"FD\00"
@.str.5 = [8 x i8] c"COMMAND\00"
@errno = global i64 0
@.str.6 = [5 x i8] c"self\00"
@.str.7 = [13 x i8] c"%s/%s/status\00"
@O_RDONLY = global i32 0
@ENOENT = global i64 0
@ENOTDIR = global i64 0
@.str.8 = [5 x i8] c"open\00"
@.str.9 = [9 x i8] c"%s/%s/fd\00"
@.str.10 = [2 x i8] c".\00"
@.str.11 = [3 x i8] c"..\00"
@.str.12 = [12 x i8] c"%s/%s/fd/%s\00"
@.str.13 = [9 x i8] c"readlink\00"
@.str.14 = [8 x i8] c"readdir\00"
@.str.15 = [9 x i8] c"closedir\00"
@.str.16 = [6 x i8] c"close\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 [512 x i8]
%8 = alloca [512 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca %struct.dirent*
%14 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @helpAndLeave(i8* %20, i32 %21)
br label %23
23: ; preds = %17, %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %6
%27 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %11
%28 = load i32*, i32** %11
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %23
%33 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i64 0, i64* @errno
br label %34
34: ; preds = %150, %32
%35 = load i32*, i32** %11
%36 = call %struct.dirent* @readdir(i32* %35)
store %struct.dirent* %36, %struct.dirent** %13
%37 = icmp ne %struct.dirent* %36, null
br i1 %37, label %38, label %151
38: ; preds = %34
%39 = load %struct.dirent*, %struct.dirent** %13
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
br label %150
45: ; preds = %38
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%47 = load %struct.dirent*, %struct.dirent** %13
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 0
%49 = load i8*, i8** %48
%50 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %46, i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %49)
%51 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* @O_RDONLY
%53 = call i32 @open(i8* %51, i32 %52)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %67
56: ; preds = %45
%57 = load i64, i64* @errno
%58 = load i64, i64* @ENOENT
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %66
60: ; preds = %56
%61 = load i64, i64* @errno
%62 = load i64, i64* @ENOTDIR
%63 = icmp ne i64 %61, %62
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 @pexit(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %66
66: ; preds = %64, %60, %56
br label %150
67: ; preds = %45
%68 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%69 = load %struct.dirent*, %struct.dirent** %13
%70 = getelementptr inbounds %struct.dirent, %struct.dirent* %69, i32 0, i32 0
%71 = load i8*, i8** %70
%72 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %68, i32 512, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %71)
%73 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%74 = call i32* @opendir(i8* %73)
store i32* %74, i32** %12
%75 = load i32*, i32** %12
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %79
77: ; preds = %67
%78 = call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %79
79: ; preds = %77, %67
store i64 0, i64* @errno
br label %80
80: ; preds = %131, %79
%81 = load i32*, i32** %12
%82 = call %struct.dirent* @readdir(i32* %81)
store %struct.dirent* %82, %struct.dirent** %14
%83 = icmp ne %struct.dirent* %82, null
br i1 %83, label %84, label %132
84: ; preds = %80
%85 = load %struct.dirent*, %struct.dirent** %14
%86 = getelementptr inbounds %struct.dirent, %struct.dirent* %85, i32 0, i32 0
%87 = load i8*, i8** %86
%88 = call i64 @strncmp(i8* %87, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 1)
%89 = icmp eq i64 %88, 0
br i1 %89, label %96, label %90
90: ; preds = %84
%91 = load %struct.dirent*, %struct.dirent** %14
%92 = getelementptr inbounds %struct.dirent, %struct.dirent* %91, i32 0, i32 0
%93 = load i8*, i8** %92
%94 = call i64 @strncmp(i8* %93, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i32 2)
%95 = icmp eq i64 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %90, %84
br label %131
97: ; preds = %90
%98 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%99 = load %struct.dirent*, %struct.dirent** %13
%100 = getelementptr inbounds %struct.dirent, %struct.dirent* %99, i32 0, i32 0
%101 = load i8*, i8** %100
%102 = load %struct.dirent*, %struct.dirent** %14
%103 = getelementptr inbounds %struct.dirent, %struct.dirent* %102, i32 0, i32 0
%104 = load i8*, i8** %103
%105 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %98, i32 512, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %101, i8* %104)
%106 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%107 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%108 = call i32 @readlink(i8* %106, i8* %107, i32 512)
store i32 %108, i32* %10
%109 = load i32, i32* %10
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %113
111: ; preds = %97
%112 = call i32 @pexit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
br label %113
113: ; preds = %111, %97
%114 = load i32, i32* %10
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %115
store i8 0, i8* %116
%117 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%118 = load i8*, i8** %6
%119 = call i64 @strncmp(i8* %117, i8* %118, i32 512)
%120 = icmp eq i64 %119, 0
br i1 %120, label %121, label %130
121: ; preds = %113
%122 = load i32, i32* %9
%123 = load %struct.dirent*, %struct.dirent** %14
%124 = getelementptr inbounds %struct.dirent, %struct.dirent* %123, i32 0, i32 0
%125 = load i8*, i8** %124
%126 = load %struct.dirent*, %struct.dirent** %13
%127 = getelementptr inbounds %struct.dirent, %struct.dirent* %126, i32 0, i32 0
%128 = load i8*, i8** %127
%129 = call i32 @printProcessInfo(i32 %122, i8* %125, i8* %128)
br label %130
130: ; preds = %121, %113
br label %131
131: ; preds = %130, %96
store i64 0, i64* @errno
br label %80
132: ; preds = %80
%133 = load i64, i64* @errno
%134 = icmp ne i64 %133, 0
br i1 %134, label %135, label %137
135: ; preds = %132
%136 = call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
br label %137
137: ; preds = %135, %132
%138 = load i32*, i32** %12
%139 = call i32 @closedir(i32* %138)
%140 = icmp eq i32 %139, -1
br i1 %140, label %141, label %143
141: ; preds = %137
%142 = call i32 @pexit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0))
br label %143
143: ; preds = %141, %137
%144 = load i32, i32* %9
%145 = call i32 @close(i32 %144)
%146 = icmp eq i32 %145, -1
br i1 %146, label %147, label %149
147: ; preds = %143
%148 = call i32 @pexit(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0))
br label %149
149: ; preds = %147, %143
br label %150
150: ; preds = %149, %66, %44
store i64 0, i64* @errno
br label %34
151: ; preds = %34
%152 = load i64, i64* @errno
%153 = icmp ne i64 %152, 0
br i1 %153, label %154, label %156
154: ; preds = %151
%155 = call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
br label %156
156: ; preds = %154, %151
%157 = load i32*, i32** %11
%158 = call i32 @closedir(i32* %157)
%159 = icmp eq i32 %158, -1
br i1 %159, label %160, label %162
160: ; preds = %156
%161 = call i32 @pexit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0))
br label %162
162: ; preds = %160, %156
%163 = load i32, i32* @EXIT_SUCCESS
ret i32 %163
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@EXIT_FAILURE = global i32 0
@.str = [6 x i8] c"/proc\00"
@.str.1 = [8 x i8] c"opendir\00"
@.str.2 = [12 x i8] c"%8s%5s%20s\0A\00"
@.str.3 = [4 x i8] c"PID\00"
@.str.4 = [3 x i8] c"FD\00"
@.str.5 = [8 x i8] c"COMMAND\00"
@errno = global i64 0
@.str.6 = [5 x i8] c"self\00"
@.str.7 = [13 x i8] c"%s/%s/status\00"
@O_RDONLY = global i32 0
@ENOENT = global i64 0
@ENOTDIR = global i64 0
@.str.8 = [5 x i8] c"open\00"
@.str.9 = [9 x i8] c"%s/%s/fd\00"
@.str.10 = [2 x i8] c".\00"
@.str.11 = [3 x i8] c"..\00"
@.str.12 = [12 x i8] c"%s/%s/fd/%s\00"
@.str.13 = [9 x i8] c"readlink\00"
@.str.14 = [8 x i8] c"readdir\00"
@.str.15 = [9 x i8] c"closedir\00"
@.str.16 = [6 x i8] c"close\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @helpAndLeave(i8* %7, i32 %8)
br label %10
10: ; preds = %6, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%15 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = tail call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %10
%20 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i64 0, i64* @errno
%21 = call %struct.dirent* @readdir(i32* %15)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %101, label %23
23: ; preds = %19, %98
%24 = phi %struct.dirent* [ %99, %98 ], [ %21, %19 ]
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%28 = icmp eq i64 %27, 0
br i1 %28, label %98, label %29
29: ; preds = %23
%30 = load i8*, i8** %25
%31 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %14, i32 512, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* %14, i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %42
35: ; preds = %29
%36 = load i64, i64* @errno
%37 = load i64, i64* @ENOENT
%38 = icmp eq i64 %36, %37
%39 = load i64, i64* @ENOTDIR
%40 = icmp eq i64 %36, %39
%41 = select i1 %38, i1 true, i1 %40
br i1 %41, label %98, label %95
42: ; preds = %29
%43 = load i8*, i8** %25
%44 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %14, i32 512, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %43)
%45 = call i32* @opendir(i8* %14)
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %42
store i64 0, i64* @errno
%50 = call %struct.dirent* @readdir(i32* %45)
%51 = icmp eq %struct.dirent* %50, null
br i1 %51, label %82, label %52
52: ; preds = %49, %79
%53 = phi %struct.dirent* [ %80, %79 ], [ %50, %49 ]
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %53, i64 0, i32 0
%55 = load i8*, i8** %54
%56 = call i64 @strncmp(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i32 1)
%57 = icmp eq i64 %56, 0
br i1 %57, label %79, label %58
58: ; preds = %52
%59 = load i8*, i8** %54
%60 = call i64 @strncmp(i8* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i32 2)
%61 = icmp eq i64 %60, 0
br i1 %61, label %79, label %62
62: ; preds = %58
%63 = load i8*, i8** %25
%64 = load i8*, i8** %54
%65 = call i32 (i8*, i32, i8*, i8*, i8*, ...) @snprintf(i8* %13, i32 512, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %63, i8* %64)
%66 = call i32 @readlink(i8* %13, i8* %14, i32 512)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %70
68: ; preds = %62
%69 = call i32 @pexit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.13, i64 0, i64 0))
br label %70
70: ; preds = %68, %62
%71 = sext i32 %66 to i64
%72 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %71
store i8 0, i8* %72
%73 = call i64 @strncmp(i8* %14, i8* %12, i32 512)
%74 = icmp eq i64 %73, 0
br i1 %74, label %75, label %79
75: ; preds = %70
%76 = load i8*, i8** %54
%77 = load i8*, i8** %25
%78 = call i32 @printProcessInfo(i32 %33, i8* %76, i8* %77)
br label %79
79: ; preds = %70, %75, %52, %58
store i64 0, i64* @errno
%80 = call %struct.dirent* @readdir(i32* %45)
%81 = icmp eq %struct.dirent* %80, null
br i1 %81, label %82, label %52
82: ; preds = %79, %49
%83 = load i64, i64* @errno
%84 = icmp eq i64 %83, 0
br i1 %84, label %87, label %85
85: ; preds = %82
%86 = call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
%88 = call i32 @closedir(i32* %45)
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %92
90: ; preds = %87
%91 = call i32 @pexit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0))
br label %92
92: ; preds = %90, %87
%93 = call i32 @close(i32 %33)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %98
95: ; preds = %92, %35
%96 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), %35 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), %92 ]
%97 = call i32 @pexit(i8* %96)
br label %98
98: ; preds = %95, %92, %35, %23
store i64 0, i64* @errno
%99 = call %struct.dirent* @readdir(i32* %15)
%100 = icmp eq %struct.dirent* %99, null
br i1 %100, label %101, label %23
101: ; preds = %98, %19
%102 = load i64, i64* @errno
%103 = icmp eq i64 %102, 0
br i1 %103, label %106, label %104
104: ; preds = %101
%105 = call i32 @pexit(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0))
br label %106
106: ; preds = %104, %101
%107 = call i32 @closedir(i32* %15)
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %111
109: ; preds = %106
%110 = call i32 @pexit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.15, i64 0, i64 0))
br label %111
111: ; preds = %109, %106
%112 = load i32, i32* @EXIT_SUCCESS
ret i32 %112
}