// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/main.c
// Function: is_brother_process
static int is_brother_process(const char *dir, const char *file, void *argv[])
{
    //const char *myself = (const char *)argv[0];
    char linkname[MAX_PATH];
    char filename[MAX_PATH];
    int linksize;
    int i = 0, kill_timeout = 15;
    pid_t pid;

    //dbg_time("%s", file);
    while (file[i]) {
        if (!isdigit(file[i]))
            break;
        i++;
    }

    if (file[i]) {
        //dbg_time("%s not digit", file);
        return 0;
    }

    snprintf(linkname, MAX_PATH, "%s/%s/exe", dir, file);
    linksize = readlink(linkname, filename, MAX_PATH);
    if (linksize <= 0)
        return 0;

    filename[linksize] = 0;

    pid = atoi(file);
    if (pid >= getpid())
        return 0;

    snprintf(linkname, MAX_PATH, "%s/%s/fd", dir, file);
    if (!ls_dir(linkname, is_same_linkfile, argv))
        return 0;

    dbg_time("%s/%s/exe -> %s", dir, file, filename);
    while (kill_timeout-- && !kill(pid, 0))
    {
        kill(pid, SIGTERM);
        sleep(1);
    }
    if (!kill(pid, 0))
    {
        dbg_time("force kill %s/%s/exe -> %s", dir, file, filename);
        kill(pid, SIGKILL);
        sleep(1);
    }

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %r15
movsbq (%r15), %r13
testq %r13, %r13
je 0x940d
callq 0x5590
movq (%rax), %rax
incq %r15
testb $0x8, 0x1(%rax,%r13,2)
jne 0x93e9
xorl %r15d, %r15d
jmp 0x95bf
leaq 0x139b4(%rip), %rdx     # 0x1cdc8
xorl %r15d, %r15d
leaq 0x100(%rsp), %r13
movl $0x100, %esi            # imm = 0x100
movq %r13, %rdi
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x51c0
movq %rsp, %rsi
movl $0x100, %edx            # imm = 0x100
movq %r13, %rdi
callq 0x50d0
testl %eax, %eax
jle 0x95bf
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movb $0x0, (%rsp,%rax)
movq %rbx, %rdi
callq 0x54c0
movl %eax, %ebp
callq 0x5110
cmpl %eax, %ebp
jge 0x95bf
leaq 0x1395f(%rip), %rdx     # 0x1cdd2
xorl %r15d, %r15d
leaq 0x100(%rsp), %r13
movl $0x100, %esi            # imm = 0x100
movq %r13, %rdi
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x51c0
leaq 0x13a(%rip), %rsi       # 0x95d4
movq %r13, %rdi
movq %r12, %rdx
callq 0x92e5
testl %eax, %eax
je 0x95bf
movq 0x1fb04(%rip), %rax     # 0x28fb8
movq (%rax), %r15
callq 0xe343
leaq 0x13918(%rip), %rsi     # 0x1cddb
movq %rsp, %r9
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x52c0
leaq 0x207c8(%rip), %rax     # 0x29ca8
movq (%rax), %r15
testq %r15, %r15
je 0x950a
callq 0xe343
leaq 0x138e7(%rip), %rsi     # 0x1cddb
movq %rsp, %r9
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x52c0
pushq $-0xf
popq %r13
pushq $0xf
popq %r12
pushq $0x1
popq %r15
testl %r13d, %r13d
je 0x953f
movl %ebp, %edi
xorl %esi, %esi
callq 0x5310
testl %eax, %eax
jne 0x953f
movl %ebp, %edi
movl %r12d, %esi
callq 0x5310
movl %r15d, %edi
callq 0x5550
incl %r13d
jmp 0x9516
movl %ebp, %edi
xorl %esi, %esi
callq 0x5310
testl %eax, %eax
jne 0x95bf
movq 0x1fa65(%rip), %rax     # 0x28fb8
movq (%rax), %r15
callq 0xe343
leaq 0x1388f(%rip), %rsi     # 0x1cdf1
movq %rsp, %r9
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x52c0
leaq 0x20729(%rip), %rax     # 0x29ca8
movq (%rax), %r15
testq %r15, %r15
je 0x95a9
callq 0xe343
leaq 0x1385e(%rip), %rsi     # 0x1cdf1
movq %rsp, %r9
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x52c0
pushq $0x9
popq %rsi
movl %ebp, %edi
callq 0x5310
pushq $0x1
popq %r15
movl %r15d, %edi
callq 0x5550
movl %r15d, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq