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

/* Variables and functions */
int atoi(int /*<<< orphan*/ *);
int /*<<< orphan*/ cleanupProcessList();
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ isdigit(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ print_error(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ updateProcess(int);
int updateProcessList(void) {
  DIR *dir;
  struct dirent *entry;
  if ((dir = opendir("/proc")) == NULL) {
    print_error("Cannot open directory \'/proc\'!\n"
                "The kernel needs to be compiled with support\n"
                "for /proc filesystem enabled!\n");
    return 0;
  }
  while ((entry = readdir(dir))) {
    if (isdigit(entry->d_name[0])) {
      int pid;
      pid = atoi(entry->d_name);
      updateProcess(pid);
    }
  }
  closedir(dir);
  cleanupProcessList();
  return 0;
}


x86 assembly (clang, -O0):
<updateProcessList>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe71(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ba <updateProcessList+0x3a>
lea    0xe5d(%rip),%rdi
call   1040 <print_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    1221 <updateProcessList+0xa1>
jmp    11bf <updateProcessList+0x3f>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     120a <updateProcessList+0x8a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1205 <updateProcessList+0x85>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <updateProcess@plt>
jmp    11bf <updateProcessList+0x3f>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
mov    $0x0,%al
call   10a0 <cleanupProcessList@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updateProcessList>:
push   %r14
push   %rbx
push   %rax
lea    0xe75(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     11f1 <updateProcessList+0x71>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11e0 <updateProcessList+0x60>
mov    %rax,%rbx
jmp    11c0 <updateProcessList+0x40>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e0 <updateProcessList+0x60>
mov    (%rbx),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11b0 <updateProcessList+0x30>
mov    (%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1080 <updateProcess@plt>
jmp    11b0 <updateProcessList+0x30>
mov    %r14,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
call   10a0 <cleanupProcessList@plt>
jmp    11fd <updateProcessList+0x7d>
lea    0xe0e(%rip),%rdi
call   1040 <print_error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.dirent = type { i32* }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [107 x i8] c"Cannot open directory '/proc'!\0AThe kernel needs to be compiled with support\0Afor /proc filesystem enabled!\0A\00"
define i32 @updateProcessList() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = alloca i32
%5 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @print_error(i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %1
br label %34
9: ; preds = %0
br label %10
10: ; preds = %29, %9
%11 = load i32*, i32** %2
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %3
%13 = icmp ne %struct.dirent* %12, null
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load %struct.dirent*, %struct.dirent** %3
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 0
%17 = load i32*, i32** %16
%18 = getelementptr inbounds i32, i32* %17, i64 0
%19 = load i32, i32* %18
%20 = call i64 @isdigit(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %14
%23 = load %struct.dirent*, %struct.dirent** %3
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i32*, i32** %24
%26 = call i32 @atoi(i32* %25)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = call i32 @updateProcess(i32 %27)
br label %29
29: ; preds = %22, %14
br label %10
30: ; preds = %10
%31 = load i32*, i32** %2
%32 = call i32 @closedir(i32* %31)
%33 = call i32 (...) @cleanupProcessList()
store i32 0, i32* %1
br label %34
34: ; preds = %30, %7
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
%struct.dirent = type { i32* }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [107 x i8] c"Cannot open directory '/proc'!\0AThe kernel needs to be compiled with support\0Afor /proc filesystem enabled!\0A\00"
define i32 @updateProcessList() {
%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 %6, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %22, label %8
6: ; preds = %0
%7 = tail call i32 @print_error(i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.1, i64 0, i64 0))
br label %25
8: ; preds = %3, %19
%9 = phi %struct.dirent* [ %20, %19 ], [ %4, %3 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i32*, i32** %10
%12 = load i32, i32* %11
%13 = tail call i64 @isdigit(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %8
%16 = load i32*, i32** %10
%17 = tail call i32 @atoi(i32* %16)
%18 = tail call i32 @updateProcess(i32 %17)
br label %19
19: ; preds = %15, %8
%20 = tail call %struct.dirent* @readdir(i32* %1)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %22, label %8
22: ; preds = %19, %3
%23 = tail call i32 @closedir(i32* %1)
%24 = tail call i32 (...) @cleanupProcessList()
br label %25
25: ; preds = %22, %6
ret i32 0
}