// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rax
movl %eax, -0x30(%rbp)
movb $0x1, %al
movl %eax, -0x2c(%rbp)
movq 0x4241(%rip), %r13      # 0xafd8
leaq 0x4912(%rip), %r12      # 0xb6b0
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2320
cmpl $0x63, %eax
jne 0x6dbf
movq (%r13), %rsi
movq %r12, %rdi
callq 0x2090
jmp 0x6d9e
cmpl $-0x1, %eax
je 0x6de4
cmpl $0x65, %eax
je 0x6ddb
cmpl $0x74, %eax
jne 0x6e84
movl $0x0, -0x2c(%rbp)
jmp 0x6d9e
movl $0x0, -0x30(%rbp)
jmp 0x6d9e
cmpb $0x0, 0x48c5(%rip)      # 0xb6b0
je 0x6e93
testb $0x1, -0x2c(%rbp)
movl -0x30(%rbp), %r14d
je 0x6ea1
testl %r14d, %r14d
je 0x6e0b
xorl %eax, %eax
callq 0x4d75
callq 0x5748
leaq 0x4751(%rip), %rbx      # 0xb568
movq %rbx, %rdi
callq 0x5875
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x5917
testl %eax, %eax
jne 0x6f04
testl %r14d, %r14d
je 0x6e58
cmpb $0x0, 0x4732(%rip)      # 0xb570
je 0x6f12
leaq 0x4725(%rip), %rdi      # 0xb570
callq 0x4f77
testl %eax, %eax
jne 0x6f1b
callq 0x6b02
leaq 0x4704(%rip), %rdi      # 0xb568
callq 0x58a1
xorl %eax, %eax
callq 0x450e
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 0x6555
xorl %edi, %edi
callq 0x2340
leaq 0xa8f(%rip), %rdi       # 0x7929
callq 0x20b0
jmp 0x6e87
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 0x46a1(%rip), %rsi      # 0xb568
addq %rax, %rsi
callq 0x2090
movq %rbx, %rdi
callq 0x5875
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5917
testl %eax, %eax
leaq 0xa27(%rip), %rax       # 0x7911
leaq 0xa06(%rip), %rdi       # 0x78f7
cmoveq %rax, %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x58a1
jmp 0x6e8c
leaq 0x9da(%rip), %rdi       # 0x78e5
callq 0x20b0
jmp 0x6f29
leaq 0x812(%rip), %rdi       # 0x772b
jmp 0x6f22
leaq 0x81d(%rip), %rdi       # 0x773f
xorl %eax, %eax
callq 0x43ba
leaq 0x4638(%rip), %rdi      # 0xb568
callq 0x58a1
xorl %eax, %eax
callq 0x450e
pushq $-0x1
popq %rdi
callq 0x2340