#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*/ daemonProc();
int /*<<< orphan*/ debugMsg(char *);
int /*<<< orphan*/ execCmd(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, char *, int);
int fire(void) {
  debugMsg("fire() ...");
  pid_t pid = fork();
  if (pid == 0) {
    int pid_chi = getpid();
    char exec_val[256];
    sprintf(exec_val, "%s --save-pid par %d 2> /dev/null; echo $?;",
            "/usr/bin/linuxBr", pid_chi);
    execCmd(exec_val);
    debugMsg("fire() ... go to daemonProc() ...");
    daemonProc();
    debugMsg("fire() ... go to daemonProc() ... ok ...");
    exit(0);
  } else if (pid > 0) {
    exit(0);
  } else {
    exit(1);
  }
  debugMsg("fire() ... ok ...");
  return 0;
}


x86 assembly (clang, -O0):
<fire>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xe7e(%rip),%rdi
call   1060 <debugMsg@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11f6 <fire+0x86>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0xc(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0xc(%rbp),%ecx
lea    0xe53(%rip),%rsi
lea    0xe78(%rip),%rdx
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <execCmd@plt>
lea    0xe71(%rip),%rdi
call   1060 <debugMsg@plt>
mov    $0x0,%al
call   1050 <daemonProc@plt>
lea    0xe80(%rip),%rdi
call   1060 <debugMsg@plt>
xor    %edi,%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
jle    1208 <fire+0x98>
xor    %edi,%edi
call   1080 <exit@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<fire>:
push   %rbx
sub    $0x100,%rsp
lea    0xe81(%rip),%rdi
call   1060 <debugMsg@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jne    11db <fire+0x6b>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe6d(%rip),%rsi
lea    0xe92(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%ecx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <execCmd@plt>
lea    0xe87(%rip),%rdi
call   1060 <debugMsg@plt>
xor    %eax,%eax
call   1050 <daemonProc@plt>
lea    0xe96(%rip),%rdi
call   1060 <debugMsg@plt>
jmp    11dd <fire+0x6d>
jle    11e4 <fire+0x74>
xor    %edi,%edi
call   1080 <exit@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"fire() ...\00"
@.str.1 = [44 x i8] c"%s --save-pid par %d 2> /dev/null; echo $?;\00"
@.str.2 = [17 x i8] c"/usr/bin/linuxBr\00"
@.str.3 = [34 x i8] c"fire() ... go to daemonProc() ...\00"
@.str.4 = [41 x i8] c"fire() ... go to daemonProc() ... ok ...\00"
define i32 @fire() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = call i32 @debugMsg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = call i64 (...) @fork()
store i64 %5, i64* %1
%6 = load i64, i64* %1
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %19
8: ; preds = %0
%9 = call i32 (...) @getpid()
store i32 %9, i32* %2
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = load i32, i32* %2
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = call i32 @execCmd(i8* %13)
%15 = call i32 @debugMsg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (...) @daemonProc()
%17 = call i32 @debugMsg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %0
%20 = load i64, i64* %1
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %19
%25 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"fire() ...\00"
@.str.1 = [44 x i8] c"%s --save-pid par %d 2> /dev/null; echo $?;\00"
@.str.2 = [17 x i8] c"/usr/bin/linuxBr\00"
@.str.3 = [34 x i8] c"fire() ... go to daemonProc() ...\00"
@.str.4 = [41 x i8] c"fire() ... go to daemonProc() ... ok ...\00"
define i32 @fire() {
%1 = alloca [256 x i8]
%2 = tail call i32 @debugMsg(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = tail call i32 (...) @getpid()
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%9 = call i32 @execCmd(i8* %7)
%10 = call i32 @debugMsg(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (...) @daemonProc()
%12 = call i32 @debugMsg(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %0
%15 = icmp sgt i64 %3, 0
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %14
%19 = tail call i32 @exit(i32 1)
unreachable
}