#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, char *, char *,
                          char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ system(char *);
void *handler(void *arg) {
  int buf0;
  char buf1[8];
  char buf2[16];
  char buf3[64];
  FILE *fp;
  int p1;
  int p2;
  while (1) {
    p1 = p2 = 0;
    fp = popen("ps -e | grep \"dataserver\\|updserver\"", "r");
    while (!feof(fp)) {
      fscanf(fp, "%d%s%s%s", &buf0, buf1, buf2, buf3);
      if (strcmp(buf3, "dataserver") == 0) {
        p1 = 1;
      } else if (strcmp(buf3, "updserver") == 0) {
        p2 = 1;
      }
    }
    pclose(fp);
    if (p1 == 0) {
      printf("dataserver is off.\nauto start.\n");
      system("./dataserver &");
    } else {
      printf("dataserver is running\n");
    }
    if (p2 == 0) {
      printf("updserver is off.\nauto start.\n");
      system("./updserver &");
    } else {
      printf("updserver is running\n");
    }
    printf("Type 'q' to quit\n\n");
    sleep(5);
  }
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x80(%rbp)
movl   $0x0,-0x7c(%rbp)
lea    0xe5c(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d2 <handler+0x52>
jmp    1243 <handler+0xc3>
mov    -0x78(%rbp),%rdi
lea    -0x14(%rbp),%rcx
lea    -0x30(%rbp),%r8
lea    -0x70(%rbp),%r9
lea    0xe3c(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <fscanf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1218 <handler+0x98>
movl   $0x1,-0x7c(%rbp)
jmp    123e <handler+0xbe>
lea    -0x70(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1239 <handler+0xb9>
movl   $0x1,-0x80(%rbp)
jmp    123e <handler+0xbe>
jmp    11b4 <handler+0x34>
mov    -0x78(%rbp),%rdi
call   1050 <pclose@plt>
cmpl   $0x0,-0x7c(%rbp)
jne    1273 <handler+0xf3>
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
lea    0xdfa(%rip),%rdi
call   1030 <system@plt>
jmp    127f <handler+0xff>
lea    0xdf8(%rip),%rdi
call   1040 <printf@plt>
cmpl   $0x0,-0x80(%rbp)
jne    12a6 <handler+0x126>
lea    0xdf9(%rip),%rdi
call   1040 <printf@plt>
lea    0xe0c(%rip),%rdi
call   1030 <system@plt>
jmp    12b2 <handler+0x132>
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
lea    0xe13(%rip),%rdi
call   1040 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
jmp    118f <handler+0xf>

x86 assembly (clang, -O2):
<handler>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe6b(%rip),%rbx
lea    0x10(%rsp),%rbp
lea    0x20(%rsp),%r14
lea    0xe88(%rip),%r15
jmp    11d2 <handler+0x52>
nopl   0x0(%rax,%rax,1)
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
mov    %rbx,%rdi
lea    0xe5b(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1080 <feof@plt>
test   %eax,%eax
je     1220 <handler+0xa0>
mov    %r12,%rdi
call   1050 <pclose@plt>
xor    %r13d,%r13d
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xe35(%rip),%rdi
call   1040 <system@plt>
test   %r13d,%r13d
jne    11b0 <handler+0x30>
jmp    12b8 <handler+0x138>
nopl   (%rax)
xor    %r13d,%r13d
xor    %ebx,%ebx
jmp    1257 <handler+0xd7>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
lea    0xdff(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
mov    $0x1,%eax
cmove  %eax,%r13d
mov    %r12,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1290 <handler+0x110>
mov    %r12,%rdi
lea    0xdc4(%rip),%rsi
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbp,%r8
mov    %r14,%r9
call   1060 <fscanf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1230 <handler+0xb0>
mov    $0x1,%ebx
jmp    124b <handler+0xcb>
nopl   (%rax)
mov    %r12,%rdi
call   1050 <pclose@plt>
test   %ebx,%ebx
je     12d5 <handler+0x155>
lea    0xdbd(%rip),%rdi
call   1030 <puts@plt>
lea    0xd51(%rip),%rbx
test   %r13d,%r13d
jne    11b0 <handler+0x30>
lea    0xdde(%rip),%rdi
call   1030 <puts@plt>
lea    0xd87(%rip),%rdi
call   1040 <system@plt>
jmp    11bc <handler+0x3c>
lea    0xd24(%rip),%rbx
jmp    11fb <handler+0x7b>

LLVM IR (-O0):
@.str = [37 x i8] c"ps -e | grep \22dataserver\\|updserver\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%d%s%s%s\00"
@.str.3 = [11 x i8] c"dataserver\00"
@.str.4 = [10 x i8] c"updserver\00"
@.str.5 = [32 x i8] c"dataserver is off.\0Aauto start.\0A\00"
@.str.6 = [15 x i8] c"./dataserver &\00"
@.str.7 = [23 x i8] c"dataserver is running\0A\00"
@.str.8 = [31 x i8] c"updserver is off.\0Aauto start.\0A\00"
@.str.9 = [14 x i8] c"./updserver &\00"
@.str.10 = [22 x i8] c"updserver is running\0A\00"
@.str.11 = [19 x i8] c"Type 'q' to quit\0A\0A\00"
define i8* @handler(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [8 x i8]
%5 = alloca [16 x i8]
%6 = alloca [64 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %2
br label %10
10: ; preds = %1, %52
store i32 0, i32* %9
store i32 0, i32* %8
%11 = call i32* @popen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %7
br label %12
12: ; preds = %33, %10
%13 = load i32*, i32** %7
%14 = call i32 @feof(i32* %13)
%15 = icmp ne i32 %14, 0
%16 = xor i1 %15, true
br i1 %16, label %17, label %34
17: ; preds = %12
%18 = load i32*, i32** %7
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%22 = call i32 @fscanf(i32* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %3, i8* %19, i8* %20, i8* %21)
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %17
store i32 1, i32* %8
br label %33
27: ; preds = %17
%28 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i32 1, i32* %9
br label %32
32: ; preds = %31, %27
br label %33
33: ; preds = %32, %26
br label %12
34: ; preds = %12
%35 = load i32*, i32** %7
%36 = call i32 @pclose(i32* %35)
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %44
42: ; preds = %34
%43 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
%45 = load i32, i32* %9
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%49 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %52
50: ; preds = %44
%51 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
br label %52
52: ; preds = %50, %47
%53 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%54 = call i32 @sleep(i32 5)
br label %10
}

LLVM IR (-O2):
@.str = [37 x i8] c"ps -e | grep \22dataserver\\|updserver\22\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%d%s%s%s\00"
@.str.3 = [11 x i8] c"dataserver\00"
@.str.4 = [10 x i8] c"updserver\00"
@.str.6 = [15 x i8] c"./dataserver &\00"
@.str.9 = [14 x i8] c"./updserver &\00"
@str = [22 x i8] c"dataserver is running\00"
@str.12 = [21 x i8] c"updserver is running\00"
@str.13 = [18 x i8] c"Type 'q' to quit\0A\00"
@str.14 = [30 x i8] c"updserver is off.\0Aauto start.\00"
@str.15 = [31 x i8] c"dataserver is off.\0Aauto start.\00"
define noalias i8* @handler(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = alloca [16 x i8]
%5 = alloca [64 x i8]
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
br label %10
10: ; preds = %48, %1
%11 = call i32* @popen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @feof(i32* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @pclose(i32* %11)
br label %34
16: ; preds = %10, %26
%17 = phi i32 [ %28, %26 ], [ 0, %10 ]
%18 = phi i32 [ %27, %26 ], [ 0, %10 ]
%19 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %2, i8* %7, i8* %8, i8* %9)
%20 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %16
%23 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i32 1, i32 %17
br label %26
26: ; preds = %22, %16
%27 = phi i32 [ 1, %16 ], [ %18, %22 ]
%28 = phi i32 [ %17, %16 ], [ %25, %22 ]
%29 = call i32 @feof(i32* %11)
%30 = icmp eq i32 %29, 0
br i1 %30, label %16, label %31
31: ; preds = %26
%32 = call i32 @pclose(i32* %11)
%33 = icmp eq i32 %27, 0
br i1 %33, label %34, label %38
34: ; preds = %14, %31
%35 = phi i32 [ 0, %14 ], [ %28, %31 ]
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.15, i64 0, i64 0))
%37 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %40
38: ; preds = %31
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
%41 = phi i32 [ %28, %38 ], [ %35, %34 ]
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.14, i64 0, i64 0))
%45 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %48
46: ; preds = %40
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.12, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.13, i64 0, i64 0))
%50 = call i32 @sleep(i32 5)
br label %10
}