#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 stat {
  int /*<<< orphan*/ st_uid;
};
struct passwd {
  int /*<<< orphan*/ pw_name;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ file2str(char *, char *, char *, int);
float get_mem_rate();
unsigned long get_mem_total();
int /*<<< orphan*/ get_process_mem_rate(char *, unsigned long, float *,
                                        unsigned long *);
struct passwd *getpwuid(int /*<<< orphan*/);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ proc_node_add(int /*<<< orphan*/, char *, char *,
                                 int /*<<< orphan*/, unsigned long, float);
struct dirent *readdir(int /*<<< orphan*/ *);
int readlink(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
char *strstr(char *, char *);
void proc_node_init(void) {
  char buf1[1024], buf2[1024];
  char ProcPath[1024], *ptr, comm[80];
  DIR *db, *directory;
  struct dirent *p;
  float MemUsedRate;
  unsigned long MemTotal;
  MemUsedRate = get_mem_rate();
  MemTotal = get_mem_total();
  db = opendir("/proc/");
  if (db == NULL)
    return;
  while (p = readdir(db)) {
    char *cs;
    for (cs = p->d_name; *cs; cs++)
      if (!isdigit(*cs))
        break;
    if (*cs)
      continue;
    sprintf(ProcPath, "/proc/%s", p->d_name);
    file2str(ProcPath, "comm", comm, sizeof comm);
    ptr = strstr(comm, "\n");
    *ptr = '\0';
    sprintf(buf1, "%s/exe", ProcPath);
    memset(buf2, 0, sizeof(buf2));
    if (readlink(buf1, buf2, sizeof(buf2)) == -1) {
      sprintf(buf2, "[%s]", comm);
    }
    static struct stat sb;
    stat(ProcPath, &sb);
    struct passwd *pw;
    pw = getpwuid(sb.st_uid);
    float ProcMemUsedRate;
    unsigned long ProcMemTotal;
    get_process_mem_rate(ProcPath, MemTotal, &ProcMemUsedRate, &ProcMemTotal);
    proc_node_add(atoi(p->d_name), buf2, comm, pw->pw_name, ProcMemTotal,
                  ProcMemUsedRate);
  }
  closedir(db);
}


x86 assembly (clang, -O0):
<proc_node_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0xcb0,%rsp
mov    $0x0,%al
call   1090 <get_mem_rate@plt>
movss  %xmm0,-0xc7c(%rbp)
ff
mov    $0x0,%al
call   10d0 <get_mem_total@plt>
mov    %rax,-0xc88(%rbp)
lea    0xdd1(%rip),%rdi
call   1070 <opendir@plt>
mov    %rax,-0xc68(%rbp)
cmpq   $0x0,-0xc68(%rbp)
jne    124e <proc_node_init+0x4e>
jmp    143a <proc_node_init+0x23a>
jmp    1253 <proc_node_init+0x53>
mov    -0xc68(%rbp),%rdi
call   10f0 <readdir@plt>
mov    %rax,-0xc78(%rbp)
cmp    $0x0,%rax
je     142e <proc_node_init+0x22e>
mov    -0xc78(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xc90(%rbp)
mov    -0xc90(%rbp),%rax
cmpb   $0x0,(%rax)
je     12ca <proc_node_init+0xca>
mov    -0xc90(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isdigit@plt>
cmp    $0x0,%eax
jne    12ae <proc_node_init+0xae>
jmp    12ca <proc_node_init+0xca>
jmp    12b3 <proc_node_init+0xb3>
mov    -0xc90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc90(%rbp)
jmp    1281 <proc_node_init+0x81>
mov    -0xc90(%rbp),%rax
cmpb   $0x0,(%rax)
je     12df <proc_node_init+0xdf>
jmp    1253 <proc_node_init+0x53>
lea    -0xc00(%rbp),%rdi
mov    -0xc78(%rbp),%rax
mov    (%rax),%rdx
lea    0xd10(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0xc00(%rbp),%rdi
lea    -0xc60(%rbp),%rdx
lea    0xcff(%rip),%rsi
mov    $0x50,%ecx
call   1030 <file2str@plt>
lea    -0xc60(%rbp),%rdi
lea    0xcec(%rip),%rsi
call   1120 <strstr@plt>
mov    %rax,-0xc08(%rbp)
mov    -0xc08(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x400(%rbp),%rdi
lea    -0xc00(%rbp),%rdx
lea    0xcc3(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0x800(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10a0 <memset@plt>
lea    -0x400(%rbp),%rdi
lea    -0x800(%rbp),%rsi
mov    $0x400,%edx
call   1060 <readlink@plt>
cmp    $0xffffffff,%eax
jne    13a7 <proc_node_init+0x1a7>
lea    -0x800(%rbp),%rdi
lea    -0xc60(%rbp),%rdx
lea    0xc7c(%rip),%rsi
call   1110 <sprintf@plt>
lea    -0xc00(%rbp),%rdi
lea    0x2cef(%rip),%rsi
call   10e0 <stat@plt>
mov    0x2ce4(%rip),%edi
call   1080 <getpwuid@plt>
mov    %rax,-0xc98(%rbp)
lea    -0xc00(%rbp),%rdi
mov    -0xc88(%rbp),%rsi
lea    -0xc9c(%rbp),%rdx
lea    -0xca8(%rbp),%rcx
call   10b0 <get_process_mem_rate@plt>
mov    -0xc78(%rbp),%rax
mov    (%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
lea    -0x800(%rbp),%rsi
lea    -0xc60(%rbp),%rdx
mov    -0xc98(%rbp),%rax
mov    (%rax),%ecx
mov    -0xca8(%rbp),%r8
movss  -0xc9c(%rbp),%xmm0
ff
call   1040 <proc_node_add@plt>
jmp    1253 <proc_node_init+0x53>
mov    -0xc68(%rbp),%rdi
call   10c0 <closedir@plt>
add    $0xcb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_node_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc78,%rsp
xor    %eax,%eax
call   10a0 <get_mem_rate@plt>
xor    %eax,%eax
call   10e0 <get_mem_total@plt>
mov    %rax,0x10(%rsp)
lea    0xdd5(%rip),%rdi
call   1070 <opendir@plt>
test   %rax,%rax
je     13bf <proc_node_init+0x1bf>
mov    %rax,%rbx
mov    %rax,%rdi
call   1100 <readdir@plt>
test   %rax,%rax
je     13b7 <proc_node_init+0x1b7>
mov    %rax,%r14
lea    0x70(%rsp),%r12
lea    0x20(%rsp),%r13
lea    0x470(%rsp),%r15
jmp    1359 <proc_node_init+0x159>
nopw   0x0(%rax,%rax,1)
mov    (%r14),%rdx
mov    %r12,%rdi
lea    0xd8a(%rip),%rsi
call   1120 <sprintf@plt>
mov    %r12,%rdi
lea    0xd84(%rip),%rsi
mov    %r13,%rdx
mov    $0x50,%ecx
call   1030 <file2str@plt>
mov    %r13,%rdi
mov    $0xa,%esi
call   1090 <strchr@plt>
movb   $0x0,(%rax)
lea    0x870(%rsp),%rbp
mov    %rbp,%rdi
lea    0xd5a(%rip),%rsi
mov    %r12,%rdx
call   1120 <sprintf@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10b0 <memset@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    $0x400,%edx
call   1060 <readlink@plt>
cmp    $0xffffffff,%eax
je     13a0 <proc_node_init+0x1a0>
mov    %r12,%rdi
lea    0x2daf(%rip),%rsi
call   10f0 <stat@plt>
mov    0x2da4(%rip),%edi
call   1080 <getpwuid@plt>
mov    %r13,%rbp
mov    %rax,%r13
mov    %r12,%rdi
mov    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x18(%rsp),%rcx
call   10c0 <get_process_mem_rate@plt>
mov    (%r14),%rdi
call   1110 <atoi@plt>
mov    0x0(%r13),%ecx
mov    %rbp,%r13
mov    0x18(%rsp),%r8
movss  0xc(%rsp),%xmm0
mov    %eax,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <proc_node_add@plt>
mov    %rbx,%rdi
call   1100 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     13b7 <proc_node_init+0x1b7>
mov    (%r14),%rbp
mov    0x0(%rbp),%al
test   %al,%al
je     1270 <proc_node_init+0x70>
add    $0x1,%rbp
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1050 <isdigit@plt>
test   %eax,%eax
je     1390 <proc_node_init+0x190>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1370 <proc_node_init+0x170>
jmp    1270 <proc_node_init+0x70>
nopl   (%rax)
cmpb   $0x0,-0x1(%rbp)
jne    1349 <proc_node_init+0x149>
jmp    1270 <proc_node_init+0x70>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
lea    0xc72(%rip),%rsi
mov    %r13,%rdx
call   1120 <sprintf@plt>
jmp    12eb <proc_node_init+0xeb>
mov    %rbx,%rdi
call   10d0 <closedir@plt>
add    $0xc78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
%struct.passwd = type { i32 }
@.str = [7 x i8] c"/proc/\00"
@.str.1 = [9 x i8] c"/proc/%s\00"
@.str.2 = [5 x i8] c"comm\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [7 x i8] c"%s/exe\00"
@.str.5 = [5 x i8] c"[%s]\00"
@proc_node_init.sb = internal global %struct.stat zeroinitializer
define void @proc_node_init() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca [80 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca float
%10 = alloca i64
%11 = alloca i8*
%12 = alloca %struct.passwd*
%13 = alloca float
%14 = alloca i64
%15 = call float (...) @get_mem_rate()
store float %15, float* %9
%16 = call i64 (...) @get_mem_total()
store i64 %16, i64* %10
%17 = call i32* @opendir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %0
br label %97
21: ; preds = %0
br label %22
22: ; preds = %74, %48, %21
%23 = load i32*, i32** %6
%24 = call %struct.dirent* @readdir(i32* %23)
store %struct.dirent* %24, %struct.dirent** %8
%25 = icmp ne %struct.dirent* %24, null
br i1 %25, label %26, label %94
26: ; preds = %22
%27 = load %struct.dirent*, %struct.dirent** %8
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i32 0, i32 0
%29 = load i8*, i8** %28
store i8* %29, i8** %11
br label %30
30: ; preds = %41, %26
%31 = load i8*, i8** %11
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %30
%35 = load i8*, i8** %11
%36 = load i8, i8* %35
%37 = call i32 @isdigit(i8 signext %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %34
br label %44
40: ; preds = %34
br label %41
41: ; preds = %40
%42 = load i8*, i8** %11
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %11
br label %30
44: ; preds = %39, %30
%45 = load i8*, i8** %11
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44
br label %22
49: ; preds = %44
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%51 = load %struct.dirent*, %struct.dirent** %8
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = call i32 @sprintf(i8* %50, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%57 = call i32 @file2str(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %56, i32 80)
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%59 = call i8* @strstr(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %59, i8** %4
%60 = load i8*, i8** %4
store i8 0, i8* %60
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%63 = call i32 @sprintf(i8* %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %62)
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%65 = call i32 @memset(i8* %64, i32 0, i32 1024)
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%68 = call i32 @readlink(i8* %66, i8* %67, i32 1024)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %74
70: ; preds = %49
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%72 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%73 = call i32 @sprintf(i8* %71, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %70, %49
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%76 = call i32 @stat(i8* %75, %struct.stat* @proc_node_init.sb)
%77 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @proc_node_init.sb, i32 0, i32 0)
%78 = call %struct.passwd* @getpwuid(i32 %77)
store %struct.passwd* %78, %struct.passwd** %12
%79 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%80 = load i64, i64* %10
%81 = call i32 @get_process_mem_rate(i8* %79, i64 %80, float* %13, i64* %14)
%82 = load %struct.dirent*, %struct.dirent** %8
%83 = getelementptr inbounds %struct.dirent, %struct.dirent* %82, i32 0, i32 0
%84 = load i8*, i8** %83
%85 = call i32 @atoi(i8* %84)
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%87 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%88 = load %struct.passwd*, %struct.passwd** %12
%89 = getelementptr inbounds %struct.passwd, %struct.passwd* %88, i32 0, i32 0
%90 = load i32, i32* %89
%91 = load i64, i64* %14
%92 = load float, float* %13
%93 = call i32 @proc_node_add(i32 %85, i8* %86, i8* %87, i32 %90, i64 %91, float %92)
br label %22
94: ; preds = %22
%95 = load i32*, i32** %6
%96 = call i32 @closedir(i32* %95)
br label %97
97: ; preds = %94, %20
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
%struct.passwd = type { i32 }
@.str = [7 x i8] c"/proc/\00"
@.str.1 = [9 x i8] c"/proc/%s\00"
@.str.2 = [5 x i8] c"comm\00"
@.str.4 = [7 x i8] c"%s/exe\00"
@.str.5 = [5 x i8] c"[%s]\00"
@proc_node_init.sb = internal global %struct.stat zeroinitializer
define void @proc_node_init() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [80 x i8]
%5 = alloca float
%6 = alloca i64
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%11 = tail call float (...) @get_mem_rate()
%12 = tail call i64 (...) @get_mem_total()
%13 = tail call i32* @opendir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %67, label %15
15: ; preds = %0
%16 = call %struct.dirent* @readdir(i32* %13)
%17 = icmp eq %struct.dirent* %16, null
br i1 %17, label %65, label %18
18: ; preds = %15
%19 = bitcast float* %5 to i8*
%20 = bitcast i64* %6 to i8*
br label %21
21: ; preds = %18, %62
%22 = phi %struct.dirent* [ %16, %18 ], [ %63, %62 ]
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %39, label %27
27: ; preds = %21, %32
%28 = phi i8 [ %34, %32 ], [ %25, %21 ]
%29 = phi i8* [ %33, %32 ], [ %24, %21 ]
%30 = call i32 @isdigit(i8 signext %28)
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = getelementptr inbounds i8, i8* %29, i64 1
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %39, label %27
36: ; preds = %27
%37 = load i8, i8* %29
%38 = icmp eq i8 %37, 0
br i1 %38, label %39, label %62
39: ; preds = %32, %21, %36
%40 = load i8*, i8** %23
%41 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %40)
%42 = call i32 @file2str(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %10, i32 80)
%43 = call i8* @strchr(i8* %10, i32 10)
store i8 0, i8* %43
%44 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%45 = call i32 @memset(i8* %8, i32 0, i32 1024)
%46 = call i32 @readlink(i8* %7, i8* %8, i32 1024)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %10)
br label %50
50: ; preds = %48, %39
%51 = call i32 @stat(i8* %9, %struct.stat* @proc_node_init.sb)
%52 = load i32, i32* getelementptr inbounds (%struct.stat, %struct.stat* @proc_node_init.sb, i64 0, i32 0)
%53 = call %struct.passwd* @getpwuid(i32 %52)
%54 = call i32 @get_process_mem_rate(i8* %9, i64 %12, float* %5, i64* %6)
%55 = load i8*, i8** %23
%56 = call i32 @atoi(i8* %55)
%57 = getelementptr inbounds %struct.passwd, %struct.passwd* %53, i64 0, i32 0
%58 = load i32, i32* %57
%59 = load i64, i64* %6
%60 = load float, float* %5
%61 = call i32 @proc_node_add(i32 %56, i8* %8, i8* %10, i32 %58, i64 %59, float %60)
br label %62
62: ; preds = %36, %50
%63 = call %struct.dirent* @readdir(i32* %13)
%64 = icmp eq %struct.dirent* %63, null
br i1 %64, label %65, label %21
65: ; preds = %62, %15
%66 = call i32 @closedir(i32* %13)
br label %67
67: ; preds = %0, %65
ret void
}