// File: /workspace/github_cpp_makefile_star2_O2/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 $0x128, %rsp            # imm = 0x128
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorps %xmm0, %xmm0
andq $0x0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
orl $-0x1, 0xc(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x2904
leaq 0x3b0d(%rip), %rdx      # 0x6004
leaq 0x3b13(%rip), %rcx      # 0x6011
leaq 0x3b0e(%rip), %r8       # 0x6013
leaq 0x68(%rsp), %rdi
pushq $0x6d
popq %rsi
leaq 0xc(%rsp), %r9
callq 0x2bc8
leaq 0x3b12(%rip), %rsi      # 0x6030
leaq 0x68(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x2d2a
leaq 0x68(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x2dd4
leaq 0x68(%rsp), %rdi
callq 0x2a0c
movq 0x10(%rsp), %rbx
cmpq %rbx, 0x18(%rsp)
je 0x2581
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %rbx, %rdi
callq 0x283b
testb %al, %al
je 0x25a4
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x20f0
jmp 0x26ec
movq 0x7a68(%rip), %rdi      # 0x9ff0
leaq 0x3ab3(%rip), %rsi      # 0x6042
callq 0x21b0
movq %rax, %rdi
callq 0x20d0
pushq $0x1
popq %rbp
jmp 0x26ab
leaq 0x3ac4(%rip), %rdi      # 0x606f
callq 0x2230
movq %rax, %r12
movq %rax, %rdi
callq 0x20b0
leaq 0x78(%rsp), %r13
movq %r13, -0x10(%r13)
andq $0x0, -0x8(%r13)
movq %rax, %r14
addq %r12, %r14
movb $0x0, (%r13)
leaq 0x68(%rsp), %r15
cmpq %r14, %r12
jae 0x266c
movq %r12, %rdi
pushq $0x3a
popq %rsi
callq 0x2090
movq %rax, %rbp
testq %rax, %rax
cmoveq %r14, %rbp
pushq $0xf
popq %rax
cmpq %r13, 0x68(%rsp)
je 0x2606
movq 0x78(%rsp), %rax
movq 0x8(%rbx), %rcx
movq %rbp, %rdx
subq %r12, %rdx
leaq (%rdx,%rcx), %rsi
incq %rsi
cmpq %rsi, %rax
cmovaq %rax, %rsi
movq %r15, %rdi
callq 0x22a0
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x288a
movq %r15, %rdi
pushq $0x1
popq %rsi
pushq $0x2f
popq %rdx
callq 0x21f0
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2350
movq %r15, %rdi
callq 0x283b
testb %al, %al
jne 0x26d3
xorl %r12d, %r12d
cmpb $0x3a, (%rbp)
sete %r12b
addq %rbp, %r12
jmp 0x25d9
leaq 0x68(%rsp), %rdi
callq 0x20c0
movq 0x10(%rsp), %rsi
movq 0x7946(%rip), %rdi      # 0x9fc8
callq 0x2190
leaq 0x39d1(%rip), %rsi      # 0x605f
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20d0
pushq $0x1
popq %rbp
leaq 0x28(%rsp), %rdi
callq 0x20c0
leaq 0x10(%rsp), %rdi
callq 0x2868
leaq 0x48(%rsp), %rdi
callq 0x20c0
movl %ebp, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x20f0
leaq 0x68(%rsp), %rdi
callq 0x20c0
xorl %r15d, %r15d
movq 0x78da(%rip), %r14      # 0x9fd0
leaq 0x68(%rsp), %rbx
movl $0x2950, %r13d          # imm = 0x2950
callq 0x2060
testl %eax, %eax
jne 0x276b
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rbp
subq %r12, %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
xorl %ecx, %ecx
cmpq %rcx, %rbp
je 0x2756
movq (%r12), %rdx
movq %rdx, (%rax,%rcx,8)
incq %rcx
addq $0x20, %r12
jmp 0x2740
andq $0x0, (%rax,%rbp,8)
movq 0x28(%rsp), %rdi
movq (%r14), %rdx
movq %rax, %rsi
callq 0x22f0
cmpl $-0x1, %eax
je 0x27dd
andl $0x0, 0x68(%rsp)
movq %rbx, %rdi
callq 0x2240
cmpl $-0x1, %eax
je 0x269e
movl 0x68(%rsp), %eax
andl $0x7f, %eax
movl %eax, %ecx
shll $0x18, %ecx
addl $0x1000000, %ecx        # imm = 0x1000000
xorl %ebp, %ebp
cmpl $0x2000000, %ecx        # imm = 0x2000000
jl 0x26a1
cmpl $0xd, %eax
ja 0x26a1
btl %eax, %r13d
jae 0x26a1
movl 0xc(%rsp), %eax
cmpl $-0x1, %eax
je 0x2701
leal 0x1(%r15), %ecx
cmpl %eax, %r15d
movl %ecx, %r15d
jl 0x2701
xorl %ebp, %ebp
jmp 0x26a1
pushq $0x1
popq %rdi
callq 0x2220
jmp 0x2808
jmp 0x27eb
jmp 0x2803
movq %rax, %rbx
jmp 0x281f
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x2a0c
jmp 0x281f
jmp 0x2803
jmp 0x2808
movq %rax, %rbx
jmp 0x2815
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x20c0
leaq 0x28(%rsp), %rdi
callq 0x20c0
leaq 0x10(%rsp), %rdi
callq 0x2868
leaq 0x48(%rsp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x2300