// File: /workspace/github_c_makefile_star2_O1/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, 0x4(%rsp)
callq 0x20f0
movl %eax, %ebp
leaq 0x647a(%rip), %rdi      # 0x90a2
callq 0x2120
movq %rax, %r15
movq %rax, %rdi
callq 0x2310
testq %rax, %rax
je 0x2d6d
movq %rax, %r14
leaq 0x645e(%rip), %r12      # 0x90a9
leaq 0x6456(%rip), %r13      # 0x90a8
cmpb $0x4, 0x12(%r14)
jne 0x2d59
addq $0x13, %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2280
testl %eax, %eax
je 0x2d59
movq %r14, %rdi
movq %r13, %rsi
callq 0x2280
testl %eax, %eax
je 0x2d59
movq %r14, %rdi
callq 0x2470
cmpl %ebp, %eax
je 0x2d59
movq %r12, %rbx
movl %ebp, %r12d
movq %r13, %rbp
leaq 0x120(%rsp), %r13
movq %r13, %rdi
leaq 0x63f9(%rip), %rsi      # 0x90ab
movq %r14, %rdx
xorl %eax, %eax
callq 0x2490
movq %r13, %rdi
movq %rbp, %r13
movl %r12d, %ebp
movq %rbx, %r12
xorl %esi, %esi
callq 0x2430
testl %eax, %eax
jne 0x2d59
leaq 0x120(%rsp), %rdi
leaq 0x684f(%rip), %rsi      # 0x9535
callq 0x2440
movq %rax, %rbx
leaq 0x230(%rsp), %rdi
movl $0x10d, %esi            # imm = 0x10D
movq %rax, %rdx
callq 0x2260
testq %rax, %rax
je 0x2d51
leaq 0x230(%rsp), %rdi
leaq 0x63a2(%rip), %rsi      # 0x90b9
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2340
movq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2280
testl %eax, %eax
jne 0x2d51
cmpl $0x1, 0x4(%rsp)
jne 0x2d93
movq %r14, %rdi
callq 0x2470
movl %eax, %edi
movl $0xf, %esi
callq 0x22f0
movq %rbx, %rdi
callq 0x2110
movq %r15, %rdi
callq 0x2310
movq %rax, %r14
testq %rax, %rax
jne 0x2c52
movq %r15, %rdi
callq 0x2200
xorl %ebx, %ebx
cmpl $0x4, 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, 0x4(%rsp)
je 0x2d7f
movq %r14, %rdi
callq 0x2470
leaq 0x6309(%rip), %rdi      # 0x90bc
xorl %ebx, %ebx
movl %eax, %esi
xorl %eax, %eax
callq 0x2170
jmp 0x2d7f