#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*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int detect_process(char *process_name) {
  FILE *ptr;
  char buff[512] = {0};
  char ps[128] = {0};
  sprintf(ps, "ps | grep -c %s", process_name);
  strcpy(buff, "ABNORMAL");
  if ((ptr = popen(ps, "r")) != NULL) {
    while (fgets(buff, 512, ptr) != NULL) {
      if (atoi(buff) > 2) {
        pclose(ptr);
        return 1;
      }
    }
  }
  if (strcmp(buff, "ABNORMAL") == 0) {
    return 0;
  }
  pclose(ptr);
  return 0;
}


x86 assembly (clang, -O0):
<detect_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1050 <memset@plt>
lea    -0x2a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0x2a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x220(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x2a0(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1258 <detect_process+0xd8>
jmp    1205 <detect_process+0x85>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1253 <detect_process+0xd3>
lea    -0x220(%rbp),%rdi
call   1090 <atoi@plt>
cmp    $0x2,%eax
jle    124e <detect_process+0xce>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1291 <detect_process+0x111>
jmp    1205 <detect_process+0x85>
jmp    1258 <detect_process+0xd8>
lea    -0x220(%rbp),%rdi
lea    0xdaa(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1281 <detect_process+0x101>
movl   $0x0,-0x4(%rbp)
jmp    1291 <detect_process+0x111>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_process>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x288,%rsp
mov    %rdi,%rbx
lea    0x80(%rsp),%r15
xor    %r14d,%r14d
mov    $0x200,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe25(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rdx
call   10a0 <sprintf@plt>
lea    0xe20(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
lea    0xe1a(%rip),%rsi
mov    %rbp,%rdi
call   1080 <popen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1252 <detect_process+0xd2>
lea    0x80(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1252 <detect_process+0xd2>
mov    %rbp,%rdi
call   1090 <atoi@plt>
cmp    $0x3,%eax
jl     1220 <detect_process+0xa0>
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    $0x1,%r14d
jmp    1273 <detect_process+0xf3>
lea    0xdb7(%rip),%rsi
lea    0x80(%rsp),%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1273 <detect_process+0xf3>
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %r14d,%eax
add    $0x288,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"ps | grep -c %s\00"
@.str.1 = [9 x i8] c"ABNORMAL\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @detect_process(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [512 x i8]
%6 = alloca [128 x i8]
store i8* %0, i8** %3
%7 = bitcast [512 x i8]* %5 to i8*
%8 = bitcast [128 x i8]* %6 to i8*
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%15 = call i32* @popen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %15, i32** %4
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %32
17: ; preds = %1
br label %18
18: ; preds = %30, %17
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%20 = load i32*, i32** %4
%21 = call i32* @fgets(i8* %19, i32 512, i32* %20)
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%25 = call i32 @atoi(i8* %24)
%26 = icmp sgt i32 %25, 2
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32*, i32** %4
%29 = call i32 @pclose(i32* %28)
store i32 1, i32* %2
br label %40
30: ; preds = %23
br label %18
31: ; preds = %18
br label %32
32: ; preds = %31, %1
%33 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
store i32 0, i32* %2
br label %40
37: ; preds = %32
%38 = load i32*, i32** %4
%39 = call i32 @pclose(i32* %38)
store i32 0, i32* %2
br label %40
40: ; preds = %37, %36, %27
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
@.str = [16 x i8] c"ps | grep -c %s\00"
@.str.1 = [9 x i8] c"ABNORMAL\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @detect_process(i8* %0) {
%2 = alloca [512 x i8]
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %18, label %10
10: ; preds = %1, %13
%11 = call i32* @fgets(i8* %4, i32 512, i32* %8)
%12 = icmp eq i32* %11, null
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = call i32 @atoi(i8* %4)
%15 = icmp sgt i32 %14, 2
br i1 %15, label %16, label %10
16: ; preds = %13
%17 = call i32 @pclose(i32* %8)
br label %23
18: ; preds = %10, %1
%19 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @pclose(i32* %8)
br label %23
23: ; preds = %18, %21, %16
%24 = phi i32 [ 1, %16 ], [ 0, %21 ], [ 0, %18 ]
ret i32 %24
}