// File: /workspace/github_c_makefile_star2_O3/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 0x176d(%rip), %xmm0     # 0x6240
movdqa %xmm0, 0x47b5(%rip)     # 0x9290
movq $0x40000000, 0x47c2(%rip) # imm = 0x40000000
xorl %eax, %eax
movl %eax, 0x47b2(%rip)      # 0x92a0
pxor %xmm0, %xmm0
movdqa %xmm0, 0x47b6(%rip)     # 0x92b0
movl %eax, 0x47c0(%rip)      # 0x92c0
movq 0x44f1(%rip), %rax      # 0x8ff8
movq (%rax), %rdi
xorl %esi, %esi
callq 0x2140
leaq 0x1ed6(%rip), %r14      # 0x69ee
movq 0x44b9(%rip), %r13      # 0x8fd8
leaq 0x174e(%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 0x4b5a
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movq (%r13), %rdi
callq 0x2390
movl %eax, 0x4738(%rip)      # 0x9290
jmp 0x4b2b
cmpl $0x50, %eax
jne 0x4bf7
movq (%r13), %rax
movq %rax, 0x474a(%rip)      # 0x92b8
jmp 0x4b2b
movq (%r13), %rdi
callq 0x2390
cltq
shlq $0x14, %rax
movq %rax, 0x4722(%rip)      # 0x92a8
jmp 0x4b2b
movl $0x1, 0x4702(%rip)      # 0x9294
jmp 0x4b2b
movl $0x1, 0x4702(%rip)      # 0x92a0
jmp 0x4b2b
movq (%r13), %rdi
callq 0x2390
movl %eax, 0x46e9(%rip)      # 0x9298
jmp 0x4b2b
movq (%r13), %rsi
movl $0x2, %edi
movq %r15, %rdx
callq 0x2250
testl %eax, %eax
je 0x4d30
movl 0x1c(%rsp), %eax
movl %eax, 0x46e9(%rip)      # 0x92c0
jmp 0x4b2b
incl 0x46ba(%rip)            # 0x929c
jmp 0x4b2b
movq (%r13), %rax
movq %rax, 0x46be(%rip)      # 0x92b0
jmp 0x4b2b
cmpl $-0x1, %eax
jne 0x4d14
cmpl $0x0, 0x468d(%rip)      # 0x9294
je 0x4c75
leaq 0x8(%rsp), %rsi
movl $0x4, %edi
callq 0x23d0
testl %eax, %eax
jne 0x4c52
pcmpeqd %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movdqa %xmm0, (%rsi)
movl $0x4, %edi
callq 0x22b0
testl %eax, %eax
je 0x4c52
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 0x4eaa
cmpq $0x0, 0x8(%rsp)
je 0x4eaa
leaq 0x8(%rsp), %rsi
movl $0x7, %edi
callq 0x23d0
testl %eax, %eax
jne 0x4e9b
movslq 0x45fd(%rip), %rcx      # 0x9290
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0x4ca9
addq $0x3, %rcx
movq %rcx, 0x8(%rsp)
movq %rcx, %rax
cmpq %rax, 0x10(%rsp)
jae 0x4cb5
movq %rax, 0x10(%rsp)
leaq 0x8(%rsp), %rsi
movl $0x7, %edi
callq 0x22b0
testl %eax, %eax
jne 0x4ea0
movl 0x45c6(%rip), %edi      # 0x9298
callq 0x481c
movl %eax, 0x45fb(%rip)      # 0x92d8
cmpl $-0x1, %eax
je 0x4ea5
callq 0x2130
testl %eax, %eax
je 0x4cfc
callq 0x21a0
testl %eax, %eax
jne 0x4d81
movq 0x45ad(%rip), %rdi      # 0x92b0
testq %rdi, %rdi
je 0x4d0d
cmpb $0x0, (%rdi)
jne 0x4d4e
callq 0x276d
jmp 0x4d35
movq 0x42dd(%rip), %rcx      # 0x8ff8
movq (%rcx), %rdi
leaq 0x1cf1(%rip), %rsi      # 0x6a16
movl %eax, %edx
xorl %eax, %eax
callq 0x2230
jmp 0x4d35
callq 0x25c3
movl $0x1, %ebx
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 0x4d5f
callq 0x2748
jmp 0x4d35
movq %rax, %rbx
movl 0x14(%rax), %edi
callq 0x2300
testl %eax, %eax
js 0x4d7a
movl 0x10(%rbx), %edi
callq 0x23e0
testl %eax, %eax
jns 0x4d81
callq 0x2723
jmp 0x4d35
movl $0x0, 0x44c5(%rip)      # 0x9250
xorl %eax, %eax
movq %rax, 0x44b4(%rip)      # 0x9248
pxor %xmm0, %xmm0
movdqu %xmm0, 0x44b8(%rip)     # 0x9258
movq %rax, 0x44c1(%rip)      # 0x9268
movdqu %xmm0, 0x44c9(%rip)     # 0x9278
xorl %edi, %edi
callq 0x2270
movq %rax, 0x44b3(%rip)      # 0x9270
movl 0x44d1(%rip), %edi      # 0x9294
movl 0x44d3(%rip), %esi      # 0x929c
callq 0x3058
cmpl $-0x1, %eax
jne 0x4ddd
callq 0x2701
jmp 0x4d35
callq 0x2400
movl $0xc8, 0x44dc(%rip)     # 0x92c8
movl $0x0, 0x44d6(%rip)      # 0x92cc
movl $0x640, %edi            # imm = 0x640
callq 0x2280
movq %rax, 0x44c9(%rip)      # 0x92d0
movq 0x449a(%rip), %rdi      # 0x92a8
callq 0x301c
testl %eax, %eax
jne 0x4eb4
cmpl $0x0, 0x447e(%rip)      # 0x92a0
je 0x4e2e
movl $0x3, %edi
callq 0x22d0
leaq 0x28(%rsp), %rdi
movq $0x1, -0x8(%rdi)
movl $0x0, 0x80(%rdi)
callq 0x2240
cmpl $-0x1, %eax
je 0x4eaf
leaq 0x20(%rsp), %rsi
movl $0xd, %edi
xorl %edx, %edx
callq 0x20a0
cmpl $-0x1, %eax
je 0x4eaf
movl 0x446d(%rip), %edi      # 0x92d8
xorl %ebx, %ebx
xorl %esi, %esi
movl $0x12, %edx
callq 0x31e6
testq %rax, %rax
je 0x4eb9
callq 0x267f
jmp 0x4d3a
callq 0x49f3
jmp 0x4e94
callq 0x4a89
xorl %edi, %edi
callq 0x23b0
callq 0x2610
callq 0x2635
callq 0x278f
callq 0x25eb
callq 0x26ec
callq 0x265a
callq 0x26c7
nop