// File: /workspace/github_c_makefile_star2_O1/yancanchen[P]mc-bloom-filter/mc_bloom_filter.c
// Function: main
int main(int argc, char *argv[]) 
{
    int c;
    conn *l_conn;
    struct in_addr addr;
    int daemonize = 1;
    struct passwd *pw;
    struct sigaction sa;
    struct rlimit rlim;

    /* init my_srv */
    init_my_srv_default();

    /* set stderr non-buffering (for running under, say, daemontools) */
    setbuf(stderr, NULL);

    /* process arguments */
    while ((c = getopt(argc, argv, "p:c:khirvdl:u:P:m:")) != -1) {
        switch (c) {
        case 'p':
            my_srv.port = atoi(optarg);
            break;
        // max memory now not use 
        case 'm':
            my_srv.maxbytes = ((size_t)atoi(optarg))*1024*1024;
            break;
        case 'c':
            my_srv.maxconns = atoi(optarg);
            break;
        case 'h':
            usage();
            exit(0);
        case 'i':
            usage_license();
            exit(0);
        case 'k':
            my_srv.lock_memory = 1;
            break;
        case 'v':
            my_srv.verbose++;
            break;
        case 'l':
            if (!inet_pton(AF_INET, optarg, &addr)) {
                fprintf(stderr, "Illegal address: %s\n", optarg);
                return 1;
            } else {
                my_srv.interface = addr;
            }
            break;
        case 'd':
            daemonize = 1;
            break;
        case 'r':
            my_srv.maxcore = 1;
            break;
        case 'u':
            my_srv.username = optarg;
            break;
        case 'P':
            my_srv.pid_file = optarg;
            break;
        default:
            fprintf(stderr, "Illegal argument \"%c\"\n", c);
            return 1;
        }
    }

    if (my_srv.maxcore) {
        struct rlimit rlim_new;
        /* 
         * First try raising to infinity; if that fails, try bringing
         * the soft limit to the hard. 
         */
        if (getrlimit(RLIMIT_CORE, &rlim)==0) {
            rlim_new.rlim_cur = rlim_new.rlim_max = RLIM_INFINITY;
            if (setrlimit(RLIMIT_CORE, &rlim_new)!=0) {
                /* failed. try raising just to the old max */
                rlim_new.rlim_cur = rlim_new.rlim_max = 
                    rlim.rlim_max;
                (void) setrlimit(RLIMIT_CORE, &rlim_new);
            }
        }
        /* 
         * getrlimit again to see what we ended up with. Only fail if 
         * the soft limit ends up 0, because then no core files will be 
         * created at all.
         */

        if ((getrlimit(RLIMIT_CORE, &rlim)!=0) || rlim.rlim_cur==0) {
            fprintf(stderr, "failed to ensure corefile creation\n");
            exit(1);
        }
    }

    /* 
     * If needed, increase rlimits to allow as many connections
     * as needed.
     */

    if (getrlimit(RLIMIT_NOFILE, &rlim) != 0) {
        fprintf(stderr, "failed to getrlimit number of files\n");
        exit(1);
    } else {
        int maxfiles = my_srv.maxconns;
        if (rlim.rlim_cur < maxfiles) 
            rlim.rlim_cur = maxfiles + 3;
        if (rlim.rlim_max < rlim.rlim_cur)
            rlim.rlim_max = rlim.rlim_cur;
        if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
            fprintf(stderr, "failed to set rlimit for open files. "
                    "Try running as root or requesting smaller maxconns value.\n");
            exit(1);
        }
    }

    /* 
     * initialization order: first create the listening socket
     * (may need root on low ports), then drop root if needed,
     * then daemonise if needed, then init libevent (in some cases
     * descriptors created by libevent wouldn't survive forking).
     */

    /* create the listening socket and bind it */
    l_socket = server_socket(my_srv.port);
    if (l_socket == -1) {
        fprintf(stderr, "failed to listen\n");
        exit(1);
    }

    /* lose root privileges if we have them */
    if (getuid()== 0 || geteuid()==0) {
        if (my_srv.username==0 || *(my_srv.username)=='\0') {
            fprintf(stderr, "can't run as root without the username switch\n");
            return 1;
        }
        if ((pw = getpwnam(my_srv.username)) == 0) {
            fprintf(stderr, "can't find the user %s to switch to\n", my_srv.username);
            return 1;
        }
        if (setgid(pw->pw_gid)<0 || setuid(pw->pw_uid)<0) {
            fprintf(stderr, "failed to assume identity of user %s\n", my_srv.username);
            return 1;
        }
    }

    stats_init();

    /* daemonize if requested */
    /* if we want to ensure our ability to dump core, don't chdir to / */
    if (daemonize) {
        int res;
        res = daemon(my_srv.maxcore, my_srv.verbose);
        if (res == -1) {
            fprintf(stderr, "failed to daemon() in order to daemonize\n");
            return 1;
        }
    }


    /* initialize other stuff */
    event_init();
    conn_init();
            
    if (blooms_init(my_srv.maxbytes)) {
        fprintf(stderr, "blooms init failed, No enough memory?");
        exit(-1);
    }

    /* lock paged memory if needed */
    if (my_srv.lock_memory) {
#define HAVE_MLOCKALL
#ifdef HAVE_MLOCKALL
        mlockall(MCL_CURRENT | MCL_FUTURE);
#else
        fprintf(stderr, "warning: mlockall() not supported on this platform.  proceeding without.\n");
#endif
    }

    /*
     * ignore SIGPIPE signals; we can use errno==EPIPE if we
     * need that information
     */
    sa.sa_handler = SIG_IGN;
    sa.sa_flags = 0;
    if (sigemptyset(&sa.sa_mask) == -1 ||
            sigaction(SIGPIPE, &sa, 0) == -1) {
        perror("failed to ignore SIGPIPE; sigaction");
        exit(1); 
    }

    /* create the initial listening connection */
    if (!(l_conn = conn_new(l_socket, conn_listening, EV_READ | EV_PERSIST))) {
        fprintf(stderr, "failed to create listening connection");
        exit(1);
    }

    /* save the PID in if we're a daemon */
    if (daemonize)
        save_pid(getpid(),my_srv.pid_file);

    fprintf(stderr, "service started!\r\n");

    /* enter the loop */
    event_loop(0);

    /* remove the PID file if we're a daemon */
    if (daemonize)
        remove_pidfile(my_srv.pid_file);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movdqa 0x168d(%rip), %xmm0     # 0x6240
