#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 /*<<< orphan*/ fgets(char *, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int const);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
char *strtok(char *, char *);
int exist_previous() {
  const int BUF = 120;
  char buff[BUF + 1];
  memset(buff, 0, BUF + 1);
  char splchr[] = " ";
  char *tok;
  int pid_cnt = 0;
  FILE *pipe = popen("pidof oyainput", "r");
  if (pipe == NULL) {
    return 0;
  }
  fgets(buff, BUF, pipe);
  tok = strtok(buff, splchr);
  while (tok != NULL) {
    pid_cnt++;
    tok = strtok(NULL, splchr);
  }
  pclose(pipe);
  return (pid_cnt >= 2);
}


x86 assembly (clang, -O0):
<exist_previous>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x78,-0x8(%rbp)
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x79,%edx
call   1040 <memset@plt>
mov    0xe7d(%rip),%ax
mov    %ax,-0x12(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe6d(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c3 <exist_previous+0x73>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1235 <exist_previous+0xe5>
mov    -0x30(%rbp),%rdx
lea    -0xb0(%rbp),%rdi
mov    $0x78,%esi
call   1050 <fgets@plt>
lea    -0x12(%rbp),%rsi
lea    -0xb0(%rbp),%rdi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1216 <exist_previous+0xc6>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
lea    -0x12(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    11ec <exist_previous+0x9c>
mov    -0x30(%rbp),%rdi
call   1030 <pclose@plt>
cmpl   $0x2,-0x24(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exist_previous>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
lea    0x10(%rsp),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x79,%edx
call   1040 <memset@plt>
movw   $0x20,0xe(%rsp)
lea    0xe84(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <popen@plt>
test   %rax,%rax
je     11f6 <exist_previous+0xa6>
mov    %rax,%r14
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x78,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
lea    0xe(%rsp),%rsi
mov    %rbp,%rdi
call   1070 <strtok@plt>
test   %rax,%rax
je     11ec <exist_previous+0x9c>
mov    $0x1,%ebx
lea    0xe(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <strtok@plt>
add    $0xffffffff,%ebx
test   %rax,%rax
jne    11d0 <exist_previous+0x80>
xor    %ebp,%ebp
test   %ebx,%ebx
setne  %bpl
jmp    11ee <exist_previous+0x9e>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <pclose@plt>
mov    %ebp,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.exist_previous.splchr = [2 x i8] c" \00"
@.str = [15 x i8] c"pidof oyainput\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @exist_previous() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [2 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 120, i32* %2
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 121
%11 = call i32 @memset(i8* %10, i32 0, i32 121)
%12 = bitcast [2 x i8]* %4 to i8*
store i32 0, i32* %6
%13 = call i32* @popen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %0
store i32 0, i32* %1
store i32 1, i32* %8
br label %36
17: ; preds = %0
%18 = load i32*, i32** %7
%19 = call i32 @fgets(i8* %10, i32 120, i32* %18)
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%21 = call i8* @strtok(i8* %10, i8* %20)
store i8* %21, i8** %5
br label %22
22: ; preds = %25, %17
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%29 = call i8* @strtok(i8* null, i8* %28)
store i8* %29, i8** %5
br label %22
30: ; preds = %22
%31 = load i32*, i32** %7
%32 = call i32 @pclose(i32* %31)
%33 = load i32, i32* %6
%34 = icmp sge i32 %33, 2
%35 = zext i1 %34 to i32
store i32 %35, i32* %1
store i32 1, i32* %8
br label %36
36: ; preds = %30, %16
%37 = load i8*, i8** %3
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [15 x i8] c"pidof oyainput\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @exist_previous() {
%1 = alloca i16
%2 = alloca [121 x i8]
%3 = getelementptr inbounds [121 x i8], [121 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 121)
%5 = bitcast i16* %1 to i8*
store i16 32, i16* %1
%6 = call i32* @popen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %23, label %8
8: ; preds = %0
%9 = call i32 @fgets(i8* %3, i32 120, i32* %6)
%10 = call i8* @strtok(i8* %3, i8* %5)
%11 = icmp eq i8* %10, null
br i1 %11, label %20, label %12
12: ; preds = %8, %12
%13 = phi i32 [ %14, %12 ], [ 0, %8 ]
%14 = add nuw nsw i32 %13, 1
%15 = call i8* @strtok(i8* null, i8* %5)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %12
17: ; preds = %12
%18 = icmp ne i32 %13, 0
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %17, %8
%21 = phi i32 [ 0, %8 ], [ %19, %17 ]
%22 = call i32 @pclose(i32* %6)
br label %23
23: ; preds = %0, %20
%24 = phi i32 [ %21, %20 ], [ 0, %0 ]
ret i32 %24
}