// File: /workspace/github_c_makefile_star2_O3/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
movb (%rsi), %bpl
testb %bpl, %bpl
je 0x97b6
callq 0x5580
movq (%rax), %rax
leaq 0x1(%rbx), %rcx
movsbq %bpl, %rdx
testb $0x8, 0x1(%rax,%rdx,2)
je 0x996a
movb (%rcx), %bpl
incq %rcx
testb %bpl, %bpl
jne 0x979c
leaq 0x1560b(%rip), %rdx     # 0x1edc8
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 0x996d
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movb $0x0, (%rsp,%rax)
movq %rbx, %rdi
callq 0x54b0
movl %eax, %ebp
callq 0x5110
cmpl %eax, %ebp
jge 0x996d
leaq 0x155b6(%rip), %rdx     # 0x1edd2
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 0x13f(%rip), %rsi       # 0x9982
movq %r13, %rdi
movq %r15, %rdx
callq 0x967f
testl %eax, %eax
je 0x996d
movq 0x20763(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xea3b
leaq 0x1556f(%rip), %rsi     # 0x1eddb
movq %rsp, %r9
movq %r15, %rdi
movq %rax, %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x52c0
leaq 0x2141f(%rip), %r13     # 0x2aca8
movq (%r13), %r15
testq %r15, %r15
je 0x98b4
callq 0xea3b
leaq 0x1553d(%rip), %rsi     # 0x1eddb
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 0x98e2
movl %ebp, %edi
movl $0xf, %esi
callq 0x5310
movl $0x1, %edi
callq 0x5540
incl %r15d
jne 0x98ba
movl %ebp, %edi
xorl %esi, %esi
callq 0x5310
movl $0x1, %r12d
testl %eax, %eax
jne 0x996d
movq 0x206c4(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xea3b
leaq 0x154e6(%rip), %rsi     # 0x1edf1
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 0x994c
callq 0xea3b
leaq 0x154bb(%rip), %rsi     # 0x1edf1
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
jmp 0x996d
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq