// File: /workspace/github_c_makefile_star2_O3/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 $0x2128, %rsp           # imm = 0x2128
movq %rsi, %rbx
movq %rdi, %r15
leaq -0x2150(%rbp), %r12
movl $0x2000, %edx           # imm = 0x2000
movq %r12, %rdi
xorl %esi, %esi
callq 0x21a0
leaq 0x1e40(%rip), %rdi      # 0x846f
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4316
movq %rbx, %rdi
movl $0x7c, %esi
movq %r12, %rdx
movl $0x40, %ecx
movl $0x80, %r8d
callq 0x582e
testl %eax, %eax
jle 0x6914
movl %eax, %r14d
callq 0x3420
movq %rax, 0xa58(%r15)
movl %r14d, %r14d
leaq -0x150(%rbp), %r13
movq %r15, %rbx
movq %r15, -0x38(%rbp)
xorps %xmm0, %xmm0
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)
movaps %xmm0, -0x150(%rbp)
movq %r12, %rdi
movl $0x2c, %esi
movq %r13, %rdx
movl $0x40, %ecx
movl $0x2, %r8d
callq 0x582e
cmpl $0x2, %eax
jne 0x692a
movq %r13, %rdi
callq 0x2130
cmpq $0x3, %rax
jne 0x6936
cmpb $0x2d, -0x14f(%rbp)
jne 0x6936
movq %r12, -0x40(%rbp)
movq %r13, %rdi
callq 0x2330
movl %eax, %r12d
leaq -0x14e(%rbp), %rdi
callq 0x2330
cmpl $0x7, %eax
jg 0x693f
cmpl $0x7, %r12d
jg 0x693f
movl %eax, %r15d
testl %eax, %eax
jle 0x693f
testl %r12d, %r12d
jle 0x693f
movl %r15d, %r13d
subl %r12d, %r13d
jl 0x693f
cmpl $0x2, 0xa50(%rbx)
movq %r14, -0x48(%rbp)
jne 0x676d
leaq -0x110(%rbp), %rdi
callq 0x2330
imull $0x3c, %eax, %r14d
movl %r14d, %ebx
jmp 0x6889
xorps %xmm0, %xmm0
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)
movaps %xmm0, -0xd0(%rbp)
leaq -0x110(%rbp), %rdi
movl $0x2d, %esi
leaq -0xd0(%rbp), %r14
movq %r14, %rdx
movl $0x40, %ecx
movl $0x2, %r8d
callq 0x582e
cmpl $0x2, %eax
jne 0x6974
movq %r14, %rdi
callq 0x2130
cmpq $0x5, %rax
jne 0x6956
cmpb $0x3a, -0xce(%rbp)
jne 0x6956
leaq -0x90(%rbp), %rdi
callq 0x2130
cmpq $0x5, %rax
jne 0x6956
cmpb $0x3a, -0x8e(%rbp)
jne 0x6956
leaq -0xd0(%rbp), %rdi
callq 0x2330
imull $0xe10, %eax, %ebx      # imm = 0xE10
leaq -0xcd(%rbp), %rdi
callq 0x2330
imull $0x3c, %eax, %r14d
addl %ebx, %r14d
leaq -0x90(%rbp), %rdi
callq 0x2330
imull $0xe10, %eax, %eax      # imm = 0xE10
movl %eax, -0x2c(%rbp)
leaq -0x8d(%rbp), %rdi
callq 0x2330
imull $0x3c, %eax, %ebx
addl -0x2c(%rbp), %ebx
cmpl $0x15180, %ebx          # imm = 0x15180
jg 0x6988
cmpl $0x15180, %r14d         # imm = 0x15180
jg 0x6988
cmpl %ebx, %r14d
jge 0x6988
movl %ebx, %eax
orl %r14d, %eax
js 0x6988
movl $0x0, -0x2c(%rbp)
leaq 0x1ca1(%rip), %rdi      # 0x8538
movl %r12d, %esi
movl %r15d, %edx
movl %r14d, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x4316
movl $0x1, %edi
movl $0x18, %esi
callq 0x21f0
movq %rax, %r15
movl %r12d, %edi
addq %rax, %rdi
incq %r13
movl $0x1, %esi
movq %r13, %rdx
callq 0x21a0
movslq %r14d, %rax
movq %rax, 0x8(%r15)
movslq %ebx, %rax
movq %rax, 0x10(%r15)
movq -0x38(%rbp), %rbx
movq 0xa58(%rbx), %rdi
movq %r15, %rsi
callq 0x34ee
movq -0x40(%rbp), %r12
addq $0x40, %r12
movq -0x48(%rbp), %r14
decq %r14
leaq -0x150(%rbp), %r13
jne 0x667c
jmp 0x69c3
leaq 0x1a86(%rip), %rdi      # 0x83a1
movq %rbx, %rsi
xorl %eax, %eax
callq 0x471f
jmp 0x69bc
leaq 0x1a70(%rip), %rdi      # 0x83a1
movq %r12, %rsi
jmp 0x694d
leaq 0x1b41(%rip), %rdi      # 0x847e
jmp 0x6946
leaq 0x1b5d(%rip), %rdi      # 0x84a3
leaq -0x150(%rbp), %rsi
xorl %eax, %eax
callq 0x471f
jmp 0x69ae
leaq 0x1b66(%rip), %rdi      # 0x84c3
leaq -0xd0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
xorl %eax, %eax
callq 0x471f
jmp 0x69aa
leaq 0x1a26(%rip), %rdi      # 0x83a1
movq -0x40(%rbp), %rsi
xorl %eax, %eax
callq 0x471f
jmp 0x69aa
leaq 0x1b66(%rip), %rdi      # 0x84f5
leaq -0xd0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
movl %r14d, %ecx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x471f
movq -0x38(%rbp), %rbx
movq 0xa58(%rbx), %rdi
xorl %esi, %esi
callq 0x3434
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movl -0x2c(%rbp), %eax
addq $0x2128, %rsp           # imm = 0x2128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq