#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 */
int check_mydns_memory();
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sscanf(char *, char *, ...);
int /*<<< orphan*/ sys_log(char *);
int /*<<< orphan*/ system(char *);
main() {
  FILE *stream = NULL;
  char buf[1024] = {0};
  int cnt_apache2 = 0, cnt_mydns = 0;
  int loop = 0;
  float box_uptime;
  printf("**********************************\n");
  printf("sys_daemon : start\n");
  printf("**********************************\n");
  while (1) {
    sleep(180);
    loop++;
    printf("---------check apache2-----------\n");
    stream = NULL;
    if ((stream = popen("ps -ef | grep 'apache2' | grep -v 'grep' | grep -v "
                        "'sh -c' | awk '{print $2}' | wc -l",
                        "r")) == NULL)
      printf("popen failed\n");
    memset(buf, 0, sizeof(buf));
    fread(buf, sizeof(char), sizeof(buf), stream);
    buf[1023] = '\0';
    sscanf(buf, "%d", &cnt_apache2);
    pclose(stream);
    printf("apache2 process : %d\n", cnt_apache2);
    if (cnt_apache2 == 0) {
      printf("apache2 : down, restart again...\n");
      sys_log("apache2 down!");
      system("service apache2 start");
    } else if ((loop % 20) == 0) {
      printf("apache2 : 1hour timeup, restart again\n");
      system("service apache2 restart");
    }
    printf("---------check mydns-----------------\n");
    stream = NULL;
    if ((stream = popen("ps -ef | grep 'mydns' | grep -v 'grep' | grep -v 'sh "
                        "-c' | awk '{print $2}' | wc -l",
                        "r")) == NULL)
      printf("popen failed\n");
    memset(buf, 0, sizeof(buf));
    fread(buf, sizeof(char), sizeof(buf), stream);
    buf[1023] = '\0';
    sscanf(buf, "%d", &cnt_mydns);
    pclose(stream);
    printf("mydns process : %d\n", cnt_mydns);
    sleep(1);
    if (cnt_mydns >= 1) {
      if ((loop % 20) == 0) {
        printf("time up! mydns restart!\n");
        system("killall mydns");
        cnt_mydns = 0;
      } else {
        printf("mydns : ok!\n");
        printf("check mydns memory ....\n");
        if (check_mydns_memory() == 1) {
          printf("mydns memory : alert!!!!!!!\n");
          sys_log("mydns memory alert, restart immediately!\n");
          system("killall mydns");
          cnt_mydns = 0;
        }
      }
    }
    if (cnt_mydns == 0) {
      printf("mydns : down, restart again...\n");
      system("/ailvgo/system/domain/mydns &");
    }
    stream = NULL;
    if ((stream = popen("cat /proc/uptime | grep -v 'grep' | grep -v 'sh -c' | "
                        "awk '{print $1}'",
                        "r")) == NULL)
      printf("popen failed\n");
    memset(buf, 0, sizeof(buf));
    fread(buf, sizeof(char), sizeof(buf), stream);
    buf[1023] = '\0';
    sscanf(buf, "%f", &box_uptime);
    pclose(stream);
    printf("box_uptime : %.2f\n", box_uptime);
    if (box_uptime > 3600 * 24) {
      printf("system run more than 24 hours, reboot after 10 seconds!!!\n");
      sys_log("system run too long reboot!");
      sleep(10);
      system("reboot");
    }
  }
  printf("------------sys_daemon : over------------\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
movl   $0x0,-0x414(%rbp)
movl   $0x0,-0x418(%rbp)
movl   $0x0,-0x41c(%rbp)
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xb4,%edi
call   10c0 <sleep@plt>
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x10(%rbp)
lea    0xe14(%rip),%rdi
lea    0xe63(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1273 <main+0xd3>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xe13(%rip),%rsi
lea    -0x414(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x414(%rbp),%esi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x414(%rbp)
jne    1315 <main+0x175>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe01(%rip),%rdi
call   10b0 <sys_log@plt>
lea    0xe03(%rip),%rdi
call   1040 <system@plt>
jmp    134b <main+0x1ab>
mov    -0x41c(%rbp),%eax
mov    $0x14,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1346 <main+0x1a6>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe0a(%rip),%rdi
call   1040 <system@plt>
jmp    134b <main+0x1ab>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x10(%rbp)
lea    0xe22(%rip),%rdi
lea    0xd46(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1390 <main+0x1f0>
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xcf6(%rip),%rsi
lea    -0x418(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x418(%rbp),%esi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
cmpl   $0x1,-0x418(%rbp)
jl     14b7 <main+0x317>
mov    -0x41c(%rbp),%eax
mov    $0x14,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1451 <main+0x2b1>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdce(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x418(%rbp)
jmp    14b2 <main+0x312>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <check_mydns_memory@plt>
cmp    $0x1,%eax
jne    14ad <main+0x30d>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdca(%rip),%rdi
call   10b0 <sys_log@plt>
lea    0xd6d(%rip),%rdi
call   1040 <system@plt>
movl   $0x0,-0x418(%rbp)
jmp    14b2 <main+0x312>
jmp    14b7 <main+0x317>
cmpl   $0x0,-0x418(%rbp)
jne    14de <main+0x33e>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdcd(%rip),%rdi
call   1040 <system@plt>
movq   $0x0,-0x10(%rbp)
lea    0xdd7(%rip),%rdi
lea    0xbc1(%rip),%rsi
call   10a0 <popen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1515 <main+0x375>
lea    0xba9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x410(%rbp),%rdi
lea    0xdb7(%rip),%rsi
lea    -0x420(%rbp),%rdx
mov    $0x0,%al
call   1090 <sscanf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <pclose@plt>
movss  -0x420(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
lea    0xd90(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movss  -0x420(%rbp),%xmm0
ff
movss  0xa6b(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    15ce <main+0x42e>
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xda9(%rip),%rdi
call   10b0 <sys_log@plt>
mov    $0xa,%edi
call   10c0 <sleep@plt>
lea    0xdaf(%rip),%rdi
call   1040 <system@plt>
jmp    1215 <main+0x75>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0x10(%rsp),%r13
mov    $0x400,%edx
mov    %r13,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0x1017(%rip),%rbp
mov    %rbp,%rdi
call   1030 <puts@plt>
lea    0xff5(%rip),%rdi
call   1030 <puts@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r12d
mov    $0x1,%ebx
lea    0xe41(%rip),%r14
jmp    1227 <main+0x77>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%r12d
add    $0x1,%ebx
mov    $0xb4,%edi
call   10d0 <sleep@plt>
lea    0xfed(%rip),%rdi
call   1030 <puts@plt>
lea    0xdc0(%rip),%rdi
mov    %r14,%rbp
mov    %r14,%rsi
call   10b0 <popen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1263 <main+0xb3>
lea    0x1107(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,0xc(%rsp)
mov    %ebx,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x24,%rax
lea    (%rax,%rax,4),%eax
mov    %r12,%r15
mov    %r12,%rbx
lea    (%r12,%rax,4),%r12d
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
movb   $0x0,0x40f(%rsp)
mov    %r13,%rdi
lea    0xda3(%rip),%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
mov    %r14,%rdi
call   1070 <pclose@plt>
mov    0x4(%rsp),%esi
lea    0xd87(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmpl   $0x0,0x4(%rsp)
je     1310 <main+0x160>
test   %r12d,%r12d
mov    %rbp,%r14
jne    1337 <main+0x187>
lea    0x1029(%rip),%rdi
call   1030 <puts@plt>
lea    0xd98(%rip),%rdi
jmp    1332 <main+0x182>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0x102d(%rip),%rdi
call   1030 <puts@plt>
lea    0xd52(%rip),%rdi
call   10c0 <sys_log@plt>
lea    0xd54(%rip),%rdi
mov    %rbp,%r14
call   1050 <system@plt>
lea    0xf09(%rip),%rdi
call   1030 <puts@plt>
lea    0xd67(%rip),%rdi
mov    %r14,%rsi
call   10b0 <popen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1366 <main+0x1b6>
lea    0x1004(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
movb   $0x0,0x40f(%rsp)
mov    %r13,%rdi
lea    0xcc0(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
mov    %rbp,%rdi
call   1070 <pclose@plt>
mov    (%rsp),%esi
lea    0xd4d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
mov    (%rsp),%eax
test   %eax,%eax
jle    1447 <main+0x297>
test   %r12d,%r12d
je     1420 <main+0x270>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <check_mydns_memory@plt>
cmp    $0x1,%eax
jne    1444 <main+0x294>
lea    0xeea(%rip),%rdi
call   1030 <puts@plt>
lea    0xd1b(%rip),%rdi
call   10c0 <sys_log@plt>
jmp    142c <main+0x27c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
lea    0xce6(%rip),%rdi
call   1050 <system@plt>
movl   $0x0,(%rsp)
mov    %r15,%r12
jmp    144e <main+0x29e>
mov    (%rsp),%eax
test   %eax,%eax
mov    %r15,%r12
jne    1466 <main+0x2b6>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
lea    0xcf0(%rip),%rdi
call   1050 <system@plt>
lea    0xd02(%rip),%rdi
mov    %r14,%rsi
call   10b0 <popen@plt>
mov    %rax,%rbp
test   %rax,%rax
mov    0xc(%rsp),%ebx
jne    148d <main+0x2dd>
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
movb   $0x0,0x40f(%rsp)
mov    %r13,%rdi
lea    0xcf3(%rip),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
mov    %rbp,%rdi
call   1070 <pclose@plt>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xcd1(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movss  0x8(%rsp),%xmm0
ucomiss 0xb04(%rip),%xmm0
jbe    1220 <main+0x70>
lea    0xd64(%rip),%rdi
call   1030 <puts@plt>
lea    0xcb7(%rip),%rdi
call   10c0 <sys_log@plt>
mov    $0xa,%edi
call   10d0 <sleep@plt>
lea    0xcbd(%rip),%rdi
call   1050 <system@plt>
jmp    1220 <main+0x70>

LLVM IR (-O0):
@.str = [36 x i8] c"**********************************\0A\00"
@.str.1 = [20 x i8] c"sys_daemon : start\0A\00"
@.str.2 = [35 x i8] c"---------check apache2-----------\0A\00"
@.str.3 = [86 x i8] c"ps -ef | grep 'apache2' | grep -v 'grep' | grep -v 'sh -c' | awk '{print $2}' | wc -l\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [14 x i8] c"popen failed\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [22 x i8] c"apache2 process : %d\0A\00"
@.str.8 = [34 x i8] c"apache2 : down, restart again...\0A\00"
@.str.9 = [14 x i8] c"apache2 down!\00"
@.str.10 = [22 x i8] c"service apache2 start\00"
@.str.11 = [39 x i8] c"apache2 : 1hour timeup, restart again\0A\00"
@.str.12 = [24 x i8] c"service apache2 restart\00"
@.str.13 = [39 x i8] c"---------check mydns-----------------\0A\00"
@.str.14 = [84 x i8] c"ps -ef | grep 'mydns' | grep -v 'grep' | grep -v 'sh -c' | awk '{print $2}' | wc -l\00"
@.str.15 = [20 x i8] c"mydns process : %d\0A\00"
@.str.16 = [25 x i8] c"time up! mydns restart!\0A\00"
@.str.17 = [14 x i8] c"killall mydns\00"
@.str.18 = [13 x i8] c"mydns : ok!\0A\00"
@.str.19 = [25 x i8] c"check mydns memory ....\0A\00"
@.str.20 = [29 x i8] c"mydns memory : alert!!!!!!!\0A\00"
@.str.21 = [42 x i8] c"mydns memory alert, restart immediately!\0A\00"
@.str.22 = [32 x i8] c"mydns : down, restart again...\0A\00"
@.str.23 = [30 x i8] c"/ailvgo/system/domain/mydns &\00"
@.str.24 = [71 x i8] c"cat /proc/uptime | grep -v 'grep' | grep -v 'sh -c' | awk '{print $1}'\00"
@.str.25 = [3 x i8] c"%f\00"
@.str.26 = [19 x i8] c"box_uptime : %.2f\0A\00"
@.str.27 = [59 x i8] c"system run more than 24 hours, reboot after 10 seconds!!!\0A\00"
@.str.28 = [28 x i8] c"system run too long reboot!\00"
@.str.29 = [7 x i8] c"reboot\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
store i32 0, i32* %1
store i32* null, i32** %2
%8 = bitcast [1024 x i8]* %3 to i8*
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %0, %120
%13 = call i32 @sleep(i32 180)
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
store i32 %15, i32* %6
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32* null, i32** %2
%17 = call i32* @popen(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %17, i32** %2
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %21
21: ; preds = %19, %12
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 1024)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%25 = load i32*, i32** %2
%26 = call i32 @fread(i8* %24, i32 1, i32 1024, i32* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %27
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%29 = call i32 (i8*, i8*, ...) @sscanf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %4)
%30 = load i32*, i32** %2
%31 = call i32 @pclose(i32* %30)
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %4
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %21
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0))
%38 = call i32 @sys_log(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%39 = call i32 @system(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0))
br label %48
40: ; preds = %21
%41 = load i32, i32* %6
%42 = srem i32 %41, 20
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.11, i64 0, i64 0))
%46 = call i32 @system(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0))
br label %47
47: ; preds = %44, %40
br label %48
48: ; preds = %47, %36
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0))
store i32* null, i32** %2
%50 = call i32* @popen(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %50, i32** %2
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%56 = call i32 @memset(i8* %55, i32 0, i32 1024)
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%58 = load i32*, i32** %2
%59 = call i32 @fread(i8* %57, i32 1, i32 1024, i32* %58)
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %60
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%62 = call i32 (i8*, i8*, ...) @sscanf(i8* %61, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%63 = load i32*, i32** %2
%64 = call i32 @pclose(i32* %63)
%65 = load i32, i32* %5
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i32 %65)
%67 = call i32 @sleep(i32 1)
%68 = load i32, i32* %5
%69 = icmp sge i32 %68, 1
br i1 %69, label %70, label %88
70: ; preds = %54
%71 = load i32, i32* %6
%72 = srem i32 %71, 20
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %70
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.16, i64 0, i64 0))
%76 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i64 0, i64 0))
store i32 0, i32* %5
br label %87
77: ; preds = %70
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.18, i64 0, i64 0))
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.19, i64 0, i64 0))
%80 = call i32 (...) @check_mydns_memory()
%81 = icmp eq i32 %80, 1
br i1 %81, label %82, label %86
82: ; preds = %77
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.20, i64 0, i64 0))
%84 = call i32 @sys_log(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.21, i64 0, i64 0))
%85 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i64 0, i64 0))
store i32 0, i32* %5
br label %86
86: ; preds = %82, %77
br label %87
87: ; preds = %86, %74
br label %88
88: ; preds = %87, %54
%89 = load i32, i32* %5
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.22, i64 0, i64 0))
%93 = call i32 @system(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.23, i64 0, i64 0))
br label %94
94: ; preds = %91, %88
store i32* null, i32** %2
%95 = call i32* @popen(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.24, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %95, i32** %2
%96 = icmp eq i32* %95, null
br i1 %96, label %97, label %99
97: ; preds = %94
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %99
99: ; preds = %97, %94
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%101 = call i32 @memset(i8* %100, i32 0, i32 1024)
%102 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%103 = load i32*, i32** %2
%104 = call i32 @fread(i8* %102, i32 1, i32 1024, i32* %103)
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 1023
store i8 0, i8* %105
%106 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%107 = call i32 (i8*, i8*, ...) @sscanf(i8* %106, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), float* %7)
%108 = load i32*, i32** %2
%109 = call i32 @pclose(i32* %108)
%110 = load float, float* %7
%111 = fpext float %110 to double
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.26, i64 0, i64 0), double %111)
%113 = load float, float* %7
%114 = fcmp ogt float %113, 8.640000e+04
br i1 %114, label %115, label %120
115: ; preds = %99
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.27, i64 0, i64 0))
%117 = call i32 @sys_log(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.28, i64 0, i64 0))
%118 = call i32 @sleep(i32 10)
%119 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.29, i64 0, i64 0))
br label %120
120: ; preds = %115, %99
br label %12
}

