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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ replaceNewLine(char *);
int /*<<< orphan*/ *strdup(char *);
scalar_t__ strstr(char *, char *);
char *strtok(int /*<<< orphan*/ *, char *);
int getStat(char *procsToFind) {
  FILE *fp;
  char path[10000];
  char *procs[50];
  int j = 0;
  int i = 0;
  char *pch;
  pch = strtok(strdup(procsToFind), ",");
  while (pch != NULL) {
    procs[j++] = pch;
    pch = strtok(NULL, ",");
  }
  fp = popen("ps aux", "r");
  if (fp == NULL) {
    printf("Failed to run command\n");
    return 0;
  }
  printf("pushTaskStat([\n");
  while (fgets(path, sizeof(path) - 1, fp) != NULL) {
    for (i = 0; i < j; i++) {
      if (strstr(path, procs[i])) {
        replaceNewLine(path);
        printf("{'procName':'%s','procPath':'%s'},\n", procs[i], path);
      }
    }
  }
  printf("]);");
  pclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<getStat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x28d0,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x28c4(%rbp)
movl   $0x0,-0x28c8(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rdi
lea    0xe4a(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x28d0(%rbp)
cmpq   $0x0,-0x28d0(%rbp)
je     120e <getStat+0x8e>
mov    -0x28d0(%rbp),%rcx
mov    -0x28c4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x28c4(%rbp)
cltq
mov    %rcx,-0x28c0(%rbp,%rax,8)
ff
xor    %eax,%eax
mov    %eax,%edi
lea    0xe03(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x28d0(%rbp)
jmp    11c2 <getStat+0x42>
lea    0xded(%rip),%rdi
lea    0xded(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124a <getStat+0xca>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1324 <getStat+0x1a4>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x2730(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x270f,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1306 <getStat+0x186>
movl   $0x0,-0x28c8(%rbp)
mov    -0x28c8(%rbp),%eax
cmp    -0x28c4(%rbp),%eax
jge    1301 <getStat+0x181>
lea    -0x2730(%rbp),%rdi
movslq -0x28c8(%rbp),%rax
mov    -0x28c0(%rbp,%rax,8),%rsi
ff
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     12e8 <getStat+0x168>
lea    -0x2730(%rbp),%rdi
call   1060 <replaceNewLine@plt>
movslq -0x28c8(%rbp),%rax
mov    -0x28c0(%rbp,%rax,8),%rsi
ff
lea    -0x2730(%rbp),%rdx
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12ed <getStat+0x16d>
mov    -0x28c8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28c8(%rbp)
jmp    1281 <getStat+0x101>
jmp    1258 <getStat+0xd8>
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x28d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getStat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28b8,%rsp
call   10a0 <strdup@plt>
lea    0xe53(%rip),%rsi
mov    %rax,%rdi
call   1090 <strtok@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     11e8 <getStat+0x58>
lea    0xe3c(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,0x10(%rsp,%r13,8)
add    $0x1,%r13
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
jne    11d0 <getStat+0x40>
lea    0xe13(%rip),%rdi
lea    0xe13(%rip),%rsi
call   1080 <popen@plt>
test   %rax,%rax
je     12d0 <getStat+0x140>
mov    %rax,%rbx
lea    0xe25(%rip),%rdi
call   1030 <puts@plt>
lea    0x1a0(%rsp),%rdi
mov    $0x270f,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12b8 <getStat+0x128>
mov    %r13d,%ebp
lea    0x1a0(%rsp),%r12
lea    0xdc8(%rip),%r15
mov    %rbx,0x8(%rsp)
jmp    126a <getStat+0xda>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x270f,%esi
mov    0x8(%rsp),%rbx
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     12b8 <getStat+0x128>
test   %r13d,%r13d
je     1250 <getStat+0xc0>
xor    %r14d,%r14d
jmp    1289 <getStat+0xf9>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r14
cmp    %r14,%rbp
je     1250 <getStat+0xc0>
mov    0x10(%rsp,%r14,8),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     1280 <getStat+0xf0>
mov    %r12,%rdi
call   1070 <replaceNewLine@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1280 <getStat+0xf0>
lea    0xd70(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <pclose@plt>
jmp    12dc <getStat+0x14c>
lea    0xd6b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [7 x i8] c"ps aux\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [23 x i8] c"Failed to run command\0A\00"
@.str.4 = [16 x i8] c"pushTaskStat([\0A\00"
@.str.5 = [36 x i8] c"{'procName':'%s','procPath':'%s'},\0A\00"
@.str.6 = [4 x i8] c"]);\00"
define i32 @getStat(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [10000 x i8]
%6 = alloca [50 x i8*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load i8*, i8** %3
%11 = call i32* @strdup(i8* %10)
%12 = call i8* @strtok(i32* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %9
br label %13
13: ; preds = %16, %1
%14 = load i8*, i8** %9
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i8*, i8** %9
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
store i32 %19, i32* %7
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds [50 x i8*], [50 x i8*]* %6, i64 0, i64 %20
store i8* %17, i8** %21
%22 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %22, i8** %9
br label %13
23: ; preds = %13
%24 = call i32* @popen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %4
%25 = load i32*, i32** %4
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %67
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %62, %29
%32 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%33 = load i32*, i32** %4
%34 = call i32* @fgets(i8* %32, i32 9999, i32* %33)
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %63
36: ; preds = %31
store i32 0, i32* %8
br label %37
37: ; preds = %59, %36
%38 = load i32, i32* %8
%39 = load i32, i32* %7
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %62
41: ; preds = %37
%42 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [50 x i8*], [50 x i8*]* %6, i64 0, i64 %44
%46 = load i8*, i8** %45
%47 = call i64 @strstr(i8* %42, i8* %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %58
49: ; preds = %41
%50 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%51 = call i32 @replaceNewLine(i8* %50)
%52 = load i32, i32* %8
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [50 x i8*], [50 x i8*]* %6, i64 0, i64 %53
%55 = load i8*, i8** %54
%56 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %55, i8* %56)
br label %58
58: ; preds = %49, %41
br label %59
59: ; preds = %58
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %37
62: ; preds = %37
br label %31
63: ; preds = %31
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%65 = load i32*, i32** %4
%66 = call i32 @pclose(i32* %65)
store i32 0, i32* %2
br label %67
67: ; preds = %63, %27
%68 = load i32, i32* %2
ret i32 %68
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [7 x i8] c"ps aux\00"
@.str.2 = [2 x i8] c"r\00"
@.str.5 = [36 x i8] c"{'procName':'%s','procPath':'%s'},\0A\00"
@.str.6 = [4 x i8] c"]);\00"
@str = [15 x i8] c"pushTaskStat([\00"
@str.7 = [22 x i8] c"Failed to run command\00"
define i32 @getStat(i8* nocapture %0) {
%2 = alloca [10000 x i8]
%3 = alloca [50 x i8*]
%4 = getelementptr inbounds [10000 x i8], [10000 x i8]* %2, i64 0, i64 0
%5 = bitcast [50 x i8*]* %3 to i8*
%6 = tail call i32* @strdup(i8* %0)
%7 = tail call i8* @strtok(i32* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %18, label %9
9: ; preds = %1, %9
%10 = phi i64 [ %12, %9 ], [ 0, %1 ]
%11 = phi i8* [ %14, %9 ], [ %7, %1 ]
%12 = add nuw i64 %10, 1
%13 = getelementptr inbounds [50 x i8*], [50 x i8*]* %3, i64 0, i64 %10
store i8* %11, i8** %13
%14 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = trunc i64 %12 to i32
br label %18
18: ; preds = %16, %1
%19 = phi i32 [ 0, %1 ], [ %17, %16 ]
%20 = tail call i32* @popen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
br label %50
24: ; preds = %18
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%26 = call i32* @fgets(i8* %4, i32 9999, i32* %20)
%27 = icmp eq i32* %26, null
br i1 %27, label %47, label %28
28: ; preds = %24
%29 = icmp eq i32 %19, 0
%30 = zext i32 %19 to i64
br label %34
31: ; preds = %44, %34
%32 = call i32* @fgets(i8* %4, i32 9999, i32* %20)
%33 = icmp eq i32* %32, null
br i1 %33, label %47, label %34
34: ; preds = %28, %31
br i1 %29, label %31, label %35
35: ; preds = %34, %44
%36 = phi i64 [ %45, %44 ], [ 0, %34 ]
%37 = getelementptr inbounds [50 x i8*], [50 x i8*]* %3, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = call i64 @strstr(i8* %4, i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %35
%42 = call i32 @replaceNewLine(i8* %4)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %38, i8* %4)
br label %44
44: ; preds = %35, %41
%45 = add nuw nsw i64 %36, 1
%46 = icmp eq i64 %45, %30
br i1 %46, label %31, label %35
47: ; preds = %31, %24
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%49 = call i32 @pclose(i32* %20)
br label %50
50: ; preds = %47, %22
ret i32 0
}