// File: /workspace/github_c_makefile_star2_O0/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
subq $0x290, %rsp            # imm = 0x290
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl 0x1129(%rip), %eax      # 0xa918
movl %eax, -0x1b(%rbp)
movw 0x1123(%rip), %ax       # 0xa91c
movw %ax, -0x17(%rbp)
movb 0x111b(%rip), %al       # 0xa91e
movb %al, -0x15(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x1, -0x24(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq -0x1b(%rbp), %rdx
callq 0x2320
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x989e
movl -0x14(%rbp), %eax
addl $-0x63, %eax
movl %eax, %ecx
movq %rcx, -0x288(%rbp)
subl $0x11, %eax
ja 0x988d
movq -0x288(%rbp), %rax
leaq 0xa4a(%rip), %rcx       # 0xa298
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x8ca0
xorl %edi, %edi
callq 0x2340
movl $0x1, -0x20(%rbp)
jmp 0x9899
movl $0x0, -0x24(%rbp)
jmp 0x9899
movq 0x475c(%rip), %rax      # 0xdfd8
movq (%rax), %rsi
leaq 0x4e2a(%rip), %rdi      # 0xe6b0
callq 0x2090
jmp 0x9899
callq 0x8ca0
xorl %edi, %edi
callq 0x2340
jmp 0x9814
movsbl 0x4e0b(%rip), %eax      # 0xe6b0
cmpl $0x0, %eax
jne 0x98c4
leaq 0x106e(%rip), %rdi      # 0xa91f
movb $0x0, %al
callq 0x2150
callq 0x8ca0
xorl %edi, %edi
callq 0x2340
cmpl $0x0, -0x20(%rbp)
je 0x9947
leaq -0x280(%rbp), %rdi
xorl %esi, %esi
movl $0x258, %edx            # imm = 0x258
callq 0x2190
leaq -0x280(%rbp), %rdi
addq $0x148, %rdi            # imm = 0x148
leaq 0x4dbe(%rip), %rsi      # 0xe6b0
callq 0x2090
leaq -0x280(%rbp), %rdi
callq 0x7870
leaq -0x280(%rbp), %rdi
xorl %esi, %esi
callq 0x7970
cmpl $0x0, %eax
jne 0x9926
leaq 0x1020(%rip), %rdi      # 0xa93d
movb $0x0, %al
callq 0x2150
jmp 0x9934
leaq 0x1029(%rip), %rdi      # 0xa956
movb $0x0, %al
callq 0x2150
leaq -0x280(%rbp), %rdi
callq 0x78b0
xorl %edi, %edi
callq 0x2340
cmpl $0x0, -0x24(%rbp)
je 0x9954
movb $0x0, %al
callq 0x6670
callq 0x7550
leaq 0x4c08(%rip), %rdi      # 0xe568
callq 0x7870
leaq 0x4bfc(%rip), %rdi      # 0xe568
movl $0x2, %esi
callq 0x7970
cmpl $0x0, %eax
je 0x99a6
leaq 0xfef(%rip), %rdi       # 0xa971
movb $0x0, %al
callq 0x2150
leaq 0x4bd8(%rip), %rdi      # 0xe568
callq 0x78b0
movb $0x0, %al
callq 0x5a20
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2340
cmpl $0x0, -0x24(%rbp)
je 0x9a29
movsbl 0x4bbd(%rip), %eax      # 0xe570
cmpl $0x0, %eax
jne 0x99e5
jmp 0x99ba
leaq 0xfc3(%rip), %rdi       # 0xa984
movb $0x0, %al
callq 0x58a0
leaq 0x4b99(%rip), %rdi      # 0xe568
callq 0x78b0
movb $0x0, %al
callq 0x5a20
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2340
leaq 0x4b7c(%rip), %rdi      # 0xe568
addq $0x8, %rdi
callq 0x69a0
cmpl $0x0, %eax
je 0x9a27
jmp 0x99fc
leaq 0xf95(%rip), %rdi       # 0xa998
movb $0x0, %al
callq 0x58a0
leaq 0x4b57(%rip), %rdi      # 0xe568
callq 0x78b0
movb $0x0, %al
callq 0x5a20
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2340
jmp 0x9a29
callq 0x94b0
leaq 0x4b33(%rip), %rdi      # 0xe568
callq 0x78b0
movb $0x0, %al
callq 0x5a20
xorl %eax, %eax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq