// File: /workspace/github_c_makefile_star2_O1/buf1024[P]mysch/mysch.c
// Function: build_condition
int build_condition(prog_t* prog, const char* cond)
{
    char daytimes[128][64] = { { 0 } };
    int num = 0;

    LOG_DEBUG("condition: %s\n", cond);
    num = split(cond, '|', (char **) daytimes, 64, 128);
    if (num <= 0) {
        LOG_ERROR("split %s failed.\n", cond);
        return -1;
    }

    prog->cond = list_create();

    int fail = 0;
    int i = 0;
    for (i = 0; i < num; i++) {
        char daytime[2][64] = { { 0 } };
        int dtnum = 0;

        dtnum = split(daytimes[i], ',', (char**)daytime, 64, 2);
        if(dtnum != 2) {
            LOG_ERROR("split %s failed.\n", daytimes[i]);
            fail = 1;
            break;
        }

        if(strlen(daytime[0]) != 3 || daytime[0][1] != '-') {
            LOG_ERROR("day time format not ritht: day = %s\n", daytime[0]);
            fail = 1;
            break;
        }
        int d_start = atoi(daytime[0]);
        int d_end = atoi(daytime[0] + 2);

        if(d_start > d_end || d_start <= 0 || d_end <= 0 ||
                d_start > 7 || d_end > 7) {
            LOG_ERROR("day format not ritht: day = %s\n", daytime[0]);
            fail = 1;
            break;
        }

        int t_start, t_end;
		if (prog->flag != FORK_PERIOD) {
			char times[2][64] = { { 0 } };
			int tnum = 0;
			tnum = split(daytime[1], '-', (char**) times, 64, 2);
			if (tnum != 2) {
				LOG_ERROR("split %s failed.\n", daytimes[i]);
				fail = 1;
				break;
			}
			if (strlen(times[0]) != 5 || times[0][2] != ':'
					|| strlen(times[1]) != 5 || times[1][2] != ':') {
				LOG_ERROR("time split format not ritht. time1=%s, times2=%s\n",
						times[0], times[1]);
				fail = 1;
				break;
			}

			t_start = atoi(times[0]) * 3600 + atoi(times[0] + 3) * 60;
			t_end = atoi(times[1]) * 3600 + atoi(times[1] + 3) * 60;

			if (t_start >= t_end || t_start < 0 || t_end < 0 || t_start > 86400
					|| t_end > 86400) {
				LOG_ERROR(
						"time data format not ritht. time1=%s, times2=%s, start=%d, end=%d\n",
						times[0], times[1], t_start, t_end);
				fail = 1;
				break;
			}

		}else{
			t_start = atoi(daytime[1]) * 60;
			t_end = t_start;
		}

        LOG_DEBUG("condition: daystart=%d, dayend=%d, timestart=%d, timeend=%d\n",
                d_start, d_end, t_start, t_end);

        cond_t* c = (cond_t*)malloc(sizeof(*c));
        memset(c, 0, sizeof(*c));

        int i = 0;
        for(i=d_start; i<=d_end; i++) {
            c->day[i] = 1;
        }
        c->start = t_start;
        c->end = t_end;

        list_add_node_tail(prog->cond, c);
    }

    if(fail) {
        list_release(prog->cond, AL_FREE);
        return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2118, %rsp           # imm = 0x2118
movq %rsi, %rbx
movq %rdi, %r12
leaq -0x2140(%rbp), %r14
movl $0x2000, %edx           # imm = 0x2000
movq %r14, %rdi
xorl %esi, %esi
callq 0x21a0
leaq 0x1c36(%rip), %rdi      # 0x848d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4433
movq %rbx, %rdi
movl $0x7c, %esi
movq %r14, %rdx
movl $0x40, %ecx
movl $0x80, %r8d
callq 0x595a
testl %eax, %eax
jle 0x6bee
movl %eax, %r15d
callq 0x3454
movq %r12, -0x40(%rbp)
movq %rax, 0xa58(%r12)
movl %r15d, %r13d
decq %r13
leaq -0x140(%rbp), %r12
movl $0x0, -0x30(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xd0(%rbp)
movaps %xmm0, -0xe0(%rbp)
movaps %xmm0, -0xf0(%rbp)
movaps %xmm0, -0x100(%rbp)
movaps %xmm0, -0x110(%rbp)
movaps %xmm0, -0x120(%rbp)
movaps %xmm0, -0x130(%rbp)
movaps %xmm0, -0x140(%rbp)
movq %r14, %rdi
movl $0x2c, %esi
movq %r12, %rdx
movl $0x40, %ecx
movl $0x2, %r8d
callq 0x595a
cmpl $0x2, %eax
jne 0x6975
movq %r12, %rdi
callq 0x2130
cmpq $0x3, %rax
jne 0x6981
cmpb $0x2d, -0x13f(%rbp)
jne 0x6981
movq %r12, %rdi
callq 0x2330
movl %eax, %ebx
leaq -0x13e(%rbp), %rdi
callq 0x2330
cmpl $0x7, %eax
jg 0x698a
cmpl $0x7, %ebx
jg 0x698a
movl %eax, %r15d
testl %eax, %eax
jle 0x698a
testl %ebx, %ebx
jle 0x698a
cmpl %ebx, %r15d
jl 0x698a
movq -0x40(%rbp), %rax
cmpl $0x2, 0xa50(%rax)
jne 0x69c7
leaq -0x100(%rbp), %rdi
callq 0x2330
imull $0x3c, %eax, %eax
movl %eax, -0x34(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x6b2d
leaq 0x1a43(%rip), %rdi      # 0x83bf
movq %r14, %rsi
jmp 0x6994
leaq 0x1b14(%rip), %rdi      # 0x849c
jmp 0x6991
leaq 0x1b30(%rip), %rdi      # 0x84c1
movq %r12, %rsi
xorl %eax, %eax
callq 0x4838
movl $0x6, %eax
movl $0x1, -0x30(%rbp)
subq $0x1, %r13
setb %cl
testl %eax, %eax
jne 0x6bd4
addq $0x40, %r14
testb %cl, %cl
je 0x68ac
jmp 0x6bd4
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
leaq -0x100(%rbp), %rdi
movl $0x2d, %esi
leaq -0xc0(%rbp), %r12
movq %r12, %rdx
movl $0x40, %ecx
movl $0x2, %r8d
callq 0x595a
cmpl $0x2, %eax
jne 0x6ae3
movq %r12, %rdi
callq 0x2130
cmpq $0x5, %rax
jne 0x6af9
cmpb $0x3a, -0xbe(%rbp)
jne 0x6af9
leaq -0x80(%rbp), %rdi
callq 0x2130
cmpq $0x5, %rax
jne 0x6af9
cmpb $0x3a, -0x7e(%rbp)
jne 0x6af9
movq %r12, %rdi
callq 0x2330
imull $0xe10, %eax, %eax      # imm = 0xE10
movl %eax, -0x2c(%rbp)
leaq -0xbd(%rbp), %rdi
callq 0x2330
imull $0x3c, %eax, %r12d
addl -0x2c(%rbp), %r12d
leaq -0x80(%rbp), %rdi
callq 0x2330
imull $0xe10, %eax, %eax      # imm = 0xE10
movl %eax, -0x2c(%rbp)
leaq -0x7d(%rbp), %rdi
callq 0x2330
movl %r12d, %ecx
imull $0x3c, %eax, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x15180, %eax          # imm = 0x15180
movl %r12d, -0x34(%rbp)
jg 0x6baf
cmpl $0x15180, %ecx          # imm = 0x15180
jg 0x6baf
cmpl -0x2c(%rbp), %ecx
jge 0x6baf
movl -0x2c(%rbp), %eax
orl %ecx, %eax
js 0x6baf
xorl %eax, %eax
movb $0x1, %r12b
jmp 0x6b1d
xorl %r12d, %r12d
leaq 0x18d2(%rip), %rdi      # 0x83bf
movq %r14, %rsi
xorl %eax, %eax
callq 0x4838
jmp 0x6b11
movq %r12, %rsi
xorl %r12d, %r12d
leaq 0x19db(%rip), %rdi      # 0x84e1
leaq -0x80(%rbp), %rdx
xorl %eax, %eax
callq 0x4838
movl $0x6, %eax
movl $0x1, -0x30(%rbp)
testb %r12b, %r12b
leaq -0x140(%rbp), %r12
je 0x69a7
leaq 0x1a22(%rip), %rdi      # 0x8556
movl %ebx, %esi
movl %r15d, %edx
movl -0x34(%rbp), %ecx
movl -0x2c(%rbp), %r8d
xorl %eax, %eax
callq 0x4433
movl $0x18, %edi
callq 0x22a0
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
subl %ebx, %r15d
jl 0x6b7c
movl %ebx, %edi
addq %r12, %rdi
incq %r15
movl $0x1, %esi
movq %r15, %rdx
callq 0x21a0
movslq -0x34(%rbp), %rax
movq %rax, 0x8(%r12)
movslq -0x2c(%rbp), %rax
movq %rax, 0x10(%r12)
movq -0x40(%rbp), %rax
movq 0xa58(%rax), %rdi
movq %r12, %rsi
callq 0x3535
xorl %eax, %eax
leaq -0x140(%rbp), %r12
jmp 0x69a7
xorl %r12d, %r12d
leaq 0x195a(%rip), %rdi      # 0x8513
leaq -0xc0(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movl -0x2c(%rbp), %r8d
xorl %eax, %eax
callq 0x4838
jmp 0x6b11
cmpl $0x0, -0x30(%rbp)
je 0x6c06
movq -0x40(%rbp), %rax
movq 0xa58(%rax), %rdi
xorl %esi, %esi
callq 0x347b
jmp 0x6bff
leaq 0x17ca(%rip), %rdi      # 0x83bf
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4838
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x6c08
xorl %eax, %eax
addq $0x2118, %rsp           # imm = 0x2118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq