// File: /workspace/github_c_makefile_star2_O2/niuyuling[P]CProxy/main.c
// Function: process_signal
int process_signal(int signal, char *process_name)
{
    char bufer[CACHE_SIZE];
    char comm[CACHE_SIZE];
    char proc_comm_name[CACHE_SIZE];
    FILE *fp;
    DIR *dir;
    struct dirent *ptr;
    pid_t self_pid;

    self_pid = getpid();
    dir = opendir("/proc");
    bzero(bufer, 0);
    bzero(comm, 0);
    bzero(proc_comm_name, 0);
    while ((ptr = readdir(dir)) != NULL) {
        if (ptr->d_type != DT_DIR)
            continue;
        if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0 || atoi(ptr->d_name) == self_pid)
            continue;

        sprintf(comm, "/proc/%s/comm", ptr->d_name);
        if (access(comm, F_OK) == 0) {
            fp = fopen(comm, "r");
            if (fgets(bufer, CACHE_SIZE - 1, fp) == NULL) {
                fclose(fp);
                continue;
            }
            sscanf(bufer, "%s", proc_comm_name);
            if (!strcmp(process_name, proc_comm_name)) {
                if (signal == SERVER_TYPE_STOP)
                    kill(atoi(ptr->d_name), SIGTERM);
                else {
                    closedir(dir);
                    if (signal != SERVICE_TYPE_STATUS_NOT_PRINT)
                        printf("\t%d\n", atoi(ptr->d_name));;
                    return 0;
                }
            }
            fclose(fp);
        }
    }
    closedir(dir);

    if (signal == SERVER_TYPE_STATUS) ;
    else if (signal == SERVICE_TYPE_STATUS_NOT_PRINT)
        return 1;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
movq %rsi, 0x8(%rsp)
movl %edi, (%rsp)
callq 0x20f0
movl %eax, %ebp
leaq 0x664e(%rip), %rdi      # 0x90a2
callq 0x2120
movq %rax, %r15
leaq 0x6645(%rip), %r12      # 0x90a8
leaq 0x230(%rsp), %r13
movl %ebp, 0x4(%rsp)
movq %r15, %rdi
callq 0x2320
testq %rax, %rax
je 0x2b60
movq %rax, %r14
cmpb $0x4, 0x12(%rax)
jne 0x2a6f
cmpb $0x2e, 0x13(%r14)
jne 0x2aa5
cmpb $0x0, 0x14(%r14)
je 0x2a6f
cmpb $0x2e, 0x14(%r14)
jne 0x2aa5
cmpb $0x0, 0x15(%r14)
je 0x2a6f
addq $0x13, %r14
movq %r14, %rdi
callq 0x2480
cmpl %ebp, %eax
je 0x2a6f
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x24a0
movq %r13, %rdi
xorl %esi, %esi
callq 0x2440
testl %eax, %eax
jne 0x2a6f
movq %r13, %rdi
leaq 0x6a54(%rip), %rsi      # 0x9531
callq 0x2450
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
movl $0x10d, %esi            # imm = 0x10D
movq %rax, %rdx
callq 0x2260
testq %rax, %rax
je 0x2b53
leaq 0x10(%rsp), %rdi
leaq 0x65ae(%rip), %rsi      # 0x90b6
movq %r13, %rbp
movq %r12, %r13
leaq 0x120(%rsp), %r12
movq %r12, %rdx
xorl %eax, %eax
callq 0x2350
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %r12
movq %rbp, %r13
movl 0x4(%rsp), %ebp
callq 0x2290
testl %eax, %eax
jne 0x2b53
cmpl $0x1, (%rsp)
jne 0x2b85
movq %r14, %rdi
callq 0x2480
movl %eax, %edi
pushq $0xf
popq %rsi
callq 0x2300
movq %rbx, %rdi
callq 0x2110
jmp 0x2a6f
movq %r15, %rdi
callq 0x2200
xorl %ebx, %ebx
cmpl $0x4, (%rsp)
sete %bl
movl %ebx, %eax
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x2200
xorl %ebx, %ebx
cmpl $0x4, (%rsp)
je 0x2b71
movq %r14, %rdi
callq 0x2480
leaq 0x6515(%rip), %rdi      # 0x90b9
xorl %ebx, %ebx
movl %eax, %esi
xorl %eax, %eax
callq 0x2170
jmp 0x2b71