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

/* Variables and functions */
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ pullPidMemory(int /*<<< orphan*/ *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
long strtol(int /*<<< orphan*/, char **, int);
void pullAllPidMemory(FILE *out_file) {
  DIR *d;
  struct dirent *dir;
  d = opendir("/proc/");
  if (d) {
    while ((dir = readdir(d)) != NULL) {
      long int val;
      char *unused;
      val = strtol(dir->d_name, &unused, 10);
      if (val == 0) {
        continue;
      } else {
        pullPidMemory(out_file, (int)val);
      }
    }
  }
}


x86 assembly (clang, -O0):
<pullAllPidMemory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c4 <pullAllPidMemory+0x84>
jmp    116c <pullAllPidMemory+0x2c>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11bf <pullAllPidMemory+0x7f>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <pullAllPidMemory+0x6b>
jmp    116c <pullAllPidMemory+0x2c>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %eax,%esi
call   1040 <pullPidMemory@plt>
jmp    116c <pullAllPidMemory+0x2c>
jmp    11c4 <pullAllPidMemory+0x84>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pullAllPidMemory>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
lea    0xead(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11ad <pullAllPidMemory+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11ad <pullAllPidMemory+0x6d>
lea    0x8(%rsp),%r15
jmp    118d <pullAllPidMemory+0x4d>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11ad <pullAllPidMemory+0x6d>
mov    (%rax),%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
test   %rax,%rax
je     1180 <pullAllPidMemory+0x40>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <pullPidMemory@plt>
jmp    1180 <pullAllPidMemory+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [7 x i8] c"/proc/\00"
define void @pullAllPidMemory(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i64
%6 = alloca i8*
store i32* %0, i32** %2
%7 = call i32* @opendir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %30
10: ; preds = %1
br label %11
11: ; preds = %28, %22, %10
%12 = load i32*, i32** %3
%13 = call %struct.dirent* @readdir(i32* %12)
store %struct.dirent* %13, %struct.dirent** %4
%14 = icmp ne %struct.dirent* %13, null
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load %struct.dirent*, %struct.dirent** %4
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @strtol(i32 %18, i8** %6, i32 10)
store i64 %19, i64* %5
%20 = load i64, i64* %5
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
br label %11
23: ; preds = %15
%24 = load i32*, i32** %2
%25 = load i64, i64* %5
%26 = trunc i64 %25 to i32
%27 = call i32 @pullPidMemory(i32* %24, i32 %26)
br label %28
28: ; preds = %23
br label %11
29: ; preds = %11
br label %30
30: ; preds = %29, %1
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [7 x i8] c"/proc/\00"
define void @pullAllPidMemory(i32* %0) {
%2 = alloca i8*
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %22, label %5
5: ; preds = %1
%6 = call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %22, label %8
8: ; preds = %5
%9 = bitcast i8** %2 to i8*
br label %10
10: ; preds = %8, %19
%11 = phi %struct.dirent* [ %6, %8 ], [ %20, %19 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i64 @strtol(i32 %13, i8** %2, i32 10)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %10
%17 = trunc i64 %14 to i32
%18 = call i32 @pullPidMemory(i32* %0, i32 %17)
br label %19
19: ; preds = %10, %16
%20 = call %struct.dirent* @readdir(i32* %3)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %22, label %10
22: ; preds = %19, %5, %1
ret void
}