// File: /workspace/github_cpp_makefile_star2_O3/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 $0x158, %rsp            # imm = 0x158
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x88(%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 0x98(%rsp), %rdi
callq 0x2a90
leaq 0x3a83(%rip), %rdx      # 0x6004
leaq 0x3a89(%rip), %rcx      # 0x6011
leaq 0x3a84(%rip), %r8       # 0x6013
leaq 0x98(%rsp), %rdi
leaq 0xc(%rsp), %r9
movl $0x6d, %esi
callq 0x307c
leaq 0x3a83(%rip), %rsi      # 0x6030
leaq 0x98(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x3206
leaq 0x98(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x32cc
leaq 0x98(%rsp), %rdi
callq 0x2ba0
movq 0x30(%rsp), %rbx
cmpq %rbx, 0x38(%rsp)
je 0x2631
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq (%rbx), %rdi
leaq 0x98(%rsp), %r14
movq %r14, %rsi
callq 0x21a0
movl 0x18(%r14), %ecx
andl $0x4000, %ecx           # imm = 0x4000
orl %eax, %ecx
jne 0x2681
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x2100
jmp 0x27be
movq 0x69b8(%rip), %rbx      # 0x8ff0
leaq 0x3a03(%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 0x6986(%rip), %rdi      # 0x8ff0
callq 0x2040
movl $0x1, %ebp
movq %rax, %rdi
callq 0x2110
jmp 0x2958
leaq 0x39e7(%rip), %rdi      # 0x606f
callq 0x2230
movq %rax, %rbp
movq %rax, %rdi
callq 0x20e0
movq %rax, %r14
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
testq %r14, %r14
jle 0x2785
addq %rbp, %r14
leaq 0x10(%rsp), %r15
movq %rbp, %rdi
movl $0x3a, %esi
callq 0x20c0
movq %rax, %r12
testq %rax, %rax
cmoveq %r14, %r12
movl $0xf, %eax
leaq 0x20(%rsp), %rcx
cmpq %rcx, 0x10(%rsp)
je 0x26ed
movq 0x20(%rsp), %rax
movq %r12, %r13
subq %rbp, %r13
movq 0x8(%rbx), %rcx
leaq (%rcx,%r13), %rsi
incq %rsi
cmpq %rsi, %rax
cmovaq %rax, %rsi
movq %r15, %rdi
callq 0x2290
movq 0x18(%rsp), %rdx
movq %r15, %rdi
xorl %esi, %esi
movq %rbp, %rcx
movq %r13, %r8
callq 0x21f0
movq 0x18(%rsp), %rsi
movl $0x1, %ecx
movq %r15, %rdi
xorl %edx, %edx
movl $0x2f, %r8d
callq 0x2320
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r15, %rdi
callq 0x2090
movq 0x10(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x21a0
movl 0xb0(%rsp), %ecx
andl $0x4000, %ecx           # imm = 0x4000
orl %eax, %ecx
je 0x2789
xorl %ebp, %ebp
cmpb $0x3a, (%r12)
sete %bpl
addq %r12, %rbp
cmpq %r14, %rbp
jb 0x26c0
xorl %ebx, %ebx
jmp 0x279a
movb $0x1, %bl
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2100
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x27b6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
testb %bl, %bl
je 0x28d9
xorl %eax, %eax
movq 0x6809(%rip), %r14      # 0x8fd0
leaq 0x98(%rsp), %rbx
movl $0x2950, %r12d          # imm = 0x2950
movq %rax, 0x70(%rsp)
callq 0x2070
testl %eax, %eax
jne 0x2858
movq 0x30(%rsp), %r13
movq 0x38(%rsp), %r15
movq %r15, %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, %r15
je 0x2840
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 0x282c
movq $0x0, (%rax,%rbp,8)
movq 0x50(%rsp), %rdi
movq (%r14), %rdx
movq %rax, %rsi
callq 0x22e0
cmpl $-0x1, %eax
je 0x2990
movl $0x0, 0x98(%rsp)
movq %rbx, %rdi
callq 0x2240
cmpl $-0x1, %eax
je 0x28d2
movl 0x98(%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 0x2934
cmpl $0xd, %eax
ja 0x2934
btl %eax, %r12d
jae 0x2934
movl 0xc(%rsp), %eax
cmpl $-0x1, %eax
je 0x27da
movq 0x70(%rsp), %rdx
leal 0x1(%rdx), %ecx
cmpl %eax, %edx
movl %ecx, %eax
jl 0x27d5
xorl %ebp, %ebp
jmp 0x2934
movl $0x1, %ebp
jmp 0x2934
movq 0x30(%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x66dc(%rip), %rdi      # 0x8fc8
callq 0x2200
movq %rax, %rbx
leaq 0x3764(%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 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x2950
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21d0
leaq 0x88(%rsp), %r14
leaq 0x30(%rsp), %rdi
callq 0x2a30
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0x297c
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21d0
movl %ebp, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x2220
jmp 0x29c0
jmp 0x29a0
jmp 0x29bb
movq %rax, %rbx
jmp 0x29fb
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x2ba0
jmp 0x29fb
jmp 0x29c0
jmp 0x29bb
movq %rax, %rbx
jmp 0x29df
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x29df
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x29fb
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x21d0
leaq 0x30(%rsp), %rdi
callq 0x2a30
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x2a27
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22f0
nop