#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*/ basename(char *);
int /*<<< orphan*/ execl(char *, int /*<<< orphan*/, char *);
scalar_t__ fork();
scalar_t__ isParActive();
int startDaemon(void) {
  int ret_val;
  if (isParActive() > 0) {
    pid_t pid = fork();
    if (pid < 0) {
      ret_val = 0;
    }
    if (pid == 0) {
      execl("/usr/bin/linuxBrWorker", basename("/usr/bin/linuxBrWorker"),
            (char *)0);
    } else {
      ret_val = 0;
    }
  } else {
    ret_val = 1;
  }
  return ret_val;
}


x86 assembly (clang, -O0):
<startDaemon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <isParActive@plt>
cmp    $0x0,%rax
jle    11b0 <startDaemon+0x70>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1176 <startDaemon+0x36>
movl   $0x0,-0x4(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a4 <startDaemon+0x64>
lea    0xe78(%rip),%rdi
call   1030 <basename@plt>
mov    %eax,%esi
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execl@plt>
jmp    11ab <startDaemon+0x6b>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <startDaemon+0x77>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<startDaemon>:
push   %r14
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <isParActive@plt>
test   %rax,%rax
jle    117d <startDaemon+0x3d>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jne    1182 <startDaemon+0x42>
lea    0xe9b(%rip),%r14
mov    %r14,%rdi
call   1030 <basename@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <execl@plt>
jmp    1182 <startDaemon+0x42>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/usr/bin/linuxBrWorker\00"
define i32 @startDaemon() {
%1 = alloca i32
%2 = alloca i64
%3 = call i64 (...) @isParActive()
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %0
%6 = call i64 (...) @fork()
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %5
store i32 0, i32* %1
br label %10
10: ; preds = %9, %5
%11 = load i64, i64* %2
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 @basename(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @execl(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %14, i8* null)
br label %17
16: ; preds = %10
store i32 0, i32* %1
br label %17
17: ; preds = %16, %13
br label %19
18: ; preds = %0
store i32 1, i32* %1
br label %19
19: ; preds = %18, %17
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [23 x i8] c"/usr/bin/linuxBrWorker\00"
define i32 @startDaemon() {
%1 = tail call i64 (...) @isParActive()
%2 = icmp sgt i64 %1, 0
br i1 %2, label %3, label %9
3: ; preds = %0
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @basename(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @execl(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %7, i8* null)
br label %9
9: ; preds = %0, %6, %3
%10 = phi i32 [ 0, %3 ], [ 0, %6 ], [ 1, %0 ]
ret i32 %10
}