// File: /workspace/github_c_makefile_star2_O2/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
callq 0x2d7e
movq 0x3961(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
xorl %esi, %esi
callq 0x2140
leaq 0x1346(%rip), %r14      # 0x59ee
movq 0x3929(%rip), %r13      # 0x7fd8
leaq 0xbbe(%rip), %r15       # 0x5274
leaq 0x1c(%rsp), %r12
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2370
leal -0x63(%rax), %ecx
cmpl $0x13, %ecx
ja 0x46ea
movslq (%r15,%rcx,4), %rcx
addq %r15, %rcx
jmpq *%rcx
movq (%r13), %rdi
callq 0x2390
movl %eax, 0x3ba8(%rip)      # 0x8290
jmp 0x46bb
cmpl $0x50, %eax
jne 0x4785
movq (%r13), %rax
movq %rax, 0x3bba(%rip)      # 0x82b8
jmp 0x46bb
movq (%r13), %rdi
callq 0x2390
cltq
shlq $0x14, %rax
movq %rax, 0x3b92(%rip)      # 0x82a8
jmp 0x46bb
movl $0x1, 0x3b72(%rip)      # 0x8294
jmp 0x46bb
movl $0x1, 0x3b72(%rip)      # 0x82a0
jmp 0x46bb
movq (%r13), %rdi
callq 0x2390
movl %eax, 0x3b59(%rip)      # 0x8298
jmp 0x46bb
movq (%r13), %rsi
pushq $0x2
popq %rdi
movq %r12, %rdx
callq 0x2250
testl %eax, %eax
je 0x48c9
movl 0x1c(%rsp), %eax
movl %eax, 0x3b5b(%rip)      # 0x82c0
jmp 0x46bb
incl 0x3b2c(%rip)            # 0x829c
jmp 0x46bb
movq (%r13), %rax
movq %rax, 0x3b30(%rip)      # 0x82b0
jmp 0x46bb
cmpl $-0x1, %eax
jne 0x48ad
cmpl $0x0, 0x3aff(%rip)      # 0x8294
je 0x47fb
pushq $0x4
popq %rdi
leaq 0x8(%rsp), %rsi
callq 0x23d0
testl %eax, %eax
jne 0x47da
pcmpeqd %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movdqa %xmm0, (%rsi)
pushq $0x4
popq %rdi
callq 0x22b0
testl %eax, %eax
je 0x47da
movq 0x10(%rsp), %rax
leaq 0x20(%rsp), %rsi
movq %rax, 0x8(%rsi)
movq %rax, (%rsi)
pushq $0x4
popq %rdi
callq 0x22b0
pushq $0x4
popq %rdi
leaq 0x8(%rsp), %rsi
callq 0x23d0
testl %eax, %eax
jne 0x4aa8
cmpq $0x0, 0x8(%rsp)
je 0x4aa8
pushq $0x7
popq %rdi
leaq 0x8(%rsp), %rsi
callq 0x23d0
testl %eax, %eax
jne 0x4a66
movslq 0x3a79(%rip), %rcx      # 0x8290
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0x482d
addq $0x3, %rcx
movq %rcx, 0x8(%rsp)
movq %rcx, %rax
cmpq %rax, 0x10(%rsp)
jae 0x4839
movq %rax, 0x10(%rsp)
pushq $0x7
popq %rdi
leaq 0x8(%rsp), %rsi
callq 0x22b0
testl %eax, %eax
jne 0x4a7e
movl 0x3a44(%rip), %edi      # 0x8298
callq 0x43ec
movl %eax, 0x3a79(%rip)      # 0x82d8
cmpl $-0x1, %eax
je 0x4a93
callq 0x2130
testl %eax, %eax
je 0x487e
callq 0x21a0
testl %eax, %eax
jne 0x4955
movq 0x3a2b(%rip), %rdi      # 0x82b0
testq %rdi, %rdi
je 0x488f
cmpb $0x0, (%rdi)
jne 0x48fc
movq 0x3762(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x1248(%rip), %rdi      # 0x5ae8
pushq $0x2e
popq %rsi
pushq $0x1
popq %rdx
callq 0x23c0
jmp 0x48e5
movq 0x3744(%rip), %rcx      # 0x7ff8
movq (%rcx), %rdi
leaq 0x1158(%rip), %rsi      # 0x5a16
movl %eax, %edx
xorl %eax, %eax
callq 0x2230
jmp 0x48e5
movq 0x3728(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq (%r13), %rdx
leaq 0x1123(%rip), %rsi      # 0x5a01
xorl %eax, %eax
callq 0x2230
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2220
testq %rax, %rax
jne 0x4920
movq 0x36eb(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq 0x3999(%rip), %rdx      # 0x82b0
leaq 0x11f9(%rip), %rsi      # 0x5b17
jmp 0x48de
movq %rax, %rbx
movl 0x14(%rax), %edi
callq 0x2300
testl %eax, %eax
js 0x493b
movl 0x10(%rbx), %edi
callq 0x23e0
testl %eax, %eax
jns 0x4955
movq 0x36b6(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movq 0x3964(%rip), %rdx      # 0x82b0
leaq 0x11e9(%rip), %rsi      # 0x5b3c
jmp 0x48de
callq 0x2d24
movl 0x3934(%rip), %edi      # 0x8294
movl 0x3936(%rip), %esi      # 0x829c
callq 0x2c90
cmpl $-0x1, %eax
jne 0x4988
movq 0x3681(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x11e1(%rip), %rdi      # 0x5b62
pushq $0x29
jmp 0x48a2
callq 0x2400
callq 0x2ddf
movq 0x390f(%rip), %rdi      # 0x82a8
callq 0x2c55
testl %eax, %eax
jne 0x4acb
cmpl $0x0, 0x38f3(%rip)      # 0x82a0
je 0x49b7
pushq $0x3
popq %rdi
callq 0x22d0
leaq 0x28(%rsp), %rdi
movq $0x1, -0x8(%rdi)
andl $0x0, 0x80(%rdi)
callq 0x2240
cmpl $-0x1, %eax
je 0x4abd
pushq $0xd
popq %rdi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x4abd
movl 0x38e1(%rip), %edi      # 0x82d8
xorl %ebx, %ebx
pushq $0x12
popq %rdx
xorl %esi, %esi
callq 0x2e04
testq %rax, %rax
je 0x4aeb
callq 0x20e0
movq 0x38a0(%rip), %rsi      # 0x82b8
movl %eax, %edi
callq 0x4510
movq 0x35d2(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x11cc(%rip), %rdi      # 0x5bfc
pushq $0x12
popq %rsi
pushq $0x1
popq %rdx
callq 0x23c0
xorl %edi, %edi
callq 0x2320
movq 0x386f(%rip), %rdi      # 0x82b8
callq 0x4583
jmp 0x48e8
callq 0x45b3
jmp 0x4a5f
callq 0x4649
xorl %edi, %edi
callq 0x23b0
movq 0x358b(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0xfda(%rip), %rdi       # 0x5a51
pushq $0x24
jmp 0x4afe
movq 0x3573(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0xfe7(%rip), %rdi       # 0x5a76
pushq $0x5f
jmp 0x4afe
movq 0x355e(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x1032(%rip), %rdi      # 0x5ad6
pushq $0x11
jmp 0x4afe
movq 0x3549(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0xf74(%rip), %rdi       # 0x5a2d
pushq $0x23
jmp 0x4afe
leaq 0x10ee(%rip), %rdi      # 0x5bb2
callq 0x2360
jmp 0x4b07
movq 0x3526(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x10b0(%rip), %rdi      # 0x5b8c
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x23c0
pushq $-0x1
jmp 0x4b09
movq 0x3506(%rip), %rax      # 0x7ff8
movq (%rax), %rcx
leaq 0x10da(%rip), %rdi      # 0x5bd6
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x23c0
pushq $0x1
popq %rdi
callq 0x23b0
nop