// File: /workspace/github_c_makefile_star2_O1/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 0x4b16(%rip), %r13      # 0xbfd8
leaq 0x51e7(%rip), %r12      # 0xc6b0
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2320
cmpl $0x63, %eax
jne 0x74ea
movq (%r13), %rsi
movq %r12, %rdi
callq 0x2090
jmp 0x74c9
cmpl $0x67, %eax
jg 0x7506
cmpl $-0x1, %eax
je 0x7518
cmpl $0x65, %eax
jne 0x75cf
movl $0x0, -0x30(%rbp)
jmp 0x74c9
cmpl $0x74, %eax
jne 0x75cc
movl $0x0, -0x2c(%rbp)
jmp 0x74c9
cmpb $0x0, 0x5191(%rip)      # 0xc6b0
je 0x75db
testb $0x1, -0x2c(%rbp)
movl -0x30(%rbp), %r14d
je 0x75e9
testl %r14d, %r14d
je 0x753f
xorl %eax, %eax
callq 0x51c9
callq 0x5c80
callq 0x3454
movq %rax, 0x5260(%rip)      # 0xc7b0
leaq 0x5011(%rip), %rbx      # 0xc568
xorl %edi, %edi
callq 0x26f7
movq %rax, 0x5253(%rip)      # 0xc7b8
movq %rbx, %rdi
movl $0x2, %esi
callq 0x5e86
testl %eax, %eax
jne 0x7661
testl %r14d, %r14d
je 0x75a0
cmpb $0x0, 0x4fea(%rip)      # 0xc570
je 0x766f
leaq 0x4fdd(%rip), %rdi      # 0xc570
callq 0x53bc
testl %eax, %eax
jne 0x7678
callq 0x7225
leaq 0x4fbc(%rip), %rdi      # 0xc568
callq 0x5e0d
xorl %eax, %eax
callq 0x498c
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 0x6c1a
xorl %edi, %edi
callq 0x2340
leaq 0x1365(%rip), %rdi      # 0x8947
callq 0x20b0
jmp 0x75cf
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 0x4f59(%rip), %rsi      # 0xc568
addq %rax, %rsi
callq 0x2090
callq 0x3454
movq %rax, 0x248(%rbx)
xorl %edi, %edi
callq 0x26f7
movq %rax, 0x250(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5e86
testl %eax, %eax
leaq 0x12eb(%rip), %rax      # 0x892f
leaq 0x12ca(%rip), %rdi      # 0x8915
cmoveq %rax, %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x5e0d
jmp 0x75d4
leaq 0x129b(%rip), %rdi      # 0x8903
callq 0x20b0
jmp 0x7686
leaq 0x10d3(%rip), %rdi      # 0x8749
jmp 0x767f
leaq 0x10de(%rip), %rdi      # 0x875d
xorl %eax, %eax
callq 0x4838
leaq 0x4edb(%rip), %rdi      # 0xc568
callq 0x5e0d
xorl %eax, %eax
callq 0x498c
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2340