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

/* Variables and functions */
unsigned int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ isspace(char);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int strlen(char *);
int check_spawnvpn_process(void) {
  FILE *stream = NULL;
  char buf[32];
  int len = 0;
  int enternum = 0;
  unsigned int freadret;
  memset(buf, '\0', sizeof(buf));
  stream = popen("pgrep spawncp", "r");
  freadret = fread(buf, sizeof(char), sizeof(buf), stream);
  pclose(stream);
  len = strlen(buf);
  if (len != 0) {
    int i = 0;
    for (i = 0; i < len; i++) {
      if (isspace(buf[i])) {
        enternum += 1;
      }
    }
    if (enternum >= 2) {
      return 1;
    } else {
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<check_spawnvpn_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
lea    0xe6b(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x20,%edx
call   1030 <fread@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <pclose@plt>
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1249 <check_spawnvpn_process+0xe9>
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    122c <check_spawnvpn_process+0xcc>
movslq -0x40(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%edi
call   1070 <isspace@plt>
cmp    $0x0,%rax
je     1219 <check_spawnvpn_process+0xb9>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    121e <check_spawnvpn_process+0xbe>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11ec <check_spawnvpn_process+0x8c>
cmpl   $0x2,-0x38(%rbp)
jl     1242 <check_spawnvpn_process+0xe2>
movl   $0x1,-0x4(%rbp)
jmp    1249 <check_spawnvpn_process+0xe9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_spawnvpn_process>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsp,%r14
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
lea    0xe7d(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x20,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1050 <pclose@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     11f4 <check_spawnvpn_process+0x94>
jle    11f4 <check_spawnvpn_process+0x94>
mov    %eax,%r14d
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rsp,%rbp,1),%edi
call   1070 <isspace@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%ebx
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11d0 <check_spawnvpn_process+0x70>
xor    %ebp,%ebp
cmp    $0x2,%ebx
setae  %bpl
jmp    11f4 <check_spawnvpn_process+0x94>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"pgrep spawncp\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @check_spawnvpn_process() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* null, i32** %2
store i32 0, i32* %4
store i32 0, i32* %5
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i8 signext 0, i32 32)
%10 = call i32* @popen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %2
%13 = call i32 @fread(i8* %11, i32 1, i32 32, i32* %12)
store i32 %13, i32* %6
%14 = load i32*, i32** %2
%15 = call i32 @pclose(i32* %14)
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %44
20: ; preds = %0
store i32 0, i32* %7
store i32 0, i32* %7
br label %21
21: ; preds = %36, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %4
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i64 @isspace(i8 signext %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %35
35: ; preds = %32, %25
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %21
39: ; preds = %21
%40 = load i32, i32* %5
%41 = icmp sge i32 %40, 2
br i1 %41, label %42, label %43
42: ; preds = %39
store i32 1, i32* %1
br label %44
43: ; preds = %39
store i32 0, i32* %1
br label %44
44: ; preds = %42, %43, %0
%45 = load i32, i32* %1
ret i32 %45
}

LLVM IR (-O2):
@.str = [14 x i8] c"pgrep spawncp\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @check_spawnvpn_process() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i8 signext 0, i32 32)
%4 = call i32* @popen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @fread(i8* %2, i32 1, i32 32, i32* %4)
%6 = call i32 @pclose(i32* %4)
%7 = call i32 @strlen(i8* %2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %27, label %9
9: ; preds = %0
%10 = icmp sgt i32 %7, 0
br i1 %10, label %11, label %27
11: ; preds = %9
%12 = zext i32 %7 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %22, %13 ]
%15 = phi i32 [ 0, %11 ], [ %21, %13 ]
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 %14
%17 = load i8, i8* %16
%18 = call i64 @isspace(i8 signext %17)
%19 = icmp ne i64 %18, 0
%20 = zext i1 %19 to i32
%21 = add nuw nsw i32 %15, %20
%22 = add nuw nsw i64 %14, 1
%23 = icmp eq i64 %22, %12
br i1 %23, label %24, label %13
24: ; preds = %13
%25 = icmp ugt i32 %21, 1
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %9, %24, %0
%28 = phi i32 [ undef, %0 ], [ 0, %9 ], [ %26, %24 ]
ret i32 %28
}