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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ atoi(int /*<<< orphan*/ *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isdigit(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ proc_info_get(int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void proc_info_get_all(void) {
  DIR *dir;
  struct dirent *dirp;
  dir = opendir("/proc");
  if (dir == NULL) {
    (void)fprintf(stderr, "Cannot open /proc, is it mounted?\n");
    exit(EXIT_FAILURE);
  }
  while ((dirp = readdir(dir)) != NULL) {
    if (isdigit(dirp->d_name[0])) {
      pid_t pid = atoi(dirp->d_name);
      (void)proc_info_get(pid);
    }
  }
  (void)closedir(dir);
}


x86 assembly (clang, -O0):
<proc_info_get_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe71(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c6 <proc_info_get_all+0x46>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    11cb <proc_info_get_all+0x4b>
mov    -0x8(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1216 <proc_info_get_all+0x96>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1211 <proc_info_get_all+0x91>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <proc_info_get@plt>
jmp    11cb <proc_info_get_all+0x4b>
mov    -0x8(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_info_get_all>:
push   %r14
push   %rbx
push   %rax
lea    0xe75(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11ef <proc_info_get_all+0x6f>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11e0 <proc_info_get_all+0x60>
mov    %rax,%rbx
jmp    11c0 <proc_info_get_all+0x40>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e0 <proc_info_get_all+0x60>
mov    (%rbx),%rax
mov    (%rax),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11b0 <proc_info_get_all+0x30>
mov    (%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1050 <proc_info_get@plt>
jmp    11b0 <proc_info_get_all+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <closedir@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32* }
@.str = [6 x i8] c"/proc\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"Cannot open /proc, is it mounted?\0A\00"
@EXIT_FAILURE = global i32 0
define void @proc_info_get_all() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = alloca i32
%4 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
br label %13
13: ; preds = %32, %12
%14 = load i32*, i32** %1
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %2
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %33
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %2
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i32*, i32** %19
%21 = getelementptr inbounds i32, i32* %20, i64 0
%22 = load i32, i32* %21
%23 = call i64 @isdigit(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %17
%26 = load %struct.dirent*, %struct.dirent** %2
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i32*, i32** %27
%29 = call i32 @atoi(i32* %28)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = call i32 @proc_info_get(i32 %30)
br label %32
32: ; preds = %25, %17
br label %13
33: ; preds = %13
%34 = load i32*, i32** %1
%35 = call i32 @closedir(i32* %34)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32* }
@.str = [6 x i8] c"/proc\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"Cannot open /proc, is it mounted?\0A\00"
@EXIT_FAILURE = global i32 0
define void @proc_info_get_all() {
%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 %25, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3, %22
%12 = phi %struct.dirent* [ %23, %22 ], [ %4, %3 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%14 = load i32*, i32** %13
%15 = load i32, i32* %14
%16 = tail call i64 @isdigit(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %11
%19 = load i32*, i32** %13
%20 = tail call i32 @atoi(i32* %19)
%21 = tail call i32 @proc_info_get(i32 %20)
br label %22
22: ; preds = %18, %11
%23 = tail call %struct.dirent* @readdir(i32* %1)
%24 = icmp eq %struct.dirent* %23, null
br i1 %24, label %25, label %11
25: ; preds = %22, %3
%26 = tail call i32 @closedir(i32* %1)
ret void
}