// File: /workspace/github_cpp_makefile_star2_O2/Eba-M[P]E3DC-Control/Waermepumpe.cpp
// Function: bwwptasmota(std::vector<watt_s, std::allocator<watt_s>>&, e3dc_config_t&, int, int, int)
void bwwptasmota(std::vector<watt_s> &w,e3dc_config_t &e3dc,int sunrise, int sunset,int ireq_Heistab)

{
    if (debug)
        printf("BT1");
    static std::vector<ch_s> ch;
    static ch_s cc;
    static int dauer = -1;
    time(&rawtime);
    
    if (ireq_Heistab>500)
    {
        ontime = rawtime;
        if (Tasmotastatus <= 0)
            tasmotaon1(e3dc);
    }
    if (rawtime%(24*3600)/60>sunrise&&rawtime%(24*3600)/60<sunset) 
        status = 0;
    if ((rawtime%(24*3600)/60>sunset||rawtime%(24*3600)/60<sunrise)&&(status<1||e3dc.BWWPTasmotaDauer!=dauer)) // wechsel tag/nacht
    {
        status = 1;
        dauer = e3dc.BWWPTasmotaDauer;
        ch.clear();
        int stunden = ((sunrise+24*60)-sunset)/60;
        for(int j=0;j<w.size()&&ch.size()<stunden;j++)
        {
            cc.hh = w[j].hh;
            cc.pp = w[j].pp;
            int min = cc.hh%(24*3600)/60;
            if ((min>sunset||min<sunrise)&&cc.hh%3600==0)
                ch.push_back(cc);
        }
        std::sort(ch.begin(), ch.end(), [](const ch_s& a, const ch_s& b) {
            return a.pp < b.pp;});
        while (ch.size()>e3dc.BWWPTasmotaDauer)
        {
            ch.erase(ch.end()-1);
        }
        std::sort(ch.begin(), ch.end(), [](const ch_s& a, const ch_s& b) {
            return a.hh < b.hh;});
        
    }
    
    if (ch.size() > 0)
    {
        
        if (ch[0].hh+3600 < rawtime)
        {
            ch.erase(ch.begin());
            if (ch.size() == 0&&Tasmotastatus > 0)
                tasmotaoff1(e3dc);
            return;
        }
        if (ch[0].hh <= rawtime&&Tasmotastatus <= 0)
        {
            tasmotaon1(e3dc);
        }
    }
    if ((ch.size() == 0||ch[0].hh > rawtime)&&Tasmotastatus > 0&&((rawtime-ontime)>600))
    {
        tasmotaoff1(e3dc);
    }
    if (ch.size() > 0)
        printf("Tasmo %i",(ch[0].hh%(24*3600)/3600));
    else
        printf("Tasmo %i",(rawtime-ontime));

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %r12d
movl %ecx, 0xc(%rsp)
movl %edx, 0x8(%rsp)
movq %rsi, %rbp
movq %rdi, %r15
cmpb $0x1, 0x2471d(%rip)     # 0x42020
jne 0x1d913
leaq 0xf71f(%rip), %rdi      # 0x2d02b
xorl %eax, %eax
callq 0x2040
movb 0x24727(%rip), %al      # 0x42040
testb %al, %al
je 0x1dd46
leaq 0x246f0(%rip), %rdi     # 0x42018
callq 0x2250
movq 0x246e4(%rip), %rax     # 0x42018
cmpl $0x1f5, %r12d           # imm = 0x1F5
jl 0x1d972
movq %rax, 0x24714(%rip)     # 0x42058
cmpl $0x0, 0x18a3d(%rip)     # 0x36388
movl 0xc(%rsp), %r8d
movl 0x8(%rsp), %r9d
jg 0x1d97c
movq %rbp, %rdi
callq 0x1d840
movl 0x8(%rsp), %r9d
movl 0xc(%rsp), %r8d
movq 0x246a8(%rip), %rax     # 0x42018
jmp 0x1d97c
movl 0xc(%rsp), %r8d
movl 0x8(%rsp), %r9d
movl $0x15180, %ecx          # imm = 0x15180
cqto
idivq %rcx
movq %rdx, %rax
pushq $0x3c
popq %r10
cltd
idivl %r10d
cmpl %r9d, %eax
setle %cl
cmpl %r8d, %eax
setge %dl
orb %cl, %dl
jne 0x1d9a8
andl $0x0, 0x189e8(%rip)     # 0x36390
cmpl %r8d, %eax
setle %cl
cmpl %r9d, %eax
setge %al
testb %al, %cl
jne 0x1dc09
cmpl $0x0, 0x189cd(%rip)     # 0x36390
movss 0x654(%rbp), %xmm0
jle 0x1d9e0
cvtsi2ssl 0x189b7(%rip), %xmm1 # 0x3638c
ucomiss %xmm1, %xmm0
jne 0x1d9e0
jnp 0x1dc09
movq %rbp, 0x10(%rsp)
movl $0x1, 0x189a1(%rip)     # 0x36390
cvttss2si %xmm0, %eax
movl %eax, 0x18993(%rip)     # 0x3638c
movq 0x24628(%rip), %r13     # 0x42028
movq 0x24629(%rip), %r12     # 0x42030
cmpq %r13, %r12
je 0x1da16
movq %r13, 0x2461d(%rip)     # 0x42030
movq %r13, %r12
movl %r9d, %eax
subl %r8d, %eax
addl $0x5a0, %eax            # imm = 0x5A0
cltd
idivl %r10d
movslq %eax, %rbx
pushq $0x8
popq %rbp
xorl %r14d, %r14d
pushq $0x18
popq %r11
movq (%r15), %rsi
movq 0x8(%r15), %rax
subq %rsi, %rax
cqto
idivq %r11
cmpq %r14, %rax
jbe 0x1daf2
movq %r12, %rax
subq %r13, %rax
sarq $0x4, %rax
cmpq %rbx, %rax
jae 0x1daf2
movq -0x8(%rsi,%rbp), %rcx
movq %rcx, 0x245df(%rip)     # 0x42048
movss (%rsi,%rbp), %xmm0
movss %xmm0, 0x245de(%rip)    # 0x42054
movq %rcx, %rax
cqto
movl $0x15180, %esi          # imm = 0x15180
idivq %rsi
movq %rdx, %rax
cltd
idivl %r10d
cmpl %r8d, %eax
setg %sil
cmpl %r9d, %eax
setl %dil
movq %rcx, %rax
cqto
movl $0xe10, %ecx            # imm = 0xE10
idivq %rcx
testq %rdx, %rdx
jne 0x1dae6
orb %dil, %sil
je 0x1dae6
leaq 0x24572(%rip), %rdi     # 0x42028
leaq 0x2458b(%rip), %rsi     # 0x42048
movl %r10d, %r12d
movq %r11, %r13
callq 0x2055c
movq %r13, %r11
movl %r12d, %r10d
movl 0x8(%rsp), %r9d
movl 0xc(%rsp), %r8d
movq 0x24549(%rip), %r13     # 0x42028
movq 0x2454a(%rip), %r12     # 0x42030
incq %r14
addq $0x18, %rbp
jmp 0x1da32
cmpq %r12, %r13
movq 0x10(%rsp), %rbp
je 0x1db6f
movq %r12, %rbx
subq %r13, %rbx
movq %rbx, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x1f5b5
cmpq $0x101, %rbx            # imm = 0x101
jl 0x1db4f
leaq 0x100(%r13), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x1f84a
cmpq %r12, %r14
je 0x1db6f
movq %r14, %rdi
callq 0x1f8bf
addq $0x10, %r14
jmp 0x1db3c
movq %r13, %rdi
movq %r12, %rsi
callq 0x1f84a
jmp 0x1db6f
addq $-0x10, %r14
leaq 0x244c1(%rip), %rdi     # 0x42028
movq %r14, %rsi
callq 0x2057a
movq 0x244ba(%rip), %r14     # 0x42030
movq 0x244ab(%rip), %r15     # 0x42028
movq %r14, %rbx
subq %r15, %rbx
movq %rbx, %rax
sarq $0x4, %rax
js 0x1db93
cvtsi2ss %rax, %xmm0
jmp 0x1dbaa
movq %rax, %rcx
shrq %rcx
movl %eax, %edx
andl $0x1, %edx
orq %rcx, %rdx
cvtsi2ss %rdx, %xmm0
addss %xmm0, %xmm0
ucomiss 0x654(%rbp), %xmm0
ja 0x1db5c
cmpq %r14, %r15
je 0x1dc09
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x1f8ff
cmpq $0x101, %rbx            # imm = 0x101
jl 0x1dbfe
leaq 0x100(%r15), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x1fb67
cmpq %r14, %r12
je 0x1dc09
movq %r12, %rdi
callq 0x1fbd7
addq $0x10, %r12
jmp 0x1dbeb
movq %r15, %rdi
movq %r14, %rsi
callq 0x1fb67
movq 0x24420(%rip), %rax     # 0x42030
movq 0x24411(%rip), %rsi     # 0x42028
cmpq %rsi, %rax
je 0x1dc99
movq (%rsi), %rcx
leaq 0xe10(%rcx), %rdi
movq 0x243eb(%rip), %rdx     # 0x42018
cmpq %rdx, %rdi
jge 0x1dc75
leaq 0x243ef(%rip), %rdi     # 0x42028
callq 0x2057a
movq 0x243eb(%rip), %rax     # 0x42030
cmpq 0x243dc(%rip), %rax     # 0x42028
jne 0x1dd37
cmpl $0x0, 0x1872f(%rip)     # 0x36388
jle 0x1dd37
movq %rbp, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1d890
cmpq %rdx, %rcx
jg 0x1dc99
cmpl $0x0, 0x18707(%rip)     # 0x36388
jg 0x1dc99
movq %rbp, %rdi
callq 0x1d840
movq 0x2439e(%rip), %rax     # 0x42030
movq 0x2438f(%rip), %rsi     # 0x42028
cmpq %rsi, %rax
je 0x1dcb5
movq 0x24373(%rip), %rcx     # 0x42018
cmpq %rcx, (%rsi)
jle 0x1dceb
cmpl $0x0, 0x186d7(%rip)     # 0x36388
jg 0x1dcc5
jmp 0x1dceb
cmpl $0x0, 0x186cc(%rip)     # 0x36388
jle 0x1dd0d
movq 0x24353(%rip), %rcx     # 0x42018
subq 0x2438c(%rip), %rcx     # 0x42058
cmpq $0x259, %rcx            # imm = 0x259
jl 0x1dceb
movq %rbp, %rdi
callq 0x1d890
movq 0x2434c(%rip), %rax     # 0x42030
movq 0x2433d(%rip), %rsi     # 0x42028
cmpq %rsi, %rax
je 0x1dd0d
movq (%rsi), %rax
movl $0x15180, %ecx          # imm = 0x15180
cqto
idivq %rcx
movq %rdx, %rax
movl $0xe10, %ecx            # imm = 0xE10
cltd
idivl %ecx
movslq %eax, %rsi
jmp 0x1dd1b
movq 0x24304(%rip), %rsi     # 0x42018
subq 0x2433d(%rip), %rsi     # 0x42058
leaq 0xf30d(%rip), %rdi      # 0x2d02f
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x242f3(%rip), %rdi     # 0x42040
callq 0x24f0
testl %eax, %eax
je 0x1d921
xorps %xmm0, %xmm0
movups %xmm0, 0x242c4(%rip)    # 0x42028
andq $0x0, 0x242cc(%rip)     # 0x42038
leaq 0x242b5(%rip), %rsi     # 0x42028
leaq -0xba1e(%rip), %rdi     # 0x1235c
leaq 0x18547(%rip), %rdx     # 0x362c8
callq 0x2230
leaq 0x242b3(%rip), %rdi     # 0x42040
callq 0x2180
jmp 0x1d921