// File: /workspace/github_c_makefile_star2_O3/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 0x6483(%rip), %rdi      # 0x90a2
callq 0x2120
movq %rax, %r15
movq %rax, %rdi
callq 0x2320
testq %rax, %rax
je 0x2d51
movq %rax, %r14
leaq 0x6466(%rip), %r12      # 0x90a8
leaq 0x230(%rsp), %r13
movl %ebp, 0x4(%rsp)
cmpb $0x4, 0x12(%r14)
jne 0x2d3d
cmpb $0x2e, 0x13(%r14)
jne 0x2c7d
cmpb $0x0, 0x14(%r14)
je 0x2d3d
cmpb $0x2e, 0x14(%r14)
jne 0x2c7d
cmpb $0x0, 0x15(%r14)
je 0x2d3d
addq $0x13, %r14
movq %r14, %rdi
callq 0x2480
cmpl %ebp, %eax
je 0x2d3d
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 0x2d3d
movq %r13, %rdi
leaq 0x6874(%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 0x2d35
leaq 0x10(%rsp), %rdi
leaq 0x63ce(%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 0x2d35
cmpl $0x1, (%rsp)
jne 0x2d76
movq %r14, %rdi
callq 0x2480
movl %eax, %edi
movl $0xf, %esi
callq 0x2300
movq %rbx, %rdi
callq 0x2110
movq %r15, %rdi
callq 0x2320
movq %rax, %r14
testq %rax, %rax
jne 0x2c4e
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 0x2d62
movq %r14, %rdi
callq 0x2480
leaq 0x6324(%rip), %rdi      # 0x90b9
xorl %ebx, %ebx
movl %eax, %esi
xorl %eax, %eax
callq 0x2170
jmp 0x2d62