// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rdi, %rbx
leaq -0x2140(%rbp), %r15
movl $0x2000, %edx           # imm = 0x2000
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
leaq 0x1280(%rip), %rdi      # 0x746f
movq %r14, %rsi
xorl %eax, %eax
callq 0x3fa2
pushq $0x7c
popq %rsi
pushq $0x40
popq %rcx
movq %r14, %rdi
movq %r15, %rdx
movl $0x80, %r8d
callq 0x5473
testl %eax, %eax
jle 0x64b1
movl %eax, %r15d
callq 0x30ec
movq %rax, 0xa58(%rbx)
movl %r15d, %eax
movq %rax, -0x38(%rbp)
leaq -0x140(%rbp), %r15
leaq -0xc0(%rbp), %r13
xorl %r12d, %r12d
movq %rbx, -0x30(%rbp)
cmpq -0x38(%rbp), %r12
je 0x64d0
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 %r12, %rax
shlq $0x6, %rax
leaq (%rax,%rbp), %r14
addq $-0x2140, %r14          # imm = 0xDEC0
movq %r14, %rdi
pushq $0x2c
popq %rsi
movq %r15, %rdx
pushq $0x40
popq %rcx
pushq $0x2
popq %r8
callq 0x5473
cmpl $0x2, %eax
jne 0x64c4
movq %r15, %rdi
callq 0x2130
cmpq $0x3, %rax
jne 0x64d4
cmpb $0x2d, -0x13f(%rbp)
jne 0x64d4
movq %r12, -0x40(%rbp)
movq %r15, %rdi
callq 0x2330
movl %eax, %r12d
leaq -0x13e(%rbp), %rdi
callq 0x2330
cmpl $0x7, %eax
jg 0x64dd
cmpl $0x7, %r12d
jg 0x64dd
movl %eax, %r15d
testl %eax, %eax
jle 0x64dd
testl %r12d, %r12d
jle 0x64dd
cmpl %r15d, %r12d
jg 0x64dd
cmpl $0x2, 0xa50(%rbx)
jne 0x6343
leaq -0x100(%rbp), %rdi
callq 0x2330
imull $0x3c, %eax, %r13d
movl %r13d, %r14d
jmp 0x6444
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
pushq $0x2d
popq %rsi
movq %r13, %rdx
pushq $0x40
popq %rcx
pushq $0x2
popq %r8
callq 0x5473
cmpl $0x2, %eax
jne 0x64c4
movq %r13, %rdi
callq 0x2130
cmpq $0x5, %rax
jne 0x64f4
cmpb $0x3a, -0xbe(%rbp)
jne 0x64f4
leaq -0x80(%rbp), %rdi
callq 0x2130
cmpq $0x5, %rax
jne 0x64f4
cmpb $0x3a, -0x7e(%rbp)
jne 0x64f4
movq %r13, %rdi
callq 0x2330
imull $0xe10, %eax, %r14d     # imm = 0xE10
leaq -0xbd(%rbp), %rdi
callq 0x2330
imull $0x3c, %eax, %r13d
addl %r14d, %r13d
leaq -0x80(%rbp), %rdi
callq 0x2330
imull $0xe10, %eax, %ebx      # imm = 0xE10
leaq -0x7d(%rbp), %rdi
callq 0x2330
imull $0x3c, %eax, %r14d
addl %ebx, %r14d
cmpl $0x15180, %r14d         # imm = 0x15180
jg 0x650f
cmpl $0x15180, %r13d         # imm = 0x15180
jg 0x650f
cmpl %r14d, %r13d
jge 0x650f
movl %r14d, %eax
orl %r13d, %eax
js 0x650f
movq -0x30(%rbp), %rbx
leaq 0x10ed(%rip), %rdi      # 0x7538
movl %r12d, %esi
movl %r15d, %edx
movl %r13d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3fa2
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x21f0
movl %r12d, %ecx
movq -0x40(%rbp), %r12
cmpl %ecx, %r15d
jl 0x647e
movb $0x1, (%rax,%rcx)
incq %rcx
jmp 0x6470
movslq %r13d, %rcx
movq %rcx, 0x8(%rax)
movslq %r14d, %rcx
movq %rcx, 0x10(%rax)
movq 0xa58(%rbx), %rdi
movq %rax, %rsi
callq 0x31b7
incq %r12
leaq -0x140(%rbp), %r15
leaq -0xc0(%rbp), %r13
jmp 0x6243
leaq 0xee9(%rip), %rdi       # 0x73a1
movq %r14, %rsi
xorl %eax, %eax
callq 0x43ba
jmp 0x6540
leaq 0xed6(%rip), %rdi       # 0x73a1
movq %r14, %rsi
jmp 0x64eb
xorl %eax, %eax
jmp 0x6543
leaq 0xfa3(%rip), %rdi       # 0x747e
jmp 0x64e4
leaq 0xfbf(%rip), %rdi       # 0x74a3
leaq -0x140(%rbp), %rsi
xorl %eax, %eax
callq 0x43ba
jmp 0x6532
leaq 0xfc8(%rip), %rdi       # 0x74c3
leaq -0xc0(%rbp), %rsi
leaq -0x80(%rbp), %rdx
xorl %eax, %eax
callq 0x43ba
jmp 0x6532
leaq 0xfdf(%rip), %rdi       # 0x74f5
leaq -0xc0(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movl %r13d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x43ba
movq -0x30(%rbp), %rbx
movq 0xa58(%rbx), %rdi
xorl %esi, %esi
callq 0x310a
pushq $-0x1
popq %rax
addq $0x2118, %rsp           # imm = 0x2118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq