// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rsi, %rbx
movq %rdi, %r14
movsbq (%rsi), %r12
testq %r12, %r12
sete %bpl
je 0x9874
callq 0x5580
movq (%rax), %rax
testb $0x8, 0x1(%rax,%r12,2)
je 0x9868
leaq 0x1(%rbx), %rcx
movsbq (%rcx), %rdx
testq %rdx, %rdx
sete %bpl
je 0x9874
incq %rcx
testb $0x8, 0x1(%rax,%rdx,2)
jne 0x9851
xorl %r12d, %r12d
testb %bpl, %bpl
je 0x9a26
leaq 0x1554f(%rip), %rdx     # 0x1edca
xorl %r12d, %r12d
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 0x9a26
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movb $0x0, (%rsp,%rax)
movq %rbx, %rdi
callq 0x54b0
movl %eax, %ebp
callq 0x5110
cmpl %eax, %ebp
jge 0x9a26
leaq 0x154fa(%rip), %rdx     # 0x1edd4
xorl %r12d, %r12d
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       # 0x9a3b
movq %r13, %rdi
movq %r15, %rdx
callq 0x9727
testl %eax, %eax
je 0x9a26
movq 0x206a5(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xeb2f
leaq 0x154b3(%rip), %rsi     # 0x1eddd
movq %rsp, %r9
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x52c0
leaq 0x21361(%rip), %r13     # 0x2aca8
movq (%r13), %r15
testq %r15, %r15
je 0x9972
callq 0xeb2f
leaq 0x15481(%rip), %rsi     # 0x1eddd
movq %rsp, %r9
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x52c0
movl $0xfffffff1, %r15d      # imm = 0xFFFFFFF1
movl %ebp, %edi
xorl %esi, %esi
callq 0x5310
testl %eax, %eax
jne 0x99a0
movl %ebp, %edi
movl $0xf, %esi
callq 0x5310
movl $0x1, %edi
callq 0x5540
incl %r15d
jne 0x9978
movl %ebp, %edi
xorl %esi, %esi
callq 0x5310
movl $0x1, %r12d
testl %eax, %eax
jne 0x9a26
movq 0x20606(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xeb2f
leaq 0x1542a(%rip), %rsi     # 0x1edf3
movq %rsp, %r9
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x52c0
movq (%r13), %r15
testq %r15, %r15
je 0x9a0a
callq 0xeb2f
leaq 0x153ff(%rip), %rsi     # 0x1edf3
movq %rsp, %r9
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x52c0
movl %ebp, %edi
movl $0x9, %esi
callq 0x5310
movl $0x1, %r12d
movl $0x1, %edi
callq 0x5540
movl %r12d, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq