#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 {
  scalar_t__ d_type;
  char *d_name;
};
typedef int /*<<< orphan*/ str;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_DIR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ is_int(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strstr(char *, char *);
char *strtok(char *, char *);
int main() {
  DIR *dir;
  struct dirent *entry;
  char *istr, *ret;
  char *token;
  char str[100];
  char filename[100];
  int i = 0;
  dir = opendir("/proc");
  if (!dir) {
    perror("diropen");
    exit(1);
  };
  while ((entry = readdir(dir)) != NULL) {
    if (entry->d_type == DT_DIR && is_int(entry->d_name)) {
      strcpy(filename, "/proc/");
      strcat(filename, entry->d_name);
      strcat(filename, "/status");
      FILE *fd = fopen(filename, "r");
      while (!feof(fd)) {
        if (fgets(str, sizeof(str), fd)) {
          istr = strstr(str, "Name");
          if (istr != NULL) {
            token = strtok(str, "\t");
            int iTmp = 0;
            while (token != NULL) {
              if (iTmp == 1) {
                ret = strstr(token, "genenv");
                if (ret != NULL) {
                  printf("%s", token);
                  i++;
                }
              }
              token = strtok(NULL, "\t");
              iTmp++;
            }
          }
        }
      }
      fclose(fd);
    }
  };
  closedir(dir);
  printf("%d\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x114(%rbp)
lea    0xded(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    123d <main+0x4d>
lea    0xdd8(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
jmp    1242 <main+0x52>
mov    -0x10(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1406 <main+0x216>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2d79(%rip),%rcx
cmp    (%rcx),%rax
jne    1401 <main+0x211>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <is_int@plt>
cmp    $0x0,%rax
je     1401 <main+0x211>
lea    -0x110(%rbp),%rdi
lea    0xd79(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
call   10f0 <strcat@plt>
lea    -0x110(%rbp),%rdi
lea    0xd59(%rip),%rsi
call   10f0 <strcat@plt>
lea    -0x110(%rbp),%rdi
lea    0xd4e(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12fc <main+0x10c>
jmp    13f5 <main+0x205>
lea    -0xa0(%rbp),%rdi
mov    -0x120(%rbp),%rdx
mov    $0x64,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     13f0 <main+0x200>
lea    -0xa0(%rbp),%rdi
lea    0xcf3(%rip),%rsi
call   1110 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     13eb <main+0x1fb>
lea    -0xa0(%rbp),%rdi
lea    0xcd6(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x124(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     13e6 <main+0x1f6>
cmpl   $0x1,-0x124(%rbp)
jne    13be <main+0x1ce>
mov    -0x30(%rbp),%rdi
lea    0xca2(%rip),%rsi
call   1110 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     13b9 <main+0x1c9>
mov    -0x30(%rbp),%rsi
lea    0xc8a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    13be <main+0x1ce>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc5b(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    1361 <main+0x171>
jmp    13eb <main+0x1fb>
jmp    13f0 <main+0x200>
jmp    12db <main+0xeb>
mov    -0x120(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1242 <main+0x52>
mov    -0x10(%rbp),%rdi
call   1080 <closedir@plt>
mov    -0x114(%rbp),%esi
lea    0xc14(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
lea    0xdf8(%rip),%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     13ca <main+0x1da>
mov    %rax,%r15
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     1394 <main+0x1a4>
mov    %rax,%rbp
mov    0x2dac(%rip),%rbx
lea    0x80(%rsp),%r14
lea    0xddc(%rip),%r12
lea    0xdda(%rip),%r13
movl   $0x0,0x4(%rsp)
mov    %r15,0x8(%rsp)
jmp    1288 <main+0x98>
nopl   0x0(%rax)
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    0x2d71(%rip),%rbx
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     139c <main+0x1ac>
mov    0x0(%rbp),%rax
cmp    (%rbx),%rax
jne    1274 <main+0x84>
mov    0x8(%rbp),%rdi
call   1070 <is_int@plt>
test   %rax,%rax
je     1274 <main+0x84>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
lea    0xd60(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x8(%rbp),%rsi
mov    %rbx,%rdi
call   10f0 <strcat@plt>
mov    %rbx,%rdi
lea    0xd4c(%rip),%rsi
call   10f0 <strcat@plt>
mov    %rbx,%rdi
lea    0xd45(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
mov    %rax,%rdi
jmp    12f3 <main+0x103>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1260 <main+0x70>
mov    %r14,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12f0 <main+0x100>
mov    %r14,%rdi
mov    %r12,%rsi
call   1110 <strstr@plt>
test   %rax,%rax
je     12f0 <main+0x100>
mov    %r14,%rdi
mov    %r13,%rsi
call   10e0 <strtok@plt>
test   %rax,%rax
je     12f0 <main+0x100>
xor    %edi,%edi
mov    %r13,%rsi
call   10e0 <strtok@plt>
test   %rax,%rax
je     12f0 <main+0x100>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xcd5(%rip),%rsi
call   1110 <strstr@plt>
test   %rax,%rax
je     1380 <main+0x190>
lea    0xccb(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
addl   $0x1,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r13,%rsi
call   10e0 <strtok@plt>
test   %rax,%rax
jne    1380 <main+0x190>
jmp    12f0 <main+0x100>
movl   $0x0,0x4(%rsp)
mov    %r15,%rdi
call   1080 <closedir@plt>
lea    0xc85(%rip),%rdi
mov    0x4(%rsp),%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc35(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i64, i8* }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [8 x i8] c"diropen\00"
@DT_DIR = global i64 0
@.str.2 = [7 x i8] c"/proc/\00"
@.str.3 = [8 x i8] c"/status\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [5 x i8] c"Name\00"
@.str.6 = [2 x i8] c"\09\00"
@.str.7 = [7 x i8] c"genenv\00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [100 x i8]
%8 = alloca [100 x i8]
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %9
%12 = call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %2
%13 = load i32*, i32** %2
%14 = icmp ne i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %0
%16 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %0
br label %19
19: ; preds = %92, %18
%20 = load i32*, i32** %2
%21 = call %struct.dirent* @readdir(i32* %20)
store %struct.dirent* %21, %struct.dirent** %3
%22 = icmp ne %struct.dirent* %21, null
br i1 %22, label %23, label %93
23: ; preds = %19
%24 = load %struct.dirent*, %struct.dirent** %3
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = load i64, i64* @DT_DIR
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %92
29: ; preds = %23
%30 = load %struct.dirent*, %struct.dirent** %3
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 1
%32 = load i8*, i8** %31
%33 = call i64 @is_int(i8* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %92
35: ; preds = %29
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%37 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%39 = load %struct.dirent*, %struct.dirent** %3
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i32 0, i32 1
%41 = load i8*, i8** %40
%42 = call i32 @strcat(i8* %38, i8* %41)
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %46, i32** %10
br label %47
47: ; preds = %88, %35
%48 = load i32*, i32** %10
%49 = call i32 @feof(i32* %48)
%50 = icmp ne i32 %49, 0
%51 = xor i1 %50, true
br i1 %51, label %52, label %89
52: ; preds = %47
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%54 = load i32*, i32** %10
%55 = call i64 @fgets(i8* %53, i32 100, i32* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %88
57: ; preds = %52
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%59 = call i8* @strstr(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i8* %59, i8** %4
%60 = load i8*, i8** %4
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %87
62: ; preds = %57
%63 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%64 = call i8* @strtok(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %64, i8** %6
store i32 0, i32* %11
br label %65
65: ; preds = %82, %62
%66 = load i8*, i8** %6
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %86
68: ; preds = %65
%69 = load i32, i32* %11
%70 = icmp eq i32 %69, 1
br i1 %70, label %71, label %82
71: ; preds = %68
%72 = load i8*, i8** %6
%73 = call i8* @strstr(i8* %72, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
store i8* %73, i8** %5
%74 = load i8*, i8** %5
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %81
76: ; preds = %71
%77 = load i8*, i8** %6
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %77)
%79 = load i32, i32* %9
%80 = add nsw i32 %79, 1
store i32 %80, i32* %9
br label %81
81: ; preds = %76, %71
br label %82
82: ; preds = %81, %68
%83 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %83, i8** %6
%84 = load i32, i32* %11
%85 = add nsw i32 %84, 1
store i32 %85, i32* %11
br label %65
86: ; preds = %65
br label %87
87: ; preds = %86, %57
br label %88
88: ; preds = %87, %52
br label %47
89: ; preds = %47
%90 = load i32*, i32** %10
%91 = call i32 @fclose(i32* %90)
br label %92
92: ; preds = %89, %29, %23
br label %19
93: ; preds = %19
%94 = load i32*, i32** %2
%95 = call i32 @closedir(i32* %94)
%96 = load i32, i32* %9
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %96)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i64, i8* }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [8 x i8] c"diropen\00"
@DT_DIR = global i64 0
@.str.2 = [7 x i8] c"/proc/\00"
@.str.3 = [8 x i8] c"/status\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [5 x i8] c"Name\00"
@.str.6 = [2 x i8] c"\09\00"
@.str.7 = [7 x i8] c"genenv\00"
@.str.8 = [3 x i8] c"%s\00"
@.str.9 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call %struct.dirent* @readdir(i32* %5)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %70, label %13
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %66
%14 = phi %struct.dirent* [ %68, %66 ], [ %8, %7 ]
%15 = phi i32 [ %67, %66 ], [ 0, %7 ]
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @DT_DIR
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %66
20: ; preds = %13
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 1
%22 = load i8*, i8** %21
%23 = call i64 @is_int(i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %66, label %25
25: ; preds = %20
%26 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %21
%28 = call i32 @strcat(i8* %4, i8* %27)
%29 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%30 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = call i32 @feof(i32* %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %63
33: ; preds = %25, %59
%34 = phi i32 [ %60, %59 ], [ %15, %25 ]
%35 = call i64 @fgets(i8* %3, i32 100, i32* %30)
%36 = icmp eq i64 %35, 0
br i1 %36, label %59, label %37
37: ; preds = %33
%38 = call i8* @strstr(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%39 = icmp eq i8* %38, null
br i1 %39, label %59, label %40
40: ; preds = %37
%41 = call i8* @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%42 = icmp eq i8* %41, null
br i1 %42, label %59, label %43
43: ; preds = %40
%44 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%45 = icmp eq i8* %44, null
br i1 %45, label %59, label %46
46: ; preds = %43
%47 = call i8* @strstr(i8* %44, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%48 = icmp eq i8* %47, null
br i1 %48, label %52, label %49
49: ; preds = %46
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %44)
%51 = add nsw i32 %34, 1
br label %52
52: ; preds = %49, %46
%53 = phi i32 [ %51, %49 ], [ %34, %46 ]
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%55 = icmp eq i8* %54, null
br i1 %55, label %59, label %56
56: ; preds = %52, %56
%57 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %56
59: ; preds = %56, %43, %52, %40, %37, %33
%60 = phi i32 [ %34, %37 ], [ %34, %33 ], [ %34, %40 ], [ %34, %43 ], [ %53, %52 ], [ %53, %56 ]
%61 = call i32 @feof(i32* %30)
%62 = icmp eq i32 %61, 0
br i1 %62, label %33, label %63
63: ; preds = %59, %25
%64 = phi i32 [ %15, %25 ], [ %60, %59 ]
%65 = call i32 @fclose(i32* %30)
br label %66
66: ; preds = %63, %20, %13
%67 = phi i32 [ %64, %63 ], [ %15, %20 ], [ %15, %13 ]
%68 = call %struct.dirent* @readdir(i32* %5)
%69 = icmp eq %struct.dirent* %68, null
br i1 %69, label %70, label %13
70: ; preds = %66, %7
%71 = phi i32 [ 0, %7 ], [ %67, %66 ]
%72 = call i32 @closedir(i32* %5)
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %71)
ret i32 0
}