#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 /*<<< orphan*/ add_gcd_pid(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, int /*<<< orphan*/);
int get_pid_list(void) {
  DIR *dir;
  struct dirent *entry;
  dir = opendir("/proc");
  if (dir == NULL)
    return 1;
  for (;;) {
    entry = readdir(dir);
    if (entry) {
      if (strcmp(".", entry->d_name) != 0 && strcmp("..", entry->d_name) != 0)
        add_gcd_pid(entry->d_name);
    } else
      break;
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<get_pid_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    117f <get_pid_list+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    11fe <get_pid_list+0xae>
jmp    1184 <get_pid_list+0x34>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11e4 <get_pid_list+0x94>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11df <get_pid_list+0x8f>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11df <get_pid_list+0x8f>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <add_gcd_pid@plt>
jmp    11e9 <get_pid_list+0x99>
jmp    11ee <get_pid_list+0x9e>
jmp    1184 <get_pid_list+0x34>
mov    -0x10(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pid_list>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11d3 <get_pid_list+0x83>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11c7 <get_pid_list+0x77>
mov    %rax,%rbx
lea    0xe84(%rip),%r14
lea    0xe7c(%rip),%r15
jmp    11a0 <get_pid_list+0x50>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c7 <get_pid_list+0x77>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1190 <get_pid_list+0x40>
mov    (%rbx),%esi
mov    %r15,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1190 <get_pid_list+0x40>
mov    (%rbx),%edi
call   1070 <add_gcd_pid@plt>
jmp    1190 <get_pid_list+0x40>
mov    %r12,%rdi
call   1040 <closedir@plt>
xor    %eax,%eax
jmp    11d8 <get_pid_list+0x88>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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