#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 /*<<< orphan*/ path;
typedef int /*<<< orphan*/ non_ret_buffer;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, char *, char *,
                          int *, int *, int *, int *, int *, int *, int *,
                          int *, int *, int *, int *, int *, int *, int *,
                          int *, int *, int *, int *, int *, int *, int *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int sockerror(int, char *);
int sockprint(int, char *, ...);
int dump_ps(int fd) {
  int rc = 0, tnprocs = 0, tnthreads = 0;
  struct dirent *de;
  DIR *dirp = opendir("/proc");
  while ((de = readdir(dirp)) != NULL) {
    if (isdigit(de->d_name[0])) {
      FILE *fh;
      static char path[128];
      snprintf(path, sizeof(path), "/proc/%s/stat", de->d_name);
      fh = fopen(path, "r");
      if (fh) {
        static char fname[4096], dummystr[2];
        int dummy, nthreads, ppid, rss;
        fscanf(fh,
               "%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d "
               "%d %d %d",
               &dummy, fname, &dummystr[0], &ppid, &dummy, &dummy, &dummy,
               &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy,
               &dummy, &dummy, &dummy, &dummy, &nthreads, &dummy, &dummy,
               &dummy, &rss);
        rc |= sockprint(fd, "%5s, ppid %5d, # threads: %2d, rss: %5d ",
                        de->d_name, ppid, nthreads, rss);
        tnprocs++;
        tnthreads += nthreads;
      }
      if (fh) {
        fclose(fh);
        if (rc)
          break;
        snprintf(path, sizeof(path), "/proc/%s/cmdline", de->d_name);
        fh = fopen(path, "r");
      }
      if (fh) {
        int len, loop;
        static char non_ret_buffer[4096];
        len = fread(non_ret_buffer, 1, sizeof(non_ret_buffer) - 1, fh);
        if (len < 0)
          rc |= sockerror(fd, "fread");
        else {
          non_ret_buffer[len] = 0x00;
          for (loop = 0; loop < len; loop++) {
            if (non_ret_buffer[loop] == 0x00)
              non_ret_buffer[loop] = ' ';
          }
          rc |= sockprint(fd, "%d %s\r\n", len, non_ret_buffer);
        }
        fclose(fh);
      } else {
        rc |= sockprint(fd, "Error opening %s\r\n", path);
      }
      if (rc)
        break;
    }
  }
  closedir(dirp);
  rc |= sockprint(fd, "# procs: %d, # threads: %d\r\n", tnprocs, tnthreads);
  return rc;
}


