#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ basename(char *);
int /*<<< orphan*/ debugMsg(char *);
scalar_t__ execCmd(char *);
int /*<<< orphan*/ execl(char *, int /*<<< orphan*/, char *);
scalar_t__ fork();
int /*<<< orphan*/ kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ waitpid(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
void daemonProc(void) {
  debugMsg("daemonProc() ...");
  int count = 0;
  char exe_val[256];
  sprintf(exe_val, "%s --is-active 2> /dev/null; echo $?;", "/usr/bin/linuxBr");
  debugMsg("daemonProc() ... while() ...");
  while (1) {
    debugMsg("daemonProc() ... inside while() ...");
    if (execCmd(exe_val) > 0) {
      debugMsg("daemonProc() ... while() ... is not active ...");
      pid_t pid = fork();
      if (pid == 0) {
        debugMsg("daemonProc() ... execl() ...");
        execl("/usr/bin/linuxBr", basename("/usr/bin/linuxBr"), (char *)0);
        debugMsg("daemonProc() ... execl() ... ok ...");
      } else {
        waitpid(pid, 0, 0);
        kill(pid, SIGKILL);
      }
    } else {
      debugMsg("daemonProc() ... while() ... is active ...");
    }
    if (count < 3) {
      sleep(60);
    } else {
      sleep(30);
    }
    count++;
  }
  debugMsg("daemonProc() ... while() ... ok ...");
}


x86 assembly (clang, -O0):
<daemonProc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    0xe5e(%rip),%rdi
call   1040 <debugMsg@plt>
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe55(%rip),%rsi
lea    0xe74(%rip),%rdx
call   1080 <sprintf@plt>
lea    0xe79(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xe8a(%rip),%rdi
call   1040 <debugMsg@plt>
lea    -0x110(%rbp),%rdi
call   1030 <execCmd@plt>
cmp    $0x0,%rax
jle    1283 <daemonProc+0xf3>
lea    0xe8c(%rip),%rdi
call   1040 <debugMsg@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    1259 <daemonProc+0xc9>
lea    0xe93(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xe06(%rip),%rdi
call   1050 <basename@plt>
mov    %eax,%esi
lea    0xdf8(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <execl@plt>
lea    0xe86(%rip),%rdi
call   1040 <debugMsg@plt>
jmp    127e <daemonProc+0xee>
mov    -0x118(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1070 <waitpid@plt>
mov    -0x118(%rbp),%rdi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
jmp    128f <daemonProc+0xff>
lea    0xe6f(%rip),%rdi
call   1040 <debugMsg@plt>
cmpl   $0x3,-0x4(%rbp)
jge    12a8 <daemonProc+0x118>
mov    $0x3c,%edi
call   10a0 <sleep@plt>
jmp    12b2 <daemonProc+0x122>
mov    $0x1e,%edi
call   10a0 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11d4 <daemonProc+0x44>

x86 assembly (clang, -O2):
<daemonProc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe58(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xe5d(%rip),%rsi
lea    0xe7c(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
call   1080 <sprintf@plt>
lea    0xe7b(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xe8c(%rip),%rbx
lea    0xea9(%rip),%r12
mov    $0x3c,%r13d
xor    %r14d,%r14d
jmp    1212 <daemonProc+0x82>
nopl   0x0(%rax,%rax,1)
lea    0xf02(%rip),%rdi
call   1040 <debugMsg@plt>
cmp    $0x3,%r14d
mov    $0x1e,%edi
cmovb  %r13d,%edi
call   10a0 <sleep@plt>
add    $0x1,%r14d
mov    %rbx,%rdi
call   1040 <debugMsg@plt>
mov    %r15,%rdi
call   1030 <execCmd@plt>
test   %rax,%rax
jle    11f0 <daemonProc+0x60>
mov    %r12,%rdi
call   1040 <debugMsg@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     1260 <daemonProc+0xd0>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <waitpid@plt>
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1060 <kill@plt>
jmp    11fc <daemonProc+0x6c>
nopl   (%rax)
lea    0xe51(%rip),%rdi
call   1040 <debugMsg@plt>
lea    0xdc4(%rip),%rbp
mov    %rbp,%rdi
call   1050 <basename@plt>
mov    %rbp,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1090 <execl@plt>
lea    0xe47(%rip),%rdi
jmp    11f7 <daemonProc+0x67>

LLVM IR (-O0):
@.str = [17 x i8] c"daemonProc() ...\00"
@.str.1 = [38 x i8] c"%s --is-active 2> /dev/null; echo $?;\00"
@.str.2 = [17 x i8] c"/usr/bin/linuxBr\00"
@.str.3 = [29 x i8] c"daemonProc() ... while() ...\00"
@.str.4 = [36 x i8] c"daemonProc() ... inside while() ...\00"
@.str.5 = [47 x i8] c"daemonProc() ... while() ... is not active ...\00"
@.str.6 = [29 x i8] c"daemonProc() ... execl() ...\00"
@.str.7 = [36 x i8] c"daemonProc() ... execl() ... ok ...\00"
@SIGKILL = global i32 0
@.str.8 = [43 x i8] c"daemonProc() ... while() ... is active ...\00"
define void @daemonProc() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i64
%4 = call i32 @debugMsg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @debugMsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %8
8: ; preds = %0, %39
%9 = call i32 @debugMsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = call i64 @execCmd(i8* %10)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %8
%14 = call i32 @debugMsg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%15 = call i64 (...) @fork()
store i64 %15, i64* %3
%16 = load i64, i64* %3
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = call i32 @debugMsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%20 = call i32 @basename(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @execl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %20, i8* null)
%22 = call i32 @debugMsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
br label %29
23: ; preds = %13
%24 = load i64, i64* %3
%25 = call i32 @waitpid(i64 %24, i32 0, i32 0)
%26 = load i64, i64* %3
%27 = load i32, i32* @SIGKILL
%28 = call i32 @kill(i64 %26, i32 %27)
br label %29
29: ; preds = %23, %18
br label %32
30: ; preds = %8
%31 = call i32 @debugMsg(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
br label %32
32: ; preds = %30, %29
%33 = load i32, i32* %1
%34 = icmp slt i32 %33, 3
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @sleep(i32 60)
br label %39
37: ; preds = %32
%38 = call i32 @sleep(i32 30)
br label %39
39: ; preds = %37, %35
%40 = load i32, i32* %1
%41 = add nsw i32 %40, 1
store i32 %41, i32* %1
br label %8
}

LLVM IR (-O2):
@.str = [17 x i8] c"daemonProc() ...\00"
@.str.1 = [38 x i8] c"%s --is-active 2> /dev/null; echo $?;\00"
@.str.2 = [17 x i8] c"/usr/bin/linuxBr\00"
@.str.3 = [29 x i8] c"daemonProc() ... while() ...\00"
@.str.4 = [36 x i8] c"daemonProc() ... inside while() ...\00"
@.str.5 = [47 x i8] c"daemonProc() ... while() ... is not active ...\00"
@.str.6 = [29 x i8] c"daemonProc() ... execl() ...\00"
@.str.7 = [36 x i8] c"daemonProc() ... execl() ... ok ...\00"
@SIGKILL = global i32 0
@.str.8 = [43 x i8] c"daemonProc() ... while() ... is active ...\00"
define void @daemonProc() {
%1 = alloca [256 x i8]
%2 = tail call i32 @debugMsg(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @debugMsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %6
6: ; preds = %26, %0
%7 = phi i32 [ 0, %0 ], [ %30, %26 ]
%8 = call i32 @debugMsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0))
%9 = call i64 @execCmd(i8* %3)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %6
%12 = call i32 @debugMsg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%13 = call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = call i32 @debugMsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%17 = call i32 @basename(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @execl(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %17, i8* null)
%19 = call i32 @debugMsg(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
br label %26
20: ; preds = %11
%21 = call i32 @waitpid(i64 %13, i32 0, i32 0)
%22 = load i32, i32* @SIGKILL
%23 = call i32 @kill(i64 %13, i32 %22)
br label %26
24: ; preds = %6
%25 = call i32 @debugMsg(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0))
br label %26
26: ; preds = %15, %20, %24
%27 = icmp ult i32 %7, 3
%28 = select i1 %27, i32 60, i32 30
%29 = call i32 @sleep(i32 %28)
%30 = add nuw nsw i32 %7, 1
br label %6
}