LLVM IR (-O2):
@.str.3 = [86 x i8] c"ps -ef | grep 'apache2' | grep -v 'grep' | grep -v 'sh -c' | awk '{print $2}' | wc -l\00"
@.str.4 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [22 x i8] c"apache2 process : %d\0A\00"
@.str.9 = [14 x i8] c"apache2 down!\00"
@.str.10 = [22 x i8] c"service apache2 start\00"
@.str.12 = [24 x i8] c"service apache2 restart\00"
@.str.14 = [84 x i8] c"ps -ef | grep 'mydns' | grep -v 'grep' | grep -v 'sh -c' | awk '{print $2}' | wc -l\00"
@.str.15 = [20 x i8] c"mydns process : %d\0A\00"
@.str.17 = [14 x i8] c"killall mydns\00"
@.str.21 = [42 x i8] c"mydns memory alert, restart immediately!\0A\00"
@.str.23 = [30 x i8] c"/ailvgo/system/domain/mydns &\00"
@.str.24 = [71 x i8] c"cat /proc/uptime | grep -v 'grep' | grep -v 'sh -c' | awk '{print $1}'\00"
@.str.25 = [3 x i8] c"%f\00"
@.str.26 = [19 x i8] c"box_uptime : %.2f\0A\00"
@.str.28 = [28 x i8] c"system run too long reboot!\00"
@.str.29 = [7 x i8] c"reboot\00"
@str.30 = [19 x i8] c"sys_daemon : start\00"
@str.31 = [35 x i8] c"**********************************\00"
@str.32 = [34 x i8] c"---------check apache2-----------\00"
@str.33 = [38 x i8] c"---------check mydns-----------------\00"
@str.34 = [58 x i8] c"system run more than 24 hours, reboot after 10 seconds!!!\00"
@str.36 = [31 x i8] c"mydns : down, restart again...\00"
@str.37 = [12 x i8] c"mydns : ok!\00"
@str.38 = [24 x i8] c"check mydns memory ....\00"
@str.39 = [28 x i8] c"mydns memory : alert!!!!!!!\00"
@str.40 = [24 x i8] c"time up! mydns restart!\00"
@str.42 = [38 x i8] c"apache2 : 1hour timeup, restart again\00"
@str.43 = [33 x i8] c"apache2 : down, restart again...\00"
@str.44 = [13 x i8] c"popen failed\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca float
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = bitcast float* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.31, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.30, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.31, i64 0, i64 0))
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 1023
br label %13
13: ; preds = %101, %0
%14 = phi i32 [ 0, %0 ], [ %16, %101 ]
%15 = call i32 @sleep(i32 180)
%16 = add nuw nsw i32 %14, 1
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.32, i64 0, i64 0))
%18 = call i32* @popen(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.44, i64 0, i64 0))
br label %22
22: ; preds = %20, %13
%23 = call i32 @memset(i8* %5, i32 0, i32 1024)
%24 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %18)
store i8 0, i8* %12
%25 = call i32 (i8*, i8*, ...) @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %2)
%26 = call i32 @pclose(i32* %18)
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.43, i64 0, i64 0))
%33 = call i32 @sys_log(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
br label %39
34: ; preds = %22
%35 = urem i32 %16, 20
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.42, i64 0, i64 0))
br label %39
39: ; preds = %31, %37
%40 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), %37 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), %31 ]
%41 = call i32 @system(i8* %40)
br label %42
42: ; preds = %39, %34
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.33, i64 0, i64 0))
%44 = call i32* @popen(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.44, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = call i32 @memset(i8* %5, i32 0, i32 1024)
%50 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %44)
store i8 0, i8* %12
%51 = call i32 (i8*, i8*, ...) @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%52 = call i32 @pclose(i32* %44)
%53 = load i32, i32* %3
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.15, i64 0, i64 0), i32 %53)
%55 = call i32 @sleep(i32 1)
%56 = load i32, i32* %3
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %75
58: ; preds = %48
%59 = urem i32 %16, 20
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.40, i64 0, i64 0))
%63 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i64 0, i64 0))
store i32 0, i32* %3
br label %78
64: ; preds = %58
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.37, i64 0, i64 0))
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.38, i64 0, i64 0))
%67 = call i32 (...) @check_mydns_memory()
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %73
69: ; preds = %64
%70 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.39, i64 0, i64 0))
%71 = call i32 @sys_log(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.21, i64 0, i64 0))
%72 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.17, i64 0, i64 0))
store i32 0, i32* %3
br label %78
73: ; preds = %64
%74 = load i32, i32* %3
br label %75
75: ; preds = %73, %48
%76 = phi i32 [ %74, %73 ], [ %56, %48 ]
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %69, %61, %75
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.36, i64 0, i64 0))
%80 = call i32 @system(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.23, i64 0, i64 0))
br label %81
81: ; preds = %78, %75
%82 = call i32* @popen(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.24, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%83 = icmp eq i32* %82, null
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.44, i64 0, i64 0))
br label %86
86: ; preds = %84, %81
%87 = call i32 @memset(i8* %5, i32 0, i32 1024)
%88 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %82)
store i8 0, i8* %12
%89 = call i32 (i8*, i8*, ...) @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), float* %4)
%90 = call i32 @pclose(i32* %82)
%91 = load float, float* %4
%92 = fpext float %91 to double
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.26, i64 0, i64 0), double %92)
%94 = load float, float* %4
%95 = fcmp ogt float %94, 8.640000e+04
br i1 %95, label %96, label %101
96: ; preds = %86
%97 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.34, i64 0, i64 0))
%98 = call i32 @sys_log(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.28, i64 0, i64 0))
%99 = call i32 @sleep(i32 10)
%100 = call i32 @system(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.29, i64 0, i64 0))
br label %101
101: ; preds = %96, %86
br label %13
}