// File: /workspace/github_c_makefile_star2_O3/buf1024[P]mysch/mysch.c
// Function: main
int main(int argc, char* argv[])
{
    extern char *optarg;
    int optch;
    char optstring[] = "c:htse";

    int test = 0;
    int daemon = 1;

    //读取命令行参数
    while ((optch = getopt(argc, argv, optstring)) != -1) {
        switch (optch) {
            case 'h':
                usage();
                exit(0);
            case 't':
                test = 1;
                break;
            case 'e':
                daemon = 0;
                break;
            case 'c':
                strcpy(g_info.conf, optarg);
                break;
            default:
                usage();
                exit(0);
        }
    }

    if (g_info.conf[0] == 0) {
        printf("configuration file is empty.\n");
        usage();
        exit(0);
    }

    if(test) {
        sch_info_t testinfo = {0};
        strcpy(testinfo.conf, g_info.conf);
        init_context(&testinfo);
        if(load_conf(&testinfo, LOAD_CONF_TEST) == 0) {
            printf("file syntax is correct.\n");
        }else{
            printf("file syntax is incorrect.\n");
        }
        uninit_context(&testinfo);
        exit(0);
    }

    if(daemon) {
        make_daemon();
    }

    reg_sign();

    init_context(&g_info);

    if(load_conf(&g_info, LOAD_CONF_NONE) != 0) {
        printf("load_conf failed.\n");
        uninit_context(&g_info);
        log_finish();
        exit(-1);
    }

    if(daemon) {
        if(g_info.pid_file[0] == 0) {
            LOG_ERROR("pid file is empty.\n");
            uninit_context(&g_info);
            log_finish();
            exit(-1);
        }
        if (write_pid_file(g_info.pid_file) != 0) {
            LOG_ERROR("write_pid_file failed.\n");
            uninit_context(&g_info);
            log_finish();
            exit(-1);
        }
    }


    mytask();

    uninit_context(&g_info);
    log_finish();

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rsi, %rbx
movl %edi, %r14d
leaq -0x38(%rbp), %r15
movl $0x657374, 0x3(%r15)    # imm = 0x657374
movl $0x74683a63, (%r15)     # imm = 0x74683A63
movl $0x1, -0x30(%rbp)
movb $0x1, %al
movl %eax, -0x2c(%rbp)
movq 0x4d4d(%rip), %r13      # 0xbfd8
leaq 0x541e(%rip), %r12      # 0xc6b0
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2320
cmpl $0x63, %eax
jne 0x72b3
movq (%r13), %rsi
movq %r12, %rdi
callq 0x2090
jmp 0x7292
cmpl $0x67, %eax
jg 0x72cf
cmpl $-0x1, %eax
je 0x72e1
cmpl $0x65, %eax
jne 0x7398
movl $0x0, -0x30(%rbp)
jmp 0x7292
cmpl $0x74, %eax
jne 0x7395
movl $0x0, -0x2c(%rbp)
jmp 0x7292
cmpb $0x0, 0x53c8(%rip)      # 0xc6b0
je 0x73a4
testb $0x1, -0x2c(%rbp)
movl -0x30(%rbp), %r14d
je 0x73b2
testl %r14d, %r14d
je 0x7308
xorl %eax, %eax
callq 0x50a5
callq 0x5b3c
callq 0x3420
movq %rax, 0x5497(%rip)      # 0xc7b0
leaq 0x5248(%rip), %rbx      # 0xc568
xorl %edi, %edi
callq 0x26f7
movq %rax, 0x548a(%rip)      # 0xc7b8
movq %rbx, %rdi
movl $0x2, %esi
callq 0x5d42
testl %eax, %eax
jne 0x742a
testl %r14d, %r14d
je 0x7369
cmpb $0x0, 0x5221(%rip)      # 0xc570
je 0x7438
leaq 0x5214(%rip), %rdi      # 0xc570
callq 0x5297
testl %eax, %eax
jne 0x7441
callq 0x6fec
leaq 0x51f3(%rip), %rdi      # 0xc568
callq 0x5cc9
xorl %eax, %eax
callq 0x4873
xorl %eax, %eax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x68, %eax
callq 0x69d8
xorl %edi, %edi
callq 0x2340
leaq 0x157e(%rip), %rdi      # 0x8929
callq 0x20b0
jmp 0x7398
leaq -0x290(%rbp), %rbx
movl $0x258, %edx            # imm = 0x258
movq %rbx, %rdi
xorl %esi, %esi
callq 0x21a0
movl $0x148, %eax            # imm = 0x148
leaq (%rbx,%rax), %rdi
leaq 0x5190(%rip), %rsi      # 0xc568
addq %rax, %rsi
callq 0x2090
callq 0x3420
movq %rax, 0x248(%rbx)
xorl %edi, %edi
callq 0x26f7
movq %rax, 0x250(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5d42
testl %eax, %eax
leaq 0x1504(%rip), %rax      # 0x8911
leaq 0x14e3(%rip), %rdi      # 0x88f7
cmoveq %rax, %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x5cc9
jmp 0x739d
leaq 0x14b4(%rip), %rdi      # 0x88e5
callq 0x20b0
jmp 0x744f
leaq 0x12ec(%rip), %rdi      # 0x872b
jmp 0x7448
leaq 0x12f7(%rip), %rdi      # 0x873f
xorl %eax, %eax
callq 0x471f
leaq 0x5112(%rip), %rdi      # 0xc568
callq 0x5cc9
xorl %eax, %eax
callq 0x4873
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2340