// File: /workspace/github_cpp_makefile_star2_O1/gdaws[P]process-monitor/monitor.cpp
// Function: main
int main(int argc, const char ** argv)
{
    std::string program;
    std::vector<std::string> program_arguments;
    int max_restarts = -1;
    
    {
        program_arguments::parser p;
        
        p.add_option(
            'm',
            "max-restarts",
            "N",
            "Limit the number of restarts",
            max_restarts
        );
        
        p.add_argument("PROGRAM-ARGUMENTS", program_arguments);
        
        p.parse(argc, argv);
    }
    
    if(program_arguments.size() == 0)
    {
        std::cerr<<"Not enough program arguments"<<std::endl;
        return 1;
    }
    
    std::string program_filename;
    if(!find_program(program_arguments[0], program_filename))
    {
        std::cout<<program_arguments[0]<<" file not found"<<std::endl;
        return 1;
    }
    
    bool repeat = false;
    int count_restarts = 0;
    
    do
    {
        repeat = false;
        
        create_process(program_filename, program_arguments);
        
        int child_exit_status = 0;
        if(::wait(&child_exit_status) == -1) return 1;
        
        if(WIFSIGNALED(child_exit_status))
        {
            int signal = WTERMSIG(child_exit_status);
            
            switch(signal)
            {
                case SIGILL:
                case SIGABRT:
                case SIGFPE:
                case SIGSEGV:
                case SIGPIPE:
                    repeat = true;
                    break;
                default:;
            }
        }
    }
    while(repeat && (max_restarts == -1 || ++count_restarts <= max_restarts));
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x78(%rsp), %r14
movq %r14, -0x10(%r14)
xorl %eax, %eax
movq %rax, -0x8(%r14)
movb $0x0, (%r14)
movq %rax, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
leaq 0x88(%rsp), %rdi
callq 0x2a80
leaq 0x3a86(%rip), %rdx      # 0x6004
leaq 0x3a8c(%rip), %rcx      # 0x6011
leaq 0x3a87(%rip), %r8       # 0x6013
leaq 0x88(%rsp), %rdi
leaq 0xc(%rsp), %r9
movl $0x6d, %esi
callq 0x306a
leaq 0x3a86(%rip), %rsi      # 0x6030
leaq 0x88(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x31f4
leaq 0x88(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x32ba
leaq 0x88(%rsp), %rdi
callq 0x2b90
movq 0x30(%rsp), %rbx
cmpq %rbx, 0x38(%rsp)
je 0x262e
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq (%rbx), %rdi
leaq 0x88(%rsp), %r14
movq %r14, %rsi
callq 0x21a0
movl 0x18(%r14), %ecx
andl $0x4000, %ecx           # imm = 0x4000
orl %eax, %ecx
jne 0x267e
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0x2100
jmp 0x27c2
movq 0x69bb(%rip), %rbx      # 0x8ff0
leaq 0x3a06(%rip), %rsi      # 0x6042
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x2200
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x6989(%rip), %rdi      # 0x8ff0
callq 0x2040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2110
jmp 0x2958
leaq 0x39ea(%rip), %rdi      # 0x606f
callq 0x2230
movq %rax, %r15
movq %rax, %rdi
callq 0x20e0
movq %rax, %r12
addq %r15, %r12
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %r15, %r13
cmpq %r12, %r15
jae 0x279d
movq %r13, %rdi
movl $0x3a, %esi
callq 0x20c0
movq %rax, %rbp
testq %rax, %rax
cmoveq %r12, %rbp
movl $0xf, %eax
leaq 0x20(%rsp), %rcx
cmpq %rcx, 0x10(%rsp)
je 0x26e8
movq 0x20(%rsp), %rax
movq %rbp, %r15
subq %r13, %r15
movq 0x8(%rbx), %rcx
leaq (%rcx,%r15), %rsi
incq %rsi
cmpq %rsi, %rax
cmovaq %rax, %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x2290
movq 0x18(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rcx
movq %r15, %r8
callq 0x21f0
movq 0x18(%rsp), %rsi
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
movl $0x2f, %r8d
callq 0x2320
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x2090
movq 0x10(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x21a0
movl 0xa0(%rsp), %ecx
andl $0x4000, %ecx           # imm = 0x4000
orl %eax, %ecx
sete %r14b
jne 0x2786
leaq 0x48(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2100
movq %r13, %r15
jmp 0x2794
xorl %r15d, %r15d
cmpb $0x3a, (%rbp)
sete %r15b
addq %rbp, %r15
testb %r14b, %r14b
je 0x26af
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x27b9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
cmpq %r12, %r13
jae 0x28dc
xorl %r15d, %r15d
movq 0x6804(%rip), %r14      # 0x8fd0
leaq 0x88(%rsp), %rbx
callq 0x2070
testl %eax, %eax
jne 0x2852
movq 0x30(%rsp), %r13
movq 0x38(%rsp), %r12
movq %r12, %rbp
subq %r13, %rbp
sarq $0x5, %rbp
leaq 0x2(%rbp), %rax
shrq $0x3d, %rax
leaq 0x10(,%rbp,8), %rcx
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x2030
cmpq %r13, %r12
je 0x283a
cmpq $0x1, %rbp
movq %rbp, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
movq (%r13), %rsi
movq %rsi, (%rax,%rdx,8)
incq %rdx
addq $0x20, %r13
cmpq %rdx, %rcx
jne 0x2826
movq $0x0, (%rax,%rbp,8)
movq 0x48(%rsp), %rdi
movq (%r14), %rdx
movq %rax, %rsi
callq 0x22e0
cmpl $-0x1, %eax
je 0x298d
movl $0x0, 0x88(%rsp)
movq %rbx, %rdi
callq 0x2240
movb $0x1, %cl
cmpl $-0x1, %eax
je 0x28a9
movl 0x88(%rsp), %edx
andl $0x7f, %edx
movl %edx, %esi
shll $0x18, %esi
addl $0x1000000, %esi        # imm = 0x1000000
xorl %ebp, %ebp
cmpl $0x2000000, %esi        # imm = 0x2000000
jl 0x28ae
cmpl $0xd, %edx
ja 0x28ae
movl $0x2950, %esi           # imm = 0x2950
btl %edx, %esi
jae 0x28ae
xorl %ebp, %ebp
xorl %ecx, %ecx
jmp 0x28ae
movl $0x1, %ebp
cmpl $-0x1, %eax
je 0x2937
testb %cl, %cl
jne 0x2937
movl 0xc(%rsp), %eax
cmpl $-0x1, %eax
je 0x27d4
leal 0x1(%r15), %ecx
cmpl %eax, %r15d
movl %ecx, %r15d
jl 0x27d4
xorl %ebp, %ebp
jmp 0x2937
movq 0x30(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x66d9(%rip), %rdi      # 0x8fc8
callq 0x2200
movq %rax, %rbx
leaq 0x3761(%rip), %rsi      # 0x605f
movl $0xf, %edx
movq %rax, %rdi
callq 0x2200
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2110
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x2953
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21d0
leaq 0x78(%rsp), %r14
leaq 0x30(%rsp), %rdi
callq 0x2a24
movq 0x68(%rsp), %rdi
cmpq %r14, %rdi
je 0x2979
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21d0
movl %ebp, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x2220
jmp 0x299b
jmp 0x29b6
movq %rax, %rbx
jmp 0x29f6
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2b90
jmp 0x29f6
jmp 0x29bb
jmp 0x29b6
movq %rax, %rbx
jmp 0x29da
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x29da
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x29f6
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21d0
leaq 0x30(%rsp), %rdi
callq 0x2a24
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x2a1c
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22f0