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

/* Variables and functions */
int atoi(int /*<<< orphan*/ *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
struct process_info *get_process_info(int);
scalar_t__ isdigit(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ process_info_add(struct process_info *);
struct dirent *readdir(int /*<<< orphan*/ *);
int processes_info_load(void) {
  DIR *d;
  struct dirent *de;
  struct process_info *psinfo;
  d = opendir("/proc");
  if (d == 0)
    return -1;
  while ((de = readdir(d)) != 0) {
    if (isdigit(de->d_name[0])) {
      int pid = atoi(de->d_name);
      psinfo = get_process_info(pid);
      if (!psinfo)
        continue;
      process_info_add(psinfo);
    }
  }
  closedir(d);
  return 0;
}


x86 assembly (clang, -O0):
<processes_info_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe81(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119f <processes_info_load+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    121c <processes_info_load+0xac>
jmp    11a4 <processes_info_load+0x34>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     120c <processes_info_load+0x9c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1207 <processes_info_load+0x97>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <get_process_info@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fe <processes_info_load+0x8e>
jmp    11a4 <processes_info_load+0x34>
mov    -0x20(%rbp),%rdi
call   1040 <process_info_add@plt>
jmp    11a4 <processes_info_load+0x34>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processes_info_load>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     11e9 <processes_info_load+0x79>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11dd <processes_info_load+0x6d>
mov    %rax,%rbx
jmp    11b0 <processes_info_load+0x40>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11dd <processes_info_load+0x6d>
mov    (%rbx),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11a0 <processes_info_load+0x30>
mov    (%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1080 <get_process_info@plt>
test   %rax,%rax
je     11a0 <processes_info_load+0x30>
mov    %rax,%rdi
call   1040 <process_info_add@plt>
jmp    11a0 <processes_info_load+0x30>
mov    %r14,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
jmp    11ee <processes_info_load+0x7e>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dirent = type { i32* }
%struct.process_info = type { i32 }
@.str = [6 x i8] c"/proc\00"
define i32 @processes_info_load() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = alloca %struct.process_info*
%5 = alloca i32
%6 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %2
%7 = load i32*, i32** %2
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 -1, i32* %1
br label %40
10: ; preds = %0
br label %11
11: ; preds = %36, %32, %10
%12 = load i32*, i32** %2
%13 = call %struct.dirent* @readdir(i32* %12)
store %struct.dirent* %13, %struct.dirent** %3
%14 = icmp ne %struct.dirent* %13, null
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = load %struct.dirent*, %struct.dirent** %3
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 0
%18 = load i32*, i32** %17
%19 = getelementptr inbounds i32, i32* %18, i64 0
%20 = load i32, i32* %19
%21 = call i64 @isdigit(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %15
%24 = load %struct.dirent*, %struct.dirent** %3
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i32*, i32** %25
%27 = call i32 @atoi(i32* %26)
store i32 %27, i32* %5
%28 = load i32, i32* %5
%29 = call %struct.process_info* @get_process_info(i32 %28)
store %struct.process_info* %29, %struct.process_info** %4
%30 = load %struct.process_info*, %struct.process_info** %4
%31 = icmp ne %struct.process_info* %30, null
br i1 %31, label %33, label %32
32: ; preds = %23
br label %11
33: ; preds = %23
%34 = load %struct.process_info*, %struct.process_info** %4
%35 = call i32 @process_info_add(%struct.process_info* %34)
br label %36
36: ; preds = %33, %15
br label %11
37: ; preds = %11
%38 = load i32*, i32** %2
%39 = call i32 @closedir(i32* %38)
store i32 0, i32* %1
br label %40
40: ; preds = %37, %9
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
%struct.dirent = type { i32* }
%struct.process_info = type { i32 }
@.str = [6 x i8] c"/proc\00"
define i32 @processes_info_load() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %25, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %23, label %6
6: ; preds = %3, %20
%7 = phi %struct.dirent* [ %21, %20 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i32*, i32** %8
%10 = load i32, i32* %9
%11 = tail call i64 @isdigit(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %6
%14 = load i32*, i32** %8
%15 = tail call i32 @atoi(i32* %14)
%16 = tail call %struct.process_info* @get_process_info(i32 %15)
%17 = icmp eq %struct.process_info* %16, null
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = tail call i32 @process_info_add(%struct.process_info* %16)
br label %20
20: ; preds = %6, %18, %13
%21 = tail call %struct.dirent* @readdir(i32* %1)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %23, label %6
23: ; preds = %20, %3
%24 = tail call i32 @closedir(i32* %1)
br label %25
25: ; preds = %0, %23
%26 = phi i32 [ 0, %23 ], [ -1, %0 ]
ret i32 %26
}