x86 assembly (clang, -O0):
<dump_ps>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
lea    0xe26(%rip),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     149a <dump_ps+0x2ea>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1495 <dump_ps+0x2e5>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0x2e6f(%rip),%rdi
mov    $0x80,%esi
lea    0xdd9(%rip),%rdx
call   1070 <snprintf@plt>
lea    0x2e57(%rip),%rdi
lea    0xdd4(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1333 <dump_ps+0x183>
mov    -0x28(%rbp),%rdi
lea    0xdb7(%rip),%rsi
lea    -0x2c(%rbp),%r10
mov    %r10,-0x48(%rbp)
lea    0x2ea2(%rip),%rcx
lea    0x3e9b(%rip),%r8
lea    -0x34(%rbp),%r9
lea    -0x30(%rbp),%r11
lea    -0x38(%rbp),%rax
mov    %r10,%rdx
mov    %r10,(%rsp)
mov    %r10,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %r10,0x30(%rsp)
mov    %r10,0x38(%rsp)
mov    %r10,0x40(%rsp)
mov    %r10,0x48(%rsp)
mov    %r10,0x50(%rsp)
mov    %r10,0x58(%rsp)
mov    %r10,0x60(%rsp)
mov    %r10,0x68(%rsp)
mov    %r10,0x70(%rsp)
mov    %r11,0x78(%rsp)
mov    %r10,0x80(%rsp)
mov    %r10,0x88(%rsp)
mov    %r10,0x90(%rsp)
mov    %rax,0x98(%rsp)
call   1080 <fscanf@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%r8d
mov    -0x38(%rbp),%r9d
lea    0xd4a(%rip),%rsi
mov    $0x0,%al
call   10c0 <sockprint@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x30(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     138c <dump_ps+0x1dc>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x8(%rbp)
je     1356 <dump_ps+0x1a6>
jmp    149a <dump_ps+0x2ea>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0x2d2c(%rip),%rdi
mov    $0x80,%esi
lea    0xd17(%rip),%rdx
call   1070 <snprintf@plt>
lea    0x2d14(%rip),%rdi
lea    0xc91(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1463 <dump_ps+0x2b3>
mov    -0x28(%rbp),%rcx
lea    0x3d7e(%rip),%rdi
mov    $0x1,%esi
mov    $0xfff,%edx
call   1040 <fread@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    13d8 <dump_ps+0x228>
mov    -0x4(%rbp),%edi
lea    0xcd0(%rip),%rsi
call   10d0 <sockerror@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1455 <dump_ps+0x2a5>
movslq -0x3c(%rbp),%rcx
lea    0x3d3d(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    1434 <dump_ps+0x284>
movslq -0x40(%rbp),%rcx
lea    0x3d1b(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1421 <dump_ps+0x271>
movslq -0x40(%rbp),%rcx
lea    0x3d03(%rip),%rax
movb   $0x20,(%rax,%rcx,1)
jmp    1426 <dump_ps+0x276>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    13ee <dump_ps+0x23e>
mov    -0x4(%rbp),%edi
mov    -0x3c(%rbp),%edx
lea    0xc5d(%rip),%rsi
lea    0x3cd8(%rip),%rcx
mov    $0x0,%al
call   10c0 <sockprint@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1481 <dump_ps+0x2d1>
mov    -0x4(%rbp),%edi
lea    0xc39(%rip),%rsi
lea    0x2c1c(%rip),%rdx
mov    $0x0,%al
call   10c0 <sockprint@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1490 <dump_ps+0x2e0>
jmp    149a <dump_ps+0x2ea>
jmp    1495 <dump_ps+0x2e5>
jmp    11e3 <dump_ps+0x33>
mov    -0x20(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xc06(%rip),%rsi
mov    $0x0,%al
call   10c0 <sockprint@plt>
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_ps>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,(%rsp)
lea    0xe38(%rip),%rdi
call   1060 <opendir@plt>
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     15c7 <dump_ps+0x417>
mov    %rax,%rbp
lea    0x2ea3(%rip),%r12
lea    0x24(%rsp),%r13
lea    0x3f27(%rip),%r14
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
jmp    1240 <dump_ps+0x90>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%r12
mov    (%rsp),%edi
lea    0xe89(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10c0 <sockprint@plt>
mov    %eax,%r15d
test   %r15d,%r15d
je     1593 <dump_ps+0x3e3>
jmp    15da <dump_ps+0x42a>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1593 <dump_ps+0x3e3>
mov    0x0(%rbp),%rcx
mov    %r12,%rdi
mov    $0x80,%esi
lea    0xd9e(%rip),%rdx
call   1070 <snprintf@plt>
mov    %r12,%rbx
mov    %r12,%rdi
lea    0xd9a(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1210 <dump_ps+0x60>
mov    %rax,%r12
mov    %rax,%rdi
lea    0xd85(%rip),%rsi
mov    %r13,%rdx
lea    0x2e75(%rip),%rcx
lea    0x3e6e(%rip),%r8
lea    0x14(%rsp),%r9
lea    0x10(%rsp),%rax
push   %rax
push   %r13
push   %r13
push   %r13
lea    0x2c(%rsp),%rax
push   %rax
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
push   %r13
call   1080 <fscanf@plt>
add    $0xa0,%rsp
mov    0x0(%rbp),%rdx
mov    0x14(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x10(%rsp),%r9d
mov    (%rsp),%edi
lea    0xd5f(%rip),%rsi
xor    %eax,%eax
call   10c0 <sockprint@plt>
mov    %eax,%r15d
addl   $0x1,0x8(%rsp)
mov    0x4(%rsp),%eax
add    0xc(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    %r12,%rdi
call   1050 <fclose@plt>
test   %r15d,%r15d
jne    15da <dump_ps+0x42a>
mov    0x0(%rbp),%rcx
mov    %rbx,%r12
mov    %rbx,%rdi
mov    $0x80,%esi
lea    0xd46(%rip),%rdx
call   1070 <snprintf@plt>
mov    %rbx,%rdi
lea    0xcc4(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1213 <dump_ps+0x63>
mov    %rax,%rbp
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xfff,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %eax,%eax
js     1397 <dump_ps+0x1e7>
mov    %eax,%ecx
movb   $0x0,(%rcx,%r14,1)
pxor   %xmm3,%xmm3
je     156d <dump_ps+0x3bd>
cmp    $0x10,%eax
jae    13ab <dump_ps+0x1fb>
xor    %edx,%edx
jmp    15b9 <dump_ps+0x409>
mov    (%rsp),%edi
lea    0xcf7(%rip),%rsi
call   10d0 <sockerror@plt>
jmp    1583 <dump_ps+0x3d3>
mov    %ecx,%edx
and    $0xfffffff0,%edx
xor    %esi,%esi
jmp    13cd <dump_ps+0x21d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x10,%rsi
cmp    %rsi,%rdx
je     1568 <dump_ps+0x3b8>
movq   (%rsi,%r14,1),%xmm1
movdqa %xmm1,%xmm0
pcmpeqb %xmm3,%xmm0
movd   %xmm0,%edi
test   $0x1,%dil
je     13ea <dump_ps+0x23a>
movb   $0x20,(%rsi,%r14,1)
movdqa %xmm0,%xmm2
pslld  $0x8,%xmm2
movd   %xmm2,%edi
shr    $0x10,%edi
test   $0x1,%dil
je     1406 <dump_ps+0x256>
movb   $0x20,0x1(%rsi,%r14,1)
pshuflw $0x55,%xmm1,%xmm2
pcmpeqb %xmm3,%xmm2
pextrw $0x2,%xmm2,%edi
test   $0x1,%dil
je     1420 <dump_ps+0x270>
movb   $0x20,0x2(%rsi,%r14,1)
movdqa %xmm0,%xmm2
psllq  $0x18,%xmm2
pextrw $0x3,%xmm2,%edi
test   $0x1,%dil
je     143a <dump_ps+0x28a>
movb   $0x20,0x3(%rsi,%r14,1)
pshufd $0x55,%xmm1,%xmm1
pcmpeqb %xmm3,%xmm1
pextrw $0x4,%xmm1,%edi
test   $0x1,%dil
je     1454 <dump_ps+0x2a4>
movb   $0x20,0x4(%rsi,%r14,1)
movdqa %xmm0,%xmm1
pslldq $0x5,%xmm1
pextrw $0x5,%xmm1,%edi
test   $0x1,%dil
je     146e <dump_ps+0x2be>
movb   $0x20,0x5(%rsi,%r14,1)
pextrw $0x3,%xmm0,%edi
test   $0x1,%dil
je     147f <dump_ps+0x2cf>
movb   $0x20,0x6(%rsi,%r14,1)
pslldq $0x7,%xmm0
pextrw $0x7,%xmm0,%edi
test   $0x1,%dil
je     1495 <dump_ps+0x2e5>
movb   $0x20,0x7(%rsi,%r14,1)
movq   0x8(%rsi,%r14,1),%xmm1
movdqa %xmm1,%xmm0
pcmpeqb %xmm3,%xmm0
movd   %xmm0,%edi
test   $0x1,%dil
je     14b4 <dump_ps+0x304>
movb   $0x20,0x8(%rsi,%r14,1)
movdqa %xmm0,%xmm2
pslld  $0x8,%xmm2
movd   %xmm2,%edi
shr    $0x10,%edi
test   $0x1,%dil
je     14d0 <dump_ps+0x320>
movb   $0x20,0x9(%rsi,%r14,1)
pshuflw $0x55,%xmm1,%xmm2
pcmpeqb %xmm3,%xmm2
pextrw $0x2,%xmm2,%edi
test   $0x1,%dil
je     14ea <dump_ps+0x33a>
movb   $0x20,0xa(%rsi,%r14,1)
movdqa %xmm0,%xmm2
psllq  $0x18,%xmm2
pextrw $0x3,%xmm2,%edi
test   $0x1,%dil
je     1504 <dump_ps+0x354>
movb   $0x20,0xb(%rsi,%r14,1)
pshufd $0x55,%xmm1,%xmm1
pcmpeqb %xmm3,%xmm1
pextrw $0x4,%xmm1,%edi
test   $0x1,%dil
je     151e <dump_ps+0x36e>
movb   $0x20,0xc(%rsi,%r14,1)
movdqa %xmm0,%xmm1
pslldq $0x5,%xmm1
pextrw $0x5,%xmm1,%edi
test   $0x1,%dil
je     1538 <dump_ps+0x388>
movb   $0x20,0xd(%rsi,%r14,1)
pextrw $0x3,%xmm0,%edi
test   $0x1,%dil
je     1549 <dump_ps+0x399>
movb   $0x20,0xe(%rsi,%r14,1)
pslldq $0x7,%xmm0
pextrw $0x7,%xmm0,%edi
test   $0x1,%dil
je     13c0 <dump_ps+0x210>
movb   $0x20,0xf(%rsi,%r14,1)
jmp    13c0 <dump_ps+0x210>
cmp    %rcx,%rdx
jne    15b9 <dump_ps+0x409>
mov    (%rsp),%edi
lea    0xb27(%rip),%rsi
mov    %eax,%edx
mov    %r14,%rcx
xor    %eax,%eax
call   10c0 <sockprint@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1050 <fclose@plt>
test   %r15d,%r15d
jne    15da <dump_ps+0x42a>
mov    0x18(%rsp),%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1240 <dump_ps+0x90>
jmp    15d7 <dump_ps+0x427>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rdx
cmp    %rdx,%rcx
je     156d <dump_ps+0x3bd>
cmpb   $0x0,(%rdx,%r14,1)
jne    15b0 <dump_ps+0x400>
movb   $0x20,(%rdx,%r14,1)
jmp    15b0 <dump_ps+0x400>
movl   $0x0,0x4(%rsp)
movl   $0x0,0x8(%rsp)
xor    %r15d,%r15d
mov    0x18(%rsp),%rdi
call   1090 <closedir@plt>
lea    0xace(%rip),%rsi
mov    (%rsp),%edi
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
xor    %eax,%eax
call   10c0 <sockprint@plt>
or     %r15d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/proc\00"
@dump_ps.path = internal global [128 x i8] zeroinitializer
@.str.1 = [14 x i8] c"/proc/%s/stat\00"
@.str.2 = [2 x i8] c"r\00"
@dump_ps.fname = internal global [4096 x i8] zeroinitializer
@dump_ps.dummystr = internal global [2 x i8] zeroinitializer
@.str.3 = [72 x i8] c"%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\00"
@.str.4 = [41 x i8] c"%5s, ppid %5d, # threads: %2d, rss: %5d \00"
@.str.5 = [17 x i8] c"/proc/%s/cmdline\00"
@dump_ps.non_ret_buffer = internal global [4096 x i8] zeroinitializer
@.str.6 = [6 x i8] c"fread\00"
@.str.7 = [8 x i8] c"%d %s\0D\0A\00"
@.str.8 = [19 x i8] c"Error opening %s\0D\0A\00"
@.str.9 = [29 x i8] c"# procs: %d, # threads: %d\0D\0A\00"
define i32 @dump_ps(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.dirent*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%15 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
br label %16
16: ; preds = %124, %1
%17 = load i32*, i32** %7
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %6
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %125
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %6
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = call i64 @isdigit(i8 signext %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %124
28: ; preds = %20
%29 = load %struct.dirent*, %struct.dirent** %6
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32* @fopen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %8
%34 = load i32*, i32** %8
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %54
36: ; preds = %28
%37 = load i32*, i32** %8
%38 = call i32 @fscanf(i32* %37, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i32* %9, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @dump_ps.fname, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @dump_ps.dummystr, i64 0, i64 0), i32* %11, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %9, i32* %10, i32* %9, i32* %9, i32* %9, i32* %12)
%39 = load i32, i32* %2
%40 = load %struct.dirent*, %struct.dirent** %6
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = load i32, i32* %11
%44 = load i32, i32* %10
%45 = load i32, i32* %12
%46 = call i32 (i32, i8*, ...) @sockprint(i32 %39, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %42, i32 %43, i32 %44, i32 %45)
%47 = load i32, i32* %3
%48 = or i32 %47, %46
store i32 %48, i32* %3
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
%51 = load i32, i32* %10
%52 = load i32, i32* %5
%53 = add nsw i32 %52, %51
store i32 %53, i32* %5
br label %54
54: ; preds = %36, %28
%55 = load i32*, i32** %8
%56 = icmp ne i32* %55, null
br i1 %56, label %57, label %69
57: ; preds = %54
%58 = load i32*, i32** %8
%59 = call i32 @fclose(i32* %58)
%60 = load i32, i32* %3
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %57
br label %125
63: ; preds = %57
%64 = load %struct.dirent*, %struct.dirent** %6
%65 = getelementptr inbounds %struct.dirent, %struct.dirent* %64, i32 0, i32 0
%66 = load i8*, i8** %65
%67 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %66)
%68 = call i32* @fopen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %68, i32** %8
br label %69
69: ; preds = %63, %54
%70 = load i32*, i32** %8
%71 = icmp ne i32* %70, null
br i1 %71, label %72, label %114
72: ; preds = %69
%73 = load i32*, i32** %8
%74 = call i32 @fread(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 0), i32 1, i32 4095, i32* %73)
store i32 %74, i32* %13
%75 = load i32, i32* %13
%76 = icmp slt i32 %75, 0
br i1 %76, label %77, label %82
77: ; preds = %72
%78 = load i32, i32* %2
%79 = call i32 @sockerror(i32 %78, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%80 = load i32, i32* %3
%81 = or i32 %80, %79
store i32 %81, i32* %3
br label %111
82: ; preds = %72
%83 = load i32, i32* %13
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %84
store i8 0, i8* %85
store i32 0, i32* %14
br label %86
86: ; preds = %102, %82
%87 = load i32, i32* %14
%88 = load i32, i32* %13
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %105
90: ; preds = %86
%91 = load i32, i32* %14
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %92
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %101
97: ; preds = %90
%98 = load i32, i32* %14
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %99
store i8 32, i8* %100
br label %101
101: ; preds = %97, %90
br label %102
102: ; preds = %101
%103 = load i32, i32* %14
%104 = add nsw i32 %103, 1
store i32 %104, i32* %14
br label %86
105: ; preds = %86
%106 = load i32, i32* %2
%107 = load i32, i32* %13
%108 = call i32 (i32, i8*, ...) @sockprint(i32 %106, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %107, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 0))
%109 = load i32, i32* %3
%110 = or i32 %109, %108
store i32 %110, i32* %3
br label %111
111: ; preds = %105, %77
%112 = load i32*, i32** %8
%113 = call i32 @fclose(i32* %112)
br label %119
114: ; preds = %69
%115 = load i32, i32* %2
%116 = call i32 (i32, i8*, ...) @sockprint(i32 %115, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0))
%117 = load i32, i32* %3
%118 = or i32 %117, %116
store i32 %118, i32* %3
br label %119
119: ; preds = %114, %111
%120 = load i32, i32* %3
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %123
122: ; preds = %119
br label %125
123: ; preds = %119
br label %124
124: ; preds = %123, %20
br label %16
125: ; preds = %122, %62, %16
%126 = load i32*, i32** %7
%127 = call i32 @closedir(i32* %126)
%128 = load i32, i32* %2
%129 = load i32, i32* %4
%130 = load i32, i32* %5
%131 = call i32 (i32, i8*, ...) @sockprint(i32 %128, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i32 %129, i32 %130)
%132 = load i32, i32* %3
%133 = or i32 %132, %131
store i32 %133, i32* %3
%134 = load i32, i32* %3
ret i32 %134
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/proc\00"
@dump_ps.path = internal global [128 x i8] zeroinitializer
@.str.1 = [14 x i8] c"/proc/%s/stat\00"
@.str.2 = [2 x i8] c"r\00"
@dump_ps.fname = internal global [4096 x i8] zeroinitializer
@dump_ps.dummystr = internal global [2 x i8] zeroinitializer
@.str.3 = [72 x i8] c"%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\00"
@.str.4 = [41 x i8] c"%5s, ppid %5d, # threads: %2d, rss: %5d \00"
@.str.5 = [17 x i8] c"/proc/%s/cmdline\00"
@dump_ps.non_ret_buffer = internal global [4096 x i8] zeroinitializer
@.str.6 = [6 x i8] c"fread\00"
@.str.7 = [8 x i8] c"%d %s\0D\0A\00"
@.str.8 = [19 x i8] c"Error opening %s\0D\0A\00"
@.str.9 = [29 x i8] c"# procs: %d, # threads: %d\0D\0A\00"
define i32 @dump_ps(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%7 = bitcast i32* %2 to i8*
%8 = call %struct.dirent* @readdir(i32* %6)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %181, label %10
10: ; preds = %1
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
br label %14
14: ; preds = %10, %176
%15 = phi %struct.dirent* [ %8, %10 ], [ %179, %176 ]
%16 = phi i32 [ 0, %10 ], [ %178, %176 ]
%17 = phi i32 [ 0, %10 ], [ %177, %176 ]
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = call i64 @isdigit(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %176, label %23
23: ; preds = %14
%24 = load i8*, i8** %18
%25 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32* @fopen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %167, label %28
28: ; preds = %23
%29 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i32* %2, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @dump_ps.fname, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @dump_ps.dummystr, i64 0, i64 0), i32* %4, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %2, i32* %3, i32* %2, i32* %2, i32* %2, i32* %5)
%30 = load i8*, i8** %18
%31 = load i32, i32* %4
%32 = load i32, i32* %3
%33 = load i32, i32* %5
%34 = call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %30, i32 %31, i32 %32, i32 %33)
%35 = add nsw i32 %16, 1
%36 = load i32, i32* %3
%37 = add nsw i32 %36, %17
%38 = call i32 @fclose(i32* %26)
%39 = icmp eq i32 %34, 0
br i1 %39, label %40, label %181
40: ; preds = %28
%41 = load i8*, i8** %18
%42 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = call i32* @fopen(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%44 = icmp eq i32* %43, null
br i1 %44, label %167, label %45
45: ; preds = %40
%46 = call i32 @fread(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 0), i32 1, i32 4095, i32* %43)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @sockerror(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %164
50: ; preds = %45
%51 = zext i32 %46 to i64
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %51
store i8 0, i8* %52
%53 = icmp eq i32 %46, 0
br i1 %53, label %162, label %54
54: ; preds = %50
%55 = icmp ult i32 %46, 16
br i1 %55, label %151, label %56
56: ; preds = %54
%57 = and i64 %51, 4294967280
br label %58
58: ; preds = %146, %56
%59 = phi i64 [ 0, %56 ], [ %147, %146 ]
%60 = or i64 %59, 8
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %59
%62 = bitcast i8* %61 to <8 x i8>*
%63 = load <8 x i8>, <8 x i8>* %62
%64 = getelementptr inbounds i8, i8* %61, i64 8
%65 = bitcast i8* %64 to <8 x i8>*
%66 = load <8 x i8>, <8 x i8>* %65
%67 = icmp eq <8 x i8> %63, zeroinitializer
%68 = icmp eq <8 x i8> %66, zeroinitializer
%69 = extractelement <8 x i1> %67, i64 0
br i1 %69, label %70, label %72
70: ; preds = %58
%71 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %59
store i8 32, i8* %71
br label %72
72: ; preds = %70, %58
%73 = extractelement <8 x i1> %67, i64 1
br i1 %73, label %74, label %77
74: ; preds = %72
%75 = or i64 %59, 1
%76 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %75
store i8 32, i8* %76
br label %77
77: ; preds = %74, %72
%78 = extractelement <8 x i1> %67, i64 2
br i1 %78, label %79, label %82
79: ; preds = %77
%80 = or i64 %59, 2
%81 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %80
store i8 32, i8* %81
br label %82
82: ; preds = %79, %77
%83 = extractelement <8 x i1> %67, i64 3
br i1 %83, label %84, label %87
84: ; preds = %82
%85 = or i64 %59, 3
%86 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %85
store i8 32, i8* %86
br label %87
87: ; preds = %84, %82
%88 = extractelement <8 x i1> %67, i64 4
br i1 %88, label %89, label %92
89: ; preds = %87
%90 = or i64 %59, 4
%91 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %90
store i8 32, i8* %91
br label %92
92: ; preds = %89, %87
%93 = extractelement <8 x i1> %67, i64 5
br i1 %93, label %94, label %97
94: ; preds = %92
%95 = or i64 %59, 5
%96 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %95
store i8 32, i8* %96
br label %97
97: ; preds = %94, %92
%98 = extractelement <8 x i1> %67, i64 6
br i1 %98, label %99, label %102
99: ; preds = %97
%100 = or i64 %59, 6
%101 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %100
store i8 32, i8* %101
br label %102
102: ; preds = %99, %97
%103 = extractelement <8 x i1> %67, i64 7
br i1 %103, label %104, label %107
104: ; preds = %102
%105 = or i64 %59, 7
%106 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %105
store i8 32, i8* %106
br label %107
107: ; preds = %104, %102
%108 = extractelement <8 x i1> %68, i64 0
br i1 %108, label %109, label %111
109: ; preds = %107
%110 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %60
store i8 32, i8* %110
br label %111
111: ; preds = %109, %107
%112 = extractelement <8 x i1> %68, i64 1
br i1 %112, label %113, label %116
113: ; preds = %111
%114 = or i64 %59, 9
%115 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %114
store i8 32, i8* %115
br label %116
116: ; preds = %113, %111
%117 = extractelement <8 x i1> %68, i64 2
br i1 %117, label %118, label %121
118: ; preds = %116
%119 = or i64 %59, 10
%120 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %119
store i8 32, i8* %120
br label %121
121: ; preds = %118, %116
%122 = extractelement <8 x i1> %68, i64 3
br i1 %122, label %123, label %126
123: ; preds = %121
%124 = or i64 %59, 11
%125 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %124
store i8 32, i8* %125
br label %126
126: ; preds = %123, %121
%127 = extractelement <8 x i1> %68, i64 4
br i1 %127, label %128, label %131
128: ; preds = %126
%129 = or i64 %59, 12
%130 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %129
store i8 32, i8* %130
br label %131
131: ; preds = %128, %126
%132 = extractelement <8 x i1> %68, i64 5
br i1 %132, label %133, label %136
133: ; preds = %131
%134 = or i64 %59, 13
%135 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %134
store i8 32, i8* %135
br label %136
136: ; preds = %133, %131
%137 = extractelement <8 x i1> %68, i64 6
br i1 %137, label %138, label %141
138: ; preds = %136
%139 = or i64 %59, 14
%140 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %139
store i8 32, i8* %140
br label %141
141: ; preds = %138, %136
%142 = extractelement <8 x i1> %68, i64 7
br i1 %142, label %143, label %146
143: ; preds = %141
%144 = or i64 %59, 15
%145 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %144
store i8 32, i8* %145
br label %146
146: ; preds = %143, %141
%147 = add nuw i64 %59, 16
%148 = icmp eq i64 %147, %57
br i1 %148, label %149, label %58
149: ; preds = %146
%150 = icmp eq i64 %57, %51
br i1 %150, label %162, label %151
151: ; preds = %54, %149
%152 = phi i64 [ 0, %54 ], [ %57, %149 ]
br label %153
153: ; preds = %151, %159
%154 = phi i64 [ %160, %159 ], [ %152, %151 ]
%155 = getelementptr inbounds [4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 %154
%156 = load i8, i8* %155
%157 = icmp eq i8 %156, 0
br i1 %157, label %158, label %159
158: ; preds = %153
store i8 32, i8* %155
br label %159
159: ; preds = %153, %158
%160 = add nuw nsw i64 %154, 1
%161 = icmp eq i64 %160, %51
br i1 %161, label %162, label %153
162: ; preds = %159, %149, %50
%163 = call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %46, i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @dump_ps.non_ret_buffer, i64 0, i64 0))
br label %164
164: ; preds = %162, %48
%165 = phi i32 [ %49, %48 ], [ %163, %162 ]
%166 = call i32 @fclose(i32* %43)
br label %171
167: ; preds = %23, %40
%168 = phi i32 [ %37, %40 ], [ %17, %23 ]
%169 = phi i32 [ %35, %40 ], [ %16, %23 ]
%170 = call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([128 x i8], [128 x i8]* @dump_ps.path, i64 0, i64 0))
br label %171
171: ; preds = %167, %164
%172 = phi i32 [ %37, %164 ], [ %168, %167 ]
%173 = phi i32 [ %35, %164 ], [ %169, %167 ]
%174 = phi i32 [ %165, %164 ], [ %170, %167 ]
%175 = icmp eq i32 %174, 0
br i1 %175, label %176, label %181
176: ; preds = %171, %14
%177 = phi i32 [ %17, %14 ], [ %172, %171 ]
%178 = phi i32 [ %16, %14 ], [ %173, %171 ]
%179 = call %struct.dirent* @readdir(i32* %6)
%180 = icmp eq %struct.dirent* %179, null
br i1 %180, label %181, label %14
181: ; preds = %176, %28, %171, %1
%182 = phi i32 [ 0, %1 ], [ %172, %171 ], [ %37, %28 ], [ %177, %176 ]
%183 = phi i32 [ 0, %1 ], [ %173, %171 ], [ %35, %28 ], [ %178, %176 ]
%184 = phi i32 [ 0, %1 ], [ %174, %171 ], [ %34, %28 ], [ 0, %176 ]
%185 = call i32 @closedir(i32* %6)
%186 = call i32 (i32, i8*, ...) @sockprint(i32 %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.9, i64 0, i64 0), i32 %183, i32 %182)
%187 = or i32 %186, %184
ret i32 %187
}