movdqa %xmm0, 0x46d5(%rip)     # 0x9290
movq $0x40000000, 0x46e2(%rip) # imm = 0x40000000
xorl %eax, %eax
movl %eax, 0x46d2(%rip)      # 0x92a0
pxor %xmm0, %xmm0
movdqa %xmm0, 0x46d6(%rip)     # 0x92b0
movl %eax, 0x46e0(%rip)      # 0x92c0
movq 0x4411(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
xorl %esi, %esi
callq 0x2140
leaq 0x1dfa(%rip), %r14      # 0x69f2
movq 0x43d9(%rip), %r13      # 0x8fd8
leaq 0x166e(%rip), %r12      # 0x6274
leaq 0x1c(%rsp), %r15
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2370
leal -0x63(%rax), %ecx
cmpl $0x13, %ecx
ja 0x4c3a
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movq (%r13), %rdi
callq 0x2390
movl %eax, 0x4658(%rip)      # 0x9290
jmp 0x4c0b
cmpl $0x50, %eax
jne 0x4cda
movq (%r13), %rax
movq %rax, 0x466a(%rip)      # 0x92b8
jmp 0x4c0b
movl $0x1, 0x4646(%rip)      # 0x92a0
jmp 0x4c0b
movq (%r13), %rsi
movl $0x2, %edi
movq %r15, %rdx
callq 0x2250
testl %eax, %eax
je 0x4f5c
movl 0x1c(%rsp), %eax
movl %eax, 0x4641(%rip)      # 0x92c0
jmp 0x4c0b
movq (%r13), %rdi
callq 0x2390
cltq
shlq $0x14, %rax
movq %rax, 0x4611(%rip)      # 0x92a8
jmp 0x4c0b
movl $0x1, 0x45ee(%rip)      # 0x9294
jmp 0x4c0b
incl 0x45eb(%rip)            # 0x929c
jmp 0x4c0b
movq (%r13), %rdi
callq 0x2390
movl %eax, 0x45d3(%rip)      # 0x9298
jmp 0x4c0b
movq (%r13), %rax
movq %rax, 0x45db(%rip)      # 0x92b0
jmp 0x4c0b
cmpl $-0x1, %eax
jne 0x4f39
cmpl $0x0, 0x45aa(%rip)      # 0x9294
je 0x4d58
leaq 0x8(%rsp), %rsi
movl $0x4, %edi
callq 0x23d0
testl %eax, %eax
jne 0x4d35
pcmpeqd %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movdqa %xmm0, (%rsi)
movl $0x4, %edi
callq 0x22b0
testl %eax, %eax
je 0x4d35
movq 0x10(%rsp), %rax
leaq 0x20(%rsp), %rsi
movq %rax, 0x8(%rsi)
movq %rax, (%rsi)
movl $0x4, %edi
callq 0x22b0
leaq 0x8(%rsp), %rsi
movl $0x4, %edi
callq 0x23d0
testl %eax, %eax
jne 0x4fc8
cmpq $0x0, 0x8(%rsp)
je 0x4fc8
leaq 0x8(%rsp), %rsi
movl $0x7, %edi
callq 0x23d0
testl %eax, %eax
jne 0x4faf
movslq 0x451a(%rip), %rax      # 0x9290
cmpq %rax, 0x8(%rsp)
jae 0x4d86
addq $0x3, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jae 0x4d97
movq %rax, 0x10(%rsp)
leaq 0x8(%rsp), %rsi
movl $0x7, %edi
callq 0x22b0
testl %eax, %eax
jne 0x4fb4
movl 0x44e4(%rip), %edi      # 0x9298
callq 0x48fe
movl %eax, 0x4519(%rip)      # 0x92d8
cmpl $-0x1, %eax
je 0x4fb9
callq 0x2130
testl %eax, %eax
je 0x4dda
callq 0x21b0
testl %eax, %eax
jne 0x4e24
movq 0x44cf(%rip), %rdi      # 0x92b0
testq %rdi, %rdi
je 0x4f55
cmpb $0x0, (%rdi)
je 0x4f55
callq 0x2220
testq %rax, %rax
je 0x4f79
movq %rax, %rbx
movl 0x14(%rax), %edi
callq 0x2300
testl %eax, %eax
js 0x4f63
movl 0x10(%rbx), %edi
callq 0x23e0
testl %eax, %eax
js 0x4f63
movl $0x0, 0x4422(%rip)      # 0x9250
xorl %ebx, %ebx
movq %rbx, 0x4411(%rip)      # 0x9248
pxor %xmm0, %xmm0
movdqu %xmm0, 0x4415(%rip)     # 0x9258
movq %rbx, 0x441e(%rip)      # 0x9268
movdqu %xmm0, 0x4426(%rip)     # 0x9278
xorl %edi, %edi
callq 0x2270
movq %rax, 0x4410(%rip)      # 0x9270
movl 0x442e(%rip), %edi      # 0x9294
movl 0x4430(%rip), %esi      # 0x929c
callq 0x3098
movl %eax, %ebp
cmpl $-0x1, %eax
je 0x4f6a
cmpl $-0x1, %ebp
je 0x4f83
callq 0x2400
movl $0xc8, 0x4434(%rip)     # 0x92c8
movl $0x0, 0x442e(%rip)      # 0x92cc
movl $0x640, %edi            # imm = 0x640
callq 0x2280
movq %rax, 0x4421(%rip)      # 0x92d0
movq 0x43f2(%rip), %rdi      # 0x92a8
callq 0x3028
testl %eax, %eax
jne 0x4fbe
cmpl $0x0, 0x43d6(%rip)      # 0x92a0
je 0x4ed6
movl $0x3, %edi
callq 0x22d0
leaq 0x28(%rsp), %rdi
movq $0x1, -0x8(%rdi)
movl $0x0, 0x80(%rdi)
callq 0x2240
cmpl $-0x1, %eax
je 0x4faa
leaq 0x20(%rsp), %rsi
movl $0xd, %edi
xorl %edx, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x4faa
movl 0x43bd(%rip), %edi      # 0x92d8
xorl %ebx, %ebx
xorl %esi, %esi
movl $0x12, %edx
callq 0x3226
testq %rax, %rax
je 0x4fc3
callq 0x26a1
jmp 0x4f83
movq 0x40b8(%rip), %rcx      # 0x8ff8
movq (%rcx), %rdi
leaq 0x1ad0(%rip), %rsi      # 0x6a1a
movl %eax, %edx
xorl %eax, %eax
callq 0x2230
jmp 0x4f7e
callq 0x276d
jmp 0x4f7e
callq 0x25c3
jmp 0x4f7e
callq 0x2723
jmp 0x4f7e
callq 0x265a
movl $0x1, %ebx
jmp 0x4e7c
callq 0x2748
movl $0x1, %ebx
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4b69
jmp 0x4fa3
callq 0x4ad3
xorl %edi, %edi
callq 0x23b0
callq 0x270e
callq 0x2610
callq 0x2635
callq 0x278f
callq 0x267c
callq 0x26e9
callq 0x25eb
nopl (%rax)