#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct dirent {
  char *d_name;
};
struct TYPE_3__ {
  size_t rm_eo;
  size_t rm_so;
};
typedef TYPE_1__ regmatch_t;
typedef int /*<<< orphan*/ regex_t;
typedef int /*<<< orphan*/ buff;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int REG_EXTENDED;
int REG_NEWLINE;
int REG_NOMATCH;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ regerror(int, int /*<<< orphan*/ *, char *, int);
int regexec(int /*<<< orphan*/ *, char *, size_t, TYPE_1__ *,
            int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strcmp(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int main(int argc, const char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Incorrect name of process\n");
    return 1;
  }
  const char *process_name = argv[1];
  regex_t process_name_regex;
  if (regcomp(&process_name_regex, "^Name:\t(.+)$",
              REG_EXTENDED | REG_NEWLINE)) {
    fprintf(stderr, "Could not compile process name regex\n");
    return 1;
  }
  regex_t process_dir_regex;
  if (regcomp(&process_dir_regex, "^[0-9]+$", REG_EXTENDED | REG_NEWLINE)) {
    fprintf(stderr, "Could not compile process dir regex\n");
    regfree(&process_name_regex);
    return 1;
  }
  size_t number_of_pmatches = 2;
  regmatch_t pmatch[number_of_pmatches];
  int reti;
  char buff[255];
  char stat_file_path[255];
  const char *stat_file_name = "/status";
  const char *proc_dir_name = "/proc/";
  DIR *proc_dir = opendir(proc_dir_name);
  struct dirent *process_dir;
  FILE *stat_file;
  int same_name_process_counter = 0;
  while (NULL != (process_dir = readdir(proc_dir))) {
    reti = regexec(&process_dir_regex, process_dir->d_name, 0, NULL, 0);
    if (0 == reti) {
      strcpy(stat_file_path, proc_dir_name);
      strcat(stat_file_path, process_dir->d_name);
      strcat(stat_file_path, stat_file_name);
      stat_file = fopen(stat_file_path, "r");
      while (NULL != fgets(buff, sizeof(buff), stat_file)) {
        reti =
            regexec(&process_name_regex, buff, number_of_pmatches, pmatch, 0);
        if (0 == reti) {
          buff[pmatch[1].rm_eo] = 0;
          if (0 == strcmp(&buff[pmatch[1].rm_so], process_name)) {
            same_name_process_counter++;
          }
          break;
        } else if (reti == REG_NOMATCH) {
          continue;
        } else {
          regerror(reti, &process_name_regex, buff, sizeof(buff));
          fprintf(stderr, "Regex match failed: %s\n", buff);
          closedir(proc_dir);
          fclose(stat_file);
          regfree(&process_dir_regex);
          regfree(&process_name_regex);
          return 1;
        }
      }
    } else if (reti == REG_NOMATCH) {
      continue;
    } else {
      regerror(reti, &process_dir_regex, buff, sizeof(buff));
      fprintf(stderr, "Process dir name regex match failed: %s\n", buff);
      closedir(proc_dir);
      fclose(stat_file);
      regfree(&process_dir_regex);
      regfree(&process_name_regex);
      return 1;
    }
  }
  printf("%d\n", same_name_process_counter);
  closedir(proc_dir);
  fclose(stat_file);
  regfree(&process_dir_regex);
  regfree(&process_name_regex);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1236 <main+0x46>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1605 <main+0x415>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
mov    0x2d96(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
lea    0xdbc(%rip),%rsi
call   1090 <regcomp@plt>
cmp    $0x0,%rax
je     1291 <main+0xa1>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1605 <main+0x415>
mov    0x2d30(%rip),%rax
mov    (%rax),%edx
mov    0x2d47(%rip),%rax
or     (%rax),%edx
lea    -0x20(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1090 <regcomp@plt>
cmp    $0x0,%rax
je     12e9 <main+0xf9>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <regfree@plt>
movl   $0x1,-0x4(%rbp)
jmp    1605 <main+0x415>
movq   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
shl    $0x4,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x278(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    0xd5e(%rip),%rax
mov    %rax,-0x248(%rbp)
lea    0xd58(%rip),%rax
mov    %rax,-0x250(%rbp)
mov    -0x250(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x258(%rbp)
movl   $0x0,-0x26c(%rbp)
mov    -0x258(%rbp),%rdi
call   10e0 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x260(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     15b1 <main+0x3c1>
mov    -0x260(%rbp),%rax
mov    (%rax),%rsi
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
mov    %rcx,%rdx
call   10f0 <regexec@plt>
mov    %eax,-0x3c(%rbp)
xor    %eax,%eax
cmp    -0x3c(%rbp),%eax
jne    151f <main+0x32f>
lea    -0x240(%rbp),%rdi
mov    -0x250(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x240(%rbp),%rdi
mov    -0x260(%rbp),%rax
mov    (%rax),%rsi
call   1110 <strcat@plt>
lea    -0x240(%rbp),%rdi
mov    -0x248(%rbp),%rsi
call   1110 <strcat@plt>
lea    -0x240(%rbp),%rdi
lea    0xca5(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x268(%rbp)
lea    -0x140(%rbp),%rdi
mov    -0x268(%rbp),%rdx
mov    $0xff,%esi
call   10a0 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     151a <main+0x32a>
mov    -0x278(%rbp),%rcx
lea    -0x140(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
call   10f0 <regexec@plt>
mov    %eax,-0x3c(%rbp)
xor    %eax,%eax
cmp    -0x3c(%rbp),%eax
jne    148d <main+0x29d>
mov    -0x278(%rbp),%rax
mov    0x10(%rax),%rcx
movb   $0x0,-0x140(%rbp,%rcx,1)
lea    -0x140(%rbp),%rdi
add    0x18(%rax),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1488 <main+0x298>
mov    -0x26c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x26c(%rbp)
jmp    151a <main+0x32a>
mov    -0x3c(%rbp),%eax
mov    0x2b49(%rip),%rcx
cmp    (%rcx),%eax
jne    14a4 <main+0x2b4>
jmp    13f2 <main+0x202>
mov    -0x3c(%rbp),%edi
lea    -0x140(%rbp),%rdx
lea    -0x1c(%rbp),%rsi
mov    $0xff,%ecx
call   10d0 <regerror@plt>
mov    0x2b0d(%rip),%rax
mov    (%rax),%edi
lea    -0x140(%rbp),%rdx
lea    0xbba(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x258(%rbp),%rdi
call   1080 <closedir@plt>
mov    -0x268(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x20(%rbp),%rdi
call   1060 <regfree@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <regfree@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x270(%rbp)
jmp    15fe <main+0x40e>
jmp    15ac <main+0x3bc>
mov    -0x3c(%rbp),%eax
mov    0x2ab7(%rip),%rcx
cmp    (%rcx),%eax
jne    1536 <main+0x346>
jmp    1350 <main+0x160>
mov    -0x3c(%rbp),%edi
lea    -0x140(%rbp),%rdx
lea    -0x20(%rbp),%rsi
mov    $0xff,%ecx
call   10d0 <regerror@plt>
mov    0x2a7b(%rip),%rax
mov    (%rax),%edi
lea    -0x140(%rbp),%rdx
lea    0xb40(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x258(%rbp),%rdi
call   1080 <closedir@plt>
mov    -0x268(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x20(%rbp),%rdi
call   1060 <regfree@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <regfree@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x270(%rbp)
jmp    15fe <main+0x40e>
jmp    1350 <main+0x160>
mov    -0x26c(%rbp),%esi
lea    0xb10(%rip),%rdi
call   1070 <printf@plt>
mov    -0x258(%rbp),%rdi
call   1080 <closedir@plt>
mov    -0x268(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x20(%rbp),%rdi
call   1060 <regfree@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <regfree@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x270(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
cmp    $0x1,%edi
jg     121b <main+0x2b>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
jmp    1257 <main+0x67>
mov    0x8(%rsi),%r15
mov    0x2da2(%rip),%r14
mov    0x2dbb(%rip),%rbx
mov    (%rbx),%edx
or     (%r14),%edx
lea    0xde2(%rip),%rsi
lea    -0x30(%rbp),%rdi
call   1090 <regcomp@plt>
test   %rax,%rax
je     1274 <main+0x84>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rbx),%edx
or     (%r14),%edx
lea    0xdce(%rip),%rsi
lea    -0x2c(%rbp),%rdi
call   1090 <regcomp@plt>
test   %rax,%rax
je     12b0 <main+0xc0>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
lea    -0x30(%rbp),%rdi
call   1060 <regfree@plt>
jmp    125e <main+0x6e>
mov    %r15,-0x48(%rbp)
mov    %rsp,-0x50(%rbp)
mov    %rsp,%r12
add    $0xffffffffffffffe0,%r12
mov    %r12,%rsp
lea    0xdbb(%rip),%rdi
call   1050 <opendir@plt>
mov    %rax,%r14
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
lea    -0x2c(%rbp),%r13
mov    0x2cfe(%rip),%r15
mov    %rbx,-0x40(%rbp)
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
je     13f7 <main+0x207>
mov    %rax,%rbx
mov    (%rax),%rsi
mov    %r13,%rdi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10f0 <regexec@plt>
test   %eax,%eax
je     1324 <main+0x134>
cmp    (%r15),%eax
je     12f0 <main+0x100>
jmp    140b <main+0x21b>
lea    -0x250(%rbp),%r13
mov    %r13,%rdi
lea    0xd4f(%rip),%rsi
call   1030 <strcpy@plt>
mov    (%rbx),%rsi
mov    %r13,%rdi
call   1110 <strcat@plt>
mov    %r13,%rdi
lea    0xd2d(%rip),%rsi
call   1110 <strcat@plt>
mov    %r13,%rdi
lea    0xd2d(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
lea    -0x150(%rbp),%r13
mov    %r13,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     13b1 <main+0x1c1>
mov    $0x2,%edx
lea    -0x30(%rbp),%rdi
mov    %r13,%rsi
mov    %r12,%rcx
xor    %r8d,%r8d
call   10f0 <regexec@plt>
test   %eax,%eax
je     13ba <main+0x1ca>
cmp    (%r15),%eax
je     1370 <main+0x180>
jmp    1437 <main+0x247>
lea    -0x2c(%rbp),%r13
jmp    12e2 <main+0xf2>
mov    0x10(%r12),%rax
movb   $0x0,-0x150(%rbp,%rax,1)
mov    0x18(%r12),%rdi
lea    -0x150(%rbp),%rax
add    %rax,%rdi
mov    -0x48(%rbp),%rsi
call   10b0 <strcmp@plt>
cmp    $0x1,%rax
mov    -0x38(%rbp),%rax
adc    $0x0,%eax
mov    %rax,-0x38(%rbp)
lea    -0x2c(%rbp),%r13
jmp    12e2 <main+0xf2>
lea    0xcd0(%rip),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <printf@plt>
xor    %ebx,%ebx
jmp    1474 <main+0x284>
lea    -0x2c(%rbp),%rsi
lea    -0x150(%rbp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   10d0 <regerror@plt>
mov    0x2ba4(%rip),%rax
mov    (%rax),%edi
lea    0xc70(%rip),%rsi
jmp    1465 <main+0x275>
mov    %rbx,-0x40(%rbp)
lea    -0x30(%rbp),%rsi
lea    -0x150(%rbp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   10d0 <regerror@plt>
mov    0x2b74(%rip),%rax
mov    (%rax),%edi
lea    0xc28(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%ebx
mov    %r14,%rdi
call   1080 <closedir@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x2c(%rbp),%rdi
call   1060 <regfree@plt>
lea    -0x30(%rbp),%rdi
call   1060 <regfree@plt>
mov    -0x50(%rbp),%rsp
jmp    1263 <main+0x73>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.TYPE_3__ = type { i64, i64 }
@stderr = global i32 0
@.str = [27 x i8] c"Incorrect name of process\0A\00"
@.str.1 = [13 x i8] c"^Name:\09(.+)$\00"
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@.str.2 = [38 x i8] c"Could not compile process name regex\0A\00"
@.str.3 = [9 x i8] c"^[0-9]+$\00"
@.str.4 = [37 x i8] c"Could not compile process dir regex\0A\00"
@.str.5 = [8 x i8] c"/status\00"
@.str.6 = [7 x i8] c"/proc/\00"
@.str.7 = [2 x i8] c"r\00"
@REG_NOMATCH = global i32 0
@.str.8 = [24 x i8] c"Regex match failed: %s\0A\00"
@.str.9 = [41 x i8] c"Process dir name regex match failed: %s\0A\00"
@.str.10 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca [255 x i8]
%14 = alloca [255 x i8]
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32*
%18 = alloca %struct.dirent*
%19 = alloca i32*
%20 = alloca i32
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 2
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %156
27: ; preds = %2
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
store i8* %30, i8** %6
%31 = load i32, i32* @REG_EXTENDED
%32 = load i32, i32* @REG_NEWLINE
%33 = or i32 %31, %32
%34 = call i64 @regcomp(i32* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %27
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %156
39: ; preds = %27
%40 = load i32, i32* @REG_EXTENDED
%41 = load i32, i32* @REG_NEWLINE
%42 = or i32 %40, %41
%43 = call i64 @regcomp(i32* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @regfree(i32* %7)
store i32 1, i32* %3
br label %156
49: ; preds = %39
store i64 2, i64* %9
%50 = load i64, i64* %9
%51 = call i8* @llvm.stacksave()
store i8* %51, i8** %10
%52 = alloca %struct.TYPE_3__, i64 %50
store i64 %50, i64* %11
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %15
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8** %16
%53 = load i8*, i8** %16
%54 = call i32* @opendir(i8* %53)
store i32* %54, i32** %17
store i32 0, i32* %20
br label %55
55: ; preds = %144, %130, %49
%56 = load i32*, i32** %17
%57 = call %struct.dirent* @readdir(i32* %56)
store %struct.dirent* %57, %struct.dirent** %18
%58 = icmp ne %struct.dirent* null, %57
br i1 %58, label %59, label %145
59: ; preds = %55
%60 = load %struct.dirent*, %struct.dirent** %18
%61 = getelementptr inbounds %struct.dirent, %struct.dirent* %60, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = call i32 @regexec(i32* %8, i8* %62, i64 0, %struct.TYPE_3__* null, i32 0)
store i32 %63, i32* %12
%64 = load i32, i32* %12
%65 = icmp eq i32 0, %64
br i1 %65, label %66, label %126
66: ; preds = %59
%67 = getelementptr inbounds [255 x i8], [255 x i8]* %14, i64 0, i64 0
%68 = load i8*, i8** %16
%69 = call i32 @strcpy(i8* %67, i8* %68)
%70 = getelementptr inbounds [255 x i8], [255 x i8]* %14, i64 0, i64 0
%71 = load %struct.dirent*, %struct.dirent** %18
%72 = getelementptr inbounds %struct.dirent, %struct.dirent* %71, i32 0, i32 0
%73 = load i8*, i8** %72
%74 = call i32 @strcat(i8* %70, i8* %73)
%75 = getelementptr inbounds [255 x i8], [255 x i8]* %14, i64 0, i64 0
%76 = load i8*, i8** %15
%77 = call i32 @strcat(i8* %75, i8* %76)
%78 = getelementptr inbounds [255 x i8], [255 x i8]* %14, i64 0, i64 0
%79 = call i32* @fopen(i8* %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %79, i32** %19
br label %80
80: ; preds = %111, %66
%81 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 0
%82 = load i32*, i32** %19
%83 = call i32* @fgets(i8* %81, i32 255, i32* %82)
%84 = icmp ne i32* null, %83
br i1 %84, label %85, label %125
85: ; preds = %80
%86 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 0
%87 = load i64, i64* %9
%88 = call i32 @regexec(i32* %7, i8* %86, i64 %87, %struct.TYPE_3__* %52, i32 0)
store i32 %88, i32* %12
%89 = load i32, i32* %12
%90 = icmp eq i32 0, %89
br i1 %90, label %91, label %107
91: ; preds = %85
%92 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %52, i64 1
%93 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %92, i32 0, i32 0
%94 = load i64, i64* %93
%95 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 %94
store i8 0, i8* %95
%96 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %52, i64 1
%97 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %96, i32 0, i32 1
%98 = load i64, i64* %97
%99 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 %98
%100 = load i8*, i8** %6
%101 = call i64 @strcmp(i8* %99, i8* %100)
%102 = icmp eq i64 0, %101
br i1 %102, label %103, label %106
103: ; preds = %91
%104 = load i32, i32* %20
%105 = add nsw i32 %104, 1
store i32 %105, i32* %20
br label %106
106: ; preds = %103, %91
br label %125
107: ; preds = %85
%108 = load i32, i32* %12
%109 = load i32, i32* @REG_NOMATCH
%110 = icmp eq i32 %108, %109
br i1 %110, label %111, label %112
111: ; preds = %107
br label %80
112: ; preds = %107
%113 = load i32, i32* %12
%114 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 0
%115 = call i32 @regerror(i32 %113, i32* %7, i8* %114, i32 255)
%116 = load i32, i32* @stderr
%117 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 0
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %117)
%119 = load i32*, i32** %17
%120 = call i32 @closedir(i32* %119)
%121 = load i32*, i32** %19
%122 = call i32 @fclose(i32* %121)
%123 = call i32 @regfree(i32* %8)
%124 = call i32 @regfree(i32* %7)
store i32 1, i32* %3
store i32 1, i32* %21
br label %154
125: ; preds = %106, %80
br label %144
126: ; preds = %59
%127 = load i32, i32* %12
%128 = load i32, i32* @REG_NOMATCH
%129 = icmp eq i32 %127, %128
br i1 %129, label %130, label %131
130: ; preds = %126
br label %55
131: ; preds = %126
%132 = load i32, i32* %12
%133 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 0
%134 = call i32 @regerror(i32 %132, i32* %8, i8* %133, i32 255)
%135 = load i32, i32* @stderr
%136 = getelementptr inbounds [255 x i8], [255 x i8]* %13, i64 0, i64 0
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0), i8* %136)
%138 = load i32*, i32** %17
%139 = call i32 @closedir(i32* %138)
%140 = load i32*, i32** %19
%141 = call i32 @fclose(i32* %140)
%142 = call i32 @regfree(i32* %8)
%143 = call i32 @regfree(i32* %7)
store i32 1, i32* %3
store i32 1, i32* %21
br label %154
144: ; preds = %125
br label %55
145: ; preds = %55
%146 = load i32, i32* %20
%147 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32 %146)
%148 = load i32*, i32** %17
%149 = call i32 @closedir(i32* %148)
%150 = load i32*, i32** %19
%151 = call i32 @fclose(i32* %150)
%152 = call i32 @regfree(i32* %8)
%153 = call i32 @regfree(i32* %7)
store i32 0, i32* %3
store i32 1, i32* %21
br label %154
154: ; preds = %145, %131, %112
%155 = load i8*, i8** %10
br label %156
156: ; preds = %154, %45, %36, %24
%157 = load i32, i32* %3
ret i32 %157
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [27 x i8] c"Incorrect name of process\0A\00"
@.str.1 = [13 x i8] c"^Name:\09(.+)$\00"
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@.str.2 = [38 x i8] c"Could not compile process name regex\0A\00"
@.str.3 = [9 x i8] c"^[0-9]+$\00"
@.str.4 = [37 x i8] c"Could not compile process dir regex\0A\00"
@.str.5 = [8 x i8] c"/status\00"
@.str.6 = [7 x i8] c"/proc/\00"
@.str.7 = [2 x i8] c"r\00"
@REG_NOMATCH = global i32 0
@.str.8 = [24 x i8] c"Regex match failed: %s\0A\00"
@.str.9 = [41 x i8] c"Process dir name regex match failed: %s\0A\00"
@.str.10 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [255 x i8]
%6 = alloca [255 x i8]
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %105
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = bitcast i32* %3 to i8*
%15 = load i32, i32* @REG_EXTENDED
%16 = load i32, i32* @REG_NEWLINE
%17 = or i32 %16, %15
%18 = call i64 @regcomp(i32* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
br label %103
23: ; preds = %11
%24 = bitcast i32* %4 to i8*
%25 = load i32, i32* @REG_EXTENDED
%26 = load i32, i32* @REG_NEWLINE
%27 = or i32 %26, %25
%28 = call i64 @regcomp(i32* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @regfree(i32* %3)
br label %101
34: ; preds = %23
%35 = call i8* @llvm.stacksave()
%36 = alloca [2 x %struct.TYPE_3__]
%37 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %36, i64 0, i64 0
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%39 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%40 = call i32* @opendir(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%41 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %36, i64 0, i64 1, i32 0
%42 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %36, i64 0, i64 1, i32 1
br label %43
43: ; preds = %69, %34
%44 = phi i32* [ %62, %69 ], [ undef, %34 ]
%45 = phi i32 [ %77, %69 ], [ 0, %34 ]
br label %46
46: ; preds = %63, %43
%47 = phi i32* [ %44, %43 ], [ %62, %63 ]
br label %48
48: ; preds = %46, %85
%49 = call %struct.dirent* @readdir(i32* %40)
%50 = icmp eq %struct.dirent* %49, null
br i1 %50, label %92, label %51
51: ; preds = %48
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i64 0, i32 0
%53 = load i8*, i8** %52
%54 = call i32 @regexec(i32* %4, i8* %53, i64 0, %struct.TYPE_3__* null, i32 0)
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %85
56: ; preds = %51
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i64 0, i32 0
%58 = call i32 @strcpy(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%59 = load i8*, i8** %57
%60 = call i32 @strcat(i8* %39, i8* %59)
%61 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%62 = call i32* @fopen(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %63
63: ; preds = %78, %56
%64 = call i32* @fgets(i8* %38, i32 255, i32* %62)
%65 = icmp eq i32* %64, null
br i1 %65, label %46, label %66
66: ; preds = %63
%67 = call i32 @regexec(i32* %3, i8* %38, i64 2, %struct.TYPE_3__* %37, i32 0)
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %78
69: ; preds = %66
%70 = load i64, i64* %41
%71 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 %70
store i8 0, i8* %71
%72 = load i64, i64* %42
%73 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 %72
%74 = call i64 @strcmp(i8* %73, i8* %13)
%75 = icmp eq i64 %74, 0
%76 = zext i1 %75 to i32
%77 = add nuw nsw i32 %45, %76
br label %43
78: ; preds = %66
%79 = load i32, i32* @REG_NOMATCH
%80 = icmp eq i32 %67, %79
br i1 %80, label %63, label %81
81: ; preds = %78
%82 = call i32 @regerror(i32 %67, i32* %3, i8* %38, i32 255)
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* %38)
br label %94
85: ; preds = %51
%86 = load i32, i32* @REG_NOMATCH
%87 = icmp eq i32 %54, %86
br i1 %87, label %48, label %88
88: ; preds = %85
%89 = call i32 @regerror(i32 %54, i32* %4, i8* %38, i32 255)
%90 = load i32, i32* @stderr
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0), i8* %38)
br label %94
92: ; preds = %48
%93 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i32 %45)
br label %94
94: ; preds = %92, %88, %81
%95 = phi i32* [ %47, %92 ], [ %47, %88 ], [ %62, %81 ]
%96 = phi i32 [ 0, %92 ], [ 1, %88 ], [ 1, %81 ]
%97 = call i32 @closedir(i32* %40)
%98 = call i32 @fclose(i32* %95)
%99 = call i32 @regfree(i32* %4)
%100 = call i32 @regfree(i32* %3)
br label %101
101: ; preds = %94, %30
%102 = phi i32 [ 1, %30 ], [ %96, %94 ]
br label %103
103: ; preds = %101, %20
%104 = phi i32 [ 1, %20 ], [ %102, %101 ]
br label %105
105: ; preds = %103, %8
%106 = phi i32 [ 1, %8 ], [ %104, %103 ]
ret i32 %106
}