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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unlink(char *);
int findProcess(char *aucString) {
  int bFlag = 0, iCnt, iCnt1, iCnt2;
  char aucBuff[100];
  char aucTemp[100];
  FILE *fp;
  system("ps -ax > /tmp/process.tmp");
  fp = fopen("/tmp/process.tmp", "r");
  if (fp == NULL) {
    printf("Unable to open file\n");
    return -1;
  }
  while (fgets(aucBuff, sizeof(aucBuff), fp) != NULL) {
    if (strstr(aucBuff, aucString) != NULL) {
      if (strstr(aucBuff, "Z") == NULL) {
        bFlag = 1;
        break;
      } else {
        fclose(fp);
        return -1;
      }
    }
  }
  fclose(fp);
  unlink("/tmp/process.tmp");
  if (bFlag) {
    iCnt = 0;
    iCnt2 = 0;
    while (aucBuff[iCnt++] == ' ')
      ;
    for (iCnt1 = iCnt - 1;; iCnt1++) {
      if (aucBuff[iCnt1] != ' ')
        aucTemp[iCnt2++] = aucBuff[iCnt1];
      else {
        aucTemp[iCnt2] = '\0';
        break;
      }
    }
    return (atoi(aucTemp));
  } else
    return -1;
}


x86 assembly (clang, -O0):
<findProcess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe63(%rip),%rdi
call   1050 <system@plt>
lea    0xe60(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x108(%rbp)
cmpq   $0x0,-0x108(%rbp)
jne    11e2 <findProcess+0x62>
lea    0xe4b(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133d <findProcess+0x1bd>
jmp    11e7 <findProcess+0x67>
lea    -0x90(%rbp),%rdi
mov    -0x108(%rbp),%rdx
mov    $0x64,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1269 <findProcess+0xe9>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     1264 <findProcess+0xe4>
lea    -0x90(%rbp),%rdi
lea    0xe00(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    124c <findProcess+0xcc>
movl   $0x1,-0x14(%rbp)
jmp    1269 <findProcess+0xe9>
mov    -0x108(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    133d <findProcess+0x1bd>
jmp    11e7 <findProcess+0x67>
mov    -0x108(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd8d(%rip),%rdi
call   1030 <unlink@plt>
cmpl   $0x0,-0x14(%rbp)
je     1336 <findProcess+0x1b6>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cltq
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    12bc <findProcess+0x13c>
jmp    1299 <findProcess+0x119>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
je     12fe <findProcess+0x17e>
movslq -0x1c(%rbp),%rax
mov    -0x90(%rbp,%rax,1),%cl
mov    -0x20(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
cltq
mov    %cl,-0x100(%rbp,%rax,1)
jmp    130f <findProcess+0x18f>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x100(%rbp,%rax,1)
jmp    1322 <findProcess+0x1a2>
jmp    1314 <findProcess+0x194>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12c5 <findProcess+0x145>
lea    -0x100(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    133d <findProcess+0x1bd>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findProcess>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
mov    %rdi,%r14
lea    0xe5a(%rip),%rdi
call   1060 <system@plt>
lea    0xe57(%rip),%rdi
lea    0xe61(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1248 <findProcess+0xb8>
mov    %rax,%r15
mov    %rsp,%rbx
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1256 <findProcess+0xc6>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     11d0 <findProcess+0x40>
mov    %rsp,%rdi
mov    $0x5a,%esi
call   1070 <strchr@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%eax
test   %rbx,%rbx
jne    126f <findProcess+0xdf>
lea    0xdeb(%rip),%rdi
call   1030 <unlink@plt>
mov    $0xffffffffffffffff,%rcx
nopw   0x0(%rax,%rax,1)
cmpb   $0x20,0x1(%rsp,%rcx,1)
lea    0x1(%rcx),%rcx
je     1230 <findProcess+0xa0>
mov    %ecx,%eax
mov    (%rsp,%rax,1),%al
cmp    $0x20,%al
jne    127c <findProcess+0xec>
xor    %eax,%eax
jmp    12a2 <findProcess+0x112>
lea    0xdcd(%rip),%rdi
call   1040 <puts@plt>
jmp    126a <findProcess+0xda>
mov    %r15,%rdi
call   1050 <fclose@plt>
lea    0xda4(%rip),%rdi
call   1030 <unlink@plt>
mov    $0xffffffff,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %ecx,%ecx
add    %rsp,%rcx
add    $0x1,%rcx
xor    %edx,%edx
nopw   0x0(%rax,%rax,1)
mov    %al,0x70(%rsp,%rdx,1)
movzbl (%rcx,%rdx,1),%eax
add    $0x1,%rdx
cmp    $0x20,%al
jne    1290 <findProcess+0x100>
mov    %edx,%eax
movb   $0x0,0x70(%rsp,%rax,1)
lea    0x70(%rsp),%rdi
call   10a0 <atoi@plt>
jmp    126f <findProcess+0xdf>

LLVM IR (-O0):
@.str = [26 x i8] c"ps -ax > /tmp/process.tmp\00"
@.str.1 = [17 x i8] c"/tmp/process.tmp\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"Unable to open file\0A\00"
@.str.4 = [2 x i8] c"Z\00"
define i32 @findProcess(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x i8]
%9 = alloca [100 x i8]
%10 = alloca i32*
store i8* %0, i8** %3
store i32 0, i32* %4
%11 = call i32 @system(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%12 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 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* %12, i32** %10
%13 = load i32*, i32** %10
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %84
17: ; preds = %1
br label %18
18: ; preds = %36, %17
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%20 = load i32*, i32** %10
%21 = call i32* @fgets(i8* %19, i32 100, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %37
23: ; preds = %18
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i32* @strstr(i8* %24, i8* %25)
%27 = icmp ne i32* %26, null
br i1 %27, label %28, label %36
28: ; preds = %23
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%30 = call i32* @strstr(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 1, i32* %4
br label %37
33: ; preds = %28
%34 = load i32*, i32** %10
%35 = call i32 @fclose(i32* %34)
store i32 -1, i32* %2
br label %84
36: ; preds = %23
br label %18
37: ; preds = %32, %18
%38 = load i32*, i32** %10
%39 = call i32 @fclose(i32* %38)
%40 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%41 = load i32, i32* %4
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %83
43: ; preds = %37
store i32 0, i32* %5
store i32 0, i32* %7
br label %44
44: ; preds = %52, %43
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 32
br i1 %51, label %52, label %53
52: ; preds = %44
br label %44
53: ; preds = %44
%54 = load i32, i32* %5
%55 = sub nsw i32 %54, 1
store i32 %55, i32* %6
br label %56
56: ; preds = %77, %53
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 32
br i1 %62, label %63, label %72
63: ; preds = %56
%64 = load i32, i32* %6
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
%70 = sext i32 %68 to i64
%71 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %70
store i8 %67, i8* %71
br label %76
72: ; preds = %56
%73 = load i32, i32* %7
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 %74
store i8 0, i8* %75
br label %80
76: ; preds = %63
br label %77
77: ; preds = %76
%78 = load i32, i32* %6
%79 = add nsw i32 %78, 1
store i32 %79, i32* %6
br label %56
80: ; preds = %72
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%82 = call i32 @atoi(i8* %81)
store i32 %82, i32* %2
br label %84
83: ; preds = %37
store i32 -1, i32* %2
br label %84
84: ; preds = %83, %80, %33, %15
%85 = load i32, i32* %2
ret i32 %85
}

LLVM IR (-O2):
@.str = [26 x i8] c"ps -ax > /tmp/process.tmp\00"
@.str.1 = [17 x i8] c"/tmp/process.tmp\00"
@.str.2 = [2 x i8] c"r\00"
@str = [20 x i8] c"Unable to open file\00"
define i32 @findProcess(i8* nocapture %0) {
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @system(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %53
11: ; preds = %1, %14
%12 = call i32* @fgets(i8* %4, i32 100, i32* %7)
%13 = icmp eq i32* %12, null
br i1 %13, label %50, label %14
14: ; preds = %11
%15 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %0)
%16 = icmp eq i32* %15, null
br i1 %16, label %11, label %17
17: ; preds = %14
%18 = call i8* @strchr(i8* %4, i32 90)
%19 = icmp eq i8* %18, null
%20 = call i32 @fclose(i32* %7)
br i1 %19, label %21, label %53
21: ; preds = %17
%22 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ 0, %21 ], [ %25, %23 ]
%25 = add nuw i64 %24, 1
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %24
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 32
br i1 %28, label %23, label %29
29: ; preds = %23
%30 = and i64 %24, 4294967295
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 32
br i1 %33, label %46, label %34
34: ; preds = %29, %34
%35 = phi i64 [ %40, %34 ], [ %30, %29 ]
%36 = phi i64 [ %38, %34 ], [ 0, %29 ]
%37 = phi i8 [ %42, %34 ], [ %32, %29 ]
%38 = add nuw i64 %36, 1
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %36
store i8 %37, i8* %39
%40 = add nuw i64 %35, 1
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 32
br i1 %43, label %44, label %34
44: ; preds = %34
%45 = and i64 %38, 4294967295
br label %46
46: ; preds = %44, %29
%47 = phi i64 [ 0, %29 ], [ %45, %44 ]
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %47
store i8 0, i8* %48
%49 = call i32 @atoi(i8* %5)
br label %53
50: ; preds = %11
%51 = call i32 @fclose(i32* %7)
%52 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %17, %50, %46, %9
%54 = phi i32 [ -1, %9 ], [ %49, %46 ], [ -1, %50 ], [ -1, %17 ]
ret i32 %54
}