#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 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;

/* Variables and functions */
int REG_EXTENDED;
int REG_NEWLINE;
int REG_NOMATCH;
int atoi(char *);
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*/ printf(char *, int);
int 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 *);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  regex_t regex;
  int reti = regcomp(&regex, "^PPid:\t([0-9]+)$", REG_EXTENDED | REG_NEWLINE);
  size_t number_of_pmatches = 2;
  regmatch_t pmatch[number_of_pmatches];
  if (reti) {
    fprintf(stderr, "Could not compile regex\n");
    return 1;
  }
  char buff[255];
  FILE *stat_file = fopen("/proc/self/status", "r");
  char pid_buff[10];
  int pid = -1;
  while (NULL != fgets(buff, sizeof(buff), stat_file)) {
    reti = regexec(&regex, buff, number_of_pmatches, pmatch, 0);
    if (0 == reti) {
      buff[pmatch[1].rm_eo] = 0;
      strcpy(pid_buff, &buff[pmatch[1].rm_so]);
      pid = atoi(pid_buff);
      break;
    } else if (reti == REG_NOMATCH) {
      continue;
    } else {
      regerror(reti, &regex, buff, sizeof(buff));
      fprintf(stderr, "Regex match failed: %s\n", buff);
      fclose(stat_file);
      regfree(&regex);
      return 1;
    }
  }
  if (1 != pid) {
    fclose(stat_file);
    strcpy(buff, "/proc/");
    strcat(buff, pid_buff);
    strcat(buff, "/status");
    stat_file = fopen(buff, "r");
    while (NULL != fgets(buff, sizeof(buff), stat_file)) {
      reti = regexec(&regex, buff, number_of_pmatches, pmatch, 0);
      if (0 == reti) {
        buff[pmatch[1].rm_eo] = 0;
        pid = atoi(&buff[pmatch[1].rm_so]);
        break;
      } else if (reti == REG_NOMATCH) {
        continue;
      } else {
        regerror(reti, &regex, buff, sizeof(buff));
        fprintf(stderr, "Regex match failed: %s\n", buff);
        fclose(stat_file);
        regfree(&regex);
        return 1;
      }
    }
  }
  printf("%d\n", pid);
  fclose(stat_file);
  regfree(&regex);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edx
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
or     %eax,%edx
lea    0xe13(%rip),%rsi
lea    -0x8(%rbp),%rdi
call   1070 <regcomp@plt>
mov    %eax,-0xc(%rbp)
movq   $0x2,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
shl    $0x4,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x150(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     125b <main+0x9b>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1526 <main+0x366>
lea    0xdc8(%rip),%rdi
lea    0xdd3(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x138(%rbp)
movl   $0xffffffff,-0x148(%rbp)
ff ff ff
lea    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rdx
mov    $0xff,%esi
call   1080 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1387 <main+0x1c7>
mov    -0x150(%rbp),%rcx
lea    -0x130(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x8(%rbp),%rdi
xor    %r8d,%r8d
call   10b0 <regexec@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jne    1312 <main+0x152>
mov    -0x150(%rbp),%rax
mov    0x10(%rax),%rcx
movb   $0x0,-0x130(%rbp,%rcx,1)
lea    -0x142(%rbp),%rdi
lea    -0x130(%rbp),%rsi
add    0x18(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x142(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x148(%rbp)
jmp    1387 <main+0x1c7>
mov    -0xc(%rbp),%eax
mov    0x2cc4(%rip),%rcx
cmp    (%rcx),%eax
jne    1329 <main+0x169>
jmp    127f <main+0xbf>
mov    -0xc(%rbp),%edi
lea    -0x130(%rbp),%rdx
lea    -0x8(%rbp),%rsi
mov    $0xff,%ecx
call   10a0 <regerror@plt>
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rdx
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x138(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x8(%rbp),%rdi
call   1050 <regfree@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1526 <main+0x366>
mov    $0x1,%eax
cmp    -0x148(%rbp),%eax
je     14f1 <main+0x331>
mov    -0x138(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x130(%rbp),%rdi
lea    0xca4(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x130(%rbp),%rdi
lea    -0x142(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0x130(%rbp),%rdi
lea    0xc5c(%rip),%rsi
call   10e0 <strcat@plt>
lea    -0x130(%rbp),%rdi
lea    0xc51(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rdx
mov    $0xff,%esi
call   1080 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     14ec <main+0x32c>
mov    -0x150(%rbp),%rcx
lea    -0x130(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x8(%rbp),%rdi
xor    %r8d,%r8d
call   10b0 <regexec@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jne    1477 <main+0x2b7>
mov    -0x150(%rbp),%rax
mov    0x10(%rax),%rcx
movb   $0x0,-0x130(%rbp,%rcx,1)
lea    -0x130(%rbp),%rdi
add    0x18(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x148(%rbp)
jmp    14ec <main+0x32c>
mov    -0xc(%rbp),%eax
mov    0x2b5f(%rip),%rcx
cmp    (%rcx),%eax
jne    148e <main+0x2ce>
jmp    13f7 <main+0x237>
mov    -0xc(%rbp),%edi
lea    -0x130(%rbp),%rdx
lea    -0x8(%rbp),%rsi
mov    $0xff,%ecx
call   10a0 <regerror@plt>
mov    0x2b23(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rdx
lea    0xb81(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x138(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x8(%rbp),%rdi
call   1050 <regfree@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    1526 <main+0x366>
jmp    14f1 <main+0x331>
mov    -0x148(%rbp),%esi
lea    0xb5f(%rip),%rdi
call   1060 <printf@plt>
mov    -0x138(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x8(%rbp),%rdi
call   1050 <regfree@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    0x2df0(%rip),%rax
mov    0x2e09(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe16(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1070 <regcomp@plt>
mov    %rsp,%r12
test   %eax,%eax
je     121c <main+0x5c>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%ebx
jmp    1417 <main+0x257>
lea    0xe07(%rip),%rdi
lea    0xe12(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
lea    0x40(%rsp),%rbp
lea    0x4(%rsp),%r14
lea    0x20(%rsp),%rbx
mov    0x2d98(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     12c2 <main+0x102>
mov    $0x2,%edx
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
call   10b0 <regexec@plt>
test   %eax,%eax
je     12ca <main+0x10a>
cmp    0x0(%r13),%eax
je     1250 <main+0x90>
lea    0x4(%rsp),%rsi
lea    0x40(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   10a0 <regerror@plt>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%ebx
jmp    1405 <main+0x245>
mov    $0xffffffff,%r14d
jmp    1302 <main+0x142>
mov    0x30(%rsp),%rax
movb   $0x0,0x40(%rsp,%rax,1)
add    0x38(%rsp),%rbp
lea    0x16(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   10d0 <atoi@plt>
mov    %eax,%r14d
mov    $0x1,%esi
cmp    $0x1,%eax
je     13f7 <main+0x237>
mov    %r12,0x8(%rsp)
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0xd40(%rip),%rsi
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0x16(%rsp),%rsi
mov    %rbp,%rdi
call   10e0 <strcat@plt>
lea    0xcfd(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <strcat@plt>
lea    0xcf6(%rip),%rsi
mov    %rbp,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r15
lea    0x4(%rsp),%r12
lea    0x20(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     13d4 <main+0x214>
mov    $0x2,%edx
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %rbx,%rcx
xor    %r8d,%r8d
call   10b0 <regexec@plt>
test   %eax,%eax
je     13d9 <main+0x219>
cmp    0x0(%r13),%eax
je     1360 <main+0x1a0>
lea    0x4(%rsp),%rsi
lea    0x40(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rdx
mov    $0xff,%ecx
call   10a0 <regerror@plt>
mov    0x2c1b(%rip),%rax
mov    (%rax),%edi
lea    0xc80(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%ebx
mov    0x8(%rsp),%r12
jmp    1405 <main+0x245>
mov    %r14d,%esi
jmp    13f2 <main+0x232>
mov    0x30(%rsp),%rax
movb   $0x0,0x40(%rsp,%rax,1)
add    0x38(%rsp),%rbp
mov    %rbp,%rdi
call   10d0 <atoi@plt>
mov    %eax,%esi
mov    0x8(%rsp),%r12
lea    0xc5f(%rip),%rdi
call   1060 <printf@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1040 <fclose@plt>
lea    0x4(%rsp),%rdi
call   1050 <regfree@plt>
mov    %r12,%rsp
mov    %ebx,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64 }
@.str = [17 x i8] c"^PPid:\09([0-9]+)$\00"
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"Could not compile regex\0A\00"
@.str.2 = [18 x i8] c"/proc/self/status\00"
@.str.3 = [2 x i8] c"r\00"
@REG_NOMATCH = global i32 0
@.str.4 = [24 x i8] c"Regex match failed: %s\0A\00"
@.str.5 = [7 x i8] c"/proc/\00"
@.str.6 = [8 x i8] c"/status\00"
@.str.7 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca [255 x i8]
%9 = alloca i32*
%10 = alloca [10 x i8]
%11 = alloca i32
store i32 0, i32* %1
%12 = load i32, i32* @REG_EXTENDED
%13 = load i32, i32* @REG_NEWLINE
%14 = or i32 %12, %13
%15 = call i32 @regcomp(i32* %2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %3
store i64 2, i64* %4
%16 = load i64, i64* %4
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %5
%18 = alloca %struct.TYPE_3__, i64 %16
store i64 %16, i64* %6
%19 = load i32, i32* %3
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %0
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
store i32 1, i32* %7
br label %123
24: ; preds = %0
%25 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %25, i32** %9
store i32 -1, i32* %11
br label %26
26: ; preds = %54, %24
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%28 = load i32*, i32** %9
%29 = call i32* @fgets(i8* %27, i32 255, i32* %28)
%30 = icmp ne i32* null, %29
br i1 %30, label %31, label %65
31: ; preds = %26
%32 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%33 = load i64, i64* %4
%34 = call i32 @regexec(i32* %2, i8* %32, i64 %33, %struct.TYPE_3__* %18, i32 0)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp eq i32 0, %35
br i1 %36, label %37, label %50
37: ; preds = %31
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 1
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 0
%40 = load i64, i64* %39
%41 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 %40
store i8 0, i8* %41
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i64 1
%44 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %43, i32 0, i32 1
%45 = load i64, i64* %44
%46 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 %45
%47 = call i32 @strcpy(i8* %42, i8* %46)
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%49 = call i32 @atoi(i8* %48)
store i32 %49, i32* %11
br label %65
50: ; preds = %31
%51 = load i32, i32* %3
%52 = load i32, i32* @REG_NOMATCH
%53 = icmp eq i32 %51, %52
br i1 %53, label %54, label %55
54: ; preds = %50
br label %26
55: ; preds = %50
%56 = load i32, i32* %3
%57 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%58 = call i32 @regerror(i32 %56, i32* %2, i8* %57, i32 255)
%59 = load i32, i32* @stderr
%60 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %60)
%62 = load i32*, i32** %9
%63 = call i32 @fclose(i32* %62)
%64 = call i32 @regfree(i32* %2)
store i32 1, i32* %1
store i32 1, i32* %7
br label %123
65: ; preds = %37, %26
%66 = load i32, i32* %11
%67 = icmp ne i32 1, %66
br i1 %67, label %68, label %117
68: ; preds = %65
%69 = load i32*, i32** %9
%70 = call i32 @fclose(i32* %69)
%71 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%72 = call i32 @strcpy(i8* %71, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%73 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%74 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%75 = call i32 @strcat(i8* %73, i8* %74)
%76 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%77 = call i32 @strcat(i8* %76, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%78 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%79 = call i32* @fopen(i8* %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %79, i32** %9
br label %80
80: ; preds = %105, %68
%81 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%82 = load i32*, i32** %9
%83 = call i32* @fgets(i8* %81, i32 255, i32* %82)
%84 = icmp ne i32* null, %83
br i1 %84, label %85, label %116
85: ; preds = %80
%86 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%87 = load i64, i64* %4
%88 = call i32 @regexec(i32* %2, i8* %86, i64 %87, %struct.TYPE_3__* %18, i32 0)
store i32 %88, i32* %3
%89 = load i32, i32* %3
%90 = icmp eq i32 0, %89
br i1 %90, label %91, label %101
91: ; preds = %85
%92 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, 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]* %8, i64 0, i64 %94
store i8 0, i8* %95
%96 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, 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]* %8, i64 0, i64 %98
%100 = call i32 @atoi(i8* %99)
store i32 %100, i32* %11
br label %116
101: ; preds = %85
%102 = load i32, i32* %3
%103 = load i32, i32* @REG_NOMATCH
%104 = icmp eq i32 %102, %103
br i1 %104, label %105, label %106
105: ; preds = %101
br label %80
106: ; preds = %101
%107 = load i32, i32* %3
%108 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%109 = call i32 @regerror(i32 %107, i32* %2, i8* %108, i32 255)
%110 = load i32, i32* @stderr
%111 = getelementptr inbounds [255 x i8], [255 x i8]* %8, i64 0, i64 0
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %111)
%113 = load i32*, i32** %9
%114 = call i32 @fclose(i32* %113)
%115 = call i32 @regfree(i32* %2)
store i32 1, i32* %1
store i32 1, i32* %7
br label %123
116: ; preds = %91, %80
br label %117
117: ; preds = %116, %65
%118 = load i32, i32* %11
%119 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %118)
%120 = load i32*, i32** %9
%121 = call i32 @fclose(i32* %120)
%122 = call i32 @regfree(i32* %2)
store i32 0, i32* %1
store i32 1, i32* %7
br label %123
123: ; preds = %117, %106, %55, %21
%124 = load i8*, i8** %5
%125 = load i32, i32* %1
ret i32 %125
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
@.str = [17 x i8] c"^PPid:\09([0-9]+)$\00"
@REG_EXTENDED = global i32 0
@REG_NEWLINE = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"Could not compile regex\0A\00"
@.str.2 = [18 x i8] c"/proc/self/status\00"
@.str.3 = [2 x i8] c"r\00"
@REG_NOMATCH = global i32 0
@.str.4 = [24 x i8] c"Regex match failed: %s\0A\00"
@.str.5 = [7 x i8] c"/proc/\00"
@.str.6 = [8 x i8] c"/status\00"
@.str.7 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [255 x i8]
%3 = alloca [10 x i8]
%4 = bitcast i32* %1 to i8*
%5 = load i32, i32* @REG_EXTENDED
%6 = load i32, i32* @REG_NEWLINE
%7 = or i32 %6, %5
%8 = call i32 @regcomp(i32* %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i8* @llvm.stacksave()
%10 = alloca [2 x %struct.TYPE_3__]
%11 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %10, i64 0, i64 0
%12 = icmp eq i32 %8, 0
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %80
16: ; preds = %0
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%18 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
br label %20
20: ; preds = %26, %16
%21 = call i32* @fgets(i8* %17, i32 255, i32* %18)
%22 = icmp eq i32* %21, null
br i1 %22, label %43, label %23
23: ; preds = %20
%24 = call i32 @regexec(i32* %1, i8* %17, i64 2, %struct.TYPE_3__* %11, i32 0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %23
%27 = load i32, i32* @REG_NOMATCH
%28 = icmp eq i32 %24, %27
br i1 %28, label %20, label %29
29: ; preds = %26
%30 = call i32 @regerror(i32 %24, i32* %1, i8* %17, i32 255)
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %17)
br label %75
33: ; preds = %23
%34 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %10, i64 0, i64 1, i32 0
%35 = load i64, i64* %34
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 %35
store i8 0, i8* %36
%37 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %10, i64 0, i64 1, i32 1
%38 = load i64, i64* %37
%39 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 %38
%40 = call i32 @strcpy(i8* %19, i8* %39)
%41 = call i32 @atoi(i8* %19)
%42 = icmp eq i32 %41, 1
br i1 %42, label %71, label %43
43: ; preds = %20, %33
%44 = phi i32 [ %41, %33 ], [ -1, %20 ]
%45 = call i32 @fclose(i32* %18)
%46 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @strcat(i8* %17, i8* %19)
%48 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%49 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %64, %43
%51 = call i32* @fgets(i8* %17, i32 255, i32* %49)
%52 = icmp eq i32* %51, null
br i1 %52, label %71, label %53
53: ; preds = %50
%54 = call i32 @regexec(i32* %1, i8* %17, i64 2, %struct.TYPE_3__* %11, i32 0)
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %64
56: ; preds = %53
%57 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %10, i64 0, i64 1, i32 0
%58 = load i64, i64* %57
%59 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 %58
store i8 0, i8* %59
%60 = getelementptr inbounds [2 x %struct.TYPE_3__], [2 x %struct.TYPE_3__]* %10, i64 0, i64 1, i32 1
%61 = load i64, i64* %60
%62 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 %61
%63 = call i32 @atoi(i8* %62)
br label %71
64: ; preds = %53
%65 = load i32, i32* @REG_NOMATCH
%66 = icmp eq i32 %54, %65
br i1 %66, label %50, label %67
67: ; preds = %64
%68 = call i32 @regerror(i32 %54, i32* %1, i8* %17, i32 255)
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %17)
br label %75
71: ; preds = %50, %56, %33
%72 = phi i32* [ %49, %56 ], [ %18, %33 ], [ %49, %50 ]
%73 = phi i32 [ %63, %56 ], [ 1, %33 ], [ %44, %50 ]
%74 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %71, %67, %29
%76 = phi i32* [ %72, %71 ], [ %49, %67 ], [ %18, %29 ]
%77 = phi i32 [ 0, %71 ], [ 1, %67 ], [ 1, %29 ]
%78 = call i32 @fclose(i32* %76)
%79 = call i32 @regfree(i32* %1)
br label %80
80: ; preds = %75, %13
%81 = phi i32 [ 1, %13 ], [ %77, %75 ]
ret i32 %81
}