// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movl %r8d, %r12d
movl %ecx, %ebp
movl %edx, %r14d
movq %rsi, %r13
movq %rdi, %r15
cmpb $0x1, 0x24377(%rip)     # 0x45000
jne 0x20c99
leaq 0x11569(%rip), %rdi     # 0x321fb
xorl %eax, %eax
callq 0x2040
movb 0x24381(%rip), %al      # 0x45020
testb %al, %al
je 0x2104d
leaq 0x2434a(%rip), %rdi     # 0x44ff8
callq 0x2250
cmpl $0x1f5, %r12d           # imm = 0x1F5
jl 0x20cdb
movq 0x24335(%rip), %rax     # 0x44ff8
movq %rax, 0x2436e(%rip)     # 0x45038
cmpl $0x0, 0x18697(%rip)     # 0x39368
jg 0x20cdb
movq %r13, %rdi
callq 0x20bc6
movq 0x24316(%rip), %rcx     # 0x44ff8
movabsq $0x1845c8a0ce512957, %rdx # imm = 0x1845C8A0CE512957
movq %rcx, %rax
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xd, %rdx
addq %rax, %rdx
imulq $0x15180, %rdx, %rax    # imm = 0x15180
subq %rax, %rcx
movabsq $-0x7777777777777777, %r8 # imm = 0x8888888888888889
movq %rcx, %rax
imulq %r8
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x5, %rdx
addq %rax, %rdx
movslq %r14d, %rax
cmpq %rax, %rdx
setle %sil
movslq %ebp, %rcx
cmpq %rcx, %rdx
setge %dil
orb %sil, %dil
jne 0x20d4e
movl $0x0, 0x18622(%rip)     # 0x39370
cmpq %rcx, %rdx
setle %cl
cmpq %rax, %rdx
setge %al
testb %al, %cl
jne 0x21134
cmpl $0x0, 0x18607(%rip)     # 0x39370
jle 0x20d87
cvtsi2ssl 0x185f9(%rip), %xmm0 # 0x3936c
movss 0x654(%r13), %xmm1
ucomiss %xmm0, %xmm1
jne 0x20d87
jnp 0x21134
movl $0x1, 0x185df(%rip)     # 0x39370
movq %r13, 0x18(%rsp)
cvttss2si 0x654(%r13), %eax
movl %eax, 0x185c7(%rip)     # 0x3936c
movq 0x2425c(%rip), %rax     # 0x45008
cmpq %rax, 0x2425d(%rip)     # 0x45010
je 0x20dbc
movq %rax, 0x24254(%rip)     # 0x45010
movq (%r15), %rdi
cmpq %rdi, 0x8(%r15)
je 0x20f4e
movl %r14d, %eax
subl %ebp, %eax
movl %eax, %ecx
addl $0x5a0, %ecx            # imm = 0x5A0
movslq %ecx, %rcx
imulq $-0x77777777, %rcx, %rcx # imm = 0x88888889
shrq $0x20, %rcx
addl %ecx, %eax
addl $0x5a0, %eax            # imm = 0x5A0
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0x5, %eax
addl %ecx, %eax
movslq %eax, %r9
movl $0x8, %r12d
xorl %ebx, %ebx
movabsq $0xfedcba987654321, %r10 # imm = 0xFEDCBA987654321
movabsq $0x91a2b3c4d5e6f0, %r11 # imm = 0x91A2B3C4D5E6F0
movabsq $0x123456789abcde, %r13 # imm = 0x123456789ABCDE
movl %r14d, 0x4(%rsp)
movq %r15, 0x20(%rsp)
movl %ebp, (%rsp)
movq 0x241de(%rip), %rsi     # 0x45010
movq %rsi, %rax
subq 0x241cc(%rip), %rax     # 0x45008
sarq $0x4, %rax
cmpq %r9, %rax
jae 0x20f4e
movq -0x8(%rdi,%r12), %rcx
movq %rcx, 0x241d3(%rip)     # 0x45028
movq %rcx, %rax
movabsq $0x1845c8a0ce512957, %rdx # imm = 0x1845C8A0CE512957
imulq %rdx
movss (%rdi,%r12), %xmm0
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xd, %rdx
addq %rax, %rdx
imulq $0x15180, %rdx, %rax    # imm = 0x15180
movq %rcx, %rdi
subq %rax, %rdi
movq %rdi, %rax
imulq %r8
movss %xmm0, 0x241a0(%rip)    # 0x45034
addq %rdi, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
shrq $0x5, %rdx
addl %eax, %edx
cmpl %ebp, %edx
setg %al
cmpl %r14d, %edx
setl %dl
imulq %r10, %rcx
addq %r11, %rcx
rorq $0x4, %rcx
cmpq %r13, %rcx
ja 0x20f22
orb %dl, %al
je 0x20f22
cmpq 0x2414e(%rip), %rsi     # 0x45018
je 0x20ee0
movups 0x24155(%rip), %xmm0    # 0x45028
movups %xmm0, (%rsi)
addq $0x10, 0x24132(%rip)    # 0x45010
jmp 0x20f22
leaq 0x24121(%rip), %rdi     # 0x45008
leaq 0x2413a(%rip), %rdx     # 0x45028
movq %r8, %rbp
movq %r9, %r15
movq %r10, %r13
movq %r11, %r14
callq 0x240ea
movq %r14, %r11
movq %r13, %r10
movabsq $0x123456789abcde, %r13 # imm = 0x123456789ABCDE
movq %r15, %r9
movq 0x20(%rsp), %r15
movq %rbp, %r8
movl (%rsp), %ebp
movl 0x4(%rsp), %r14d
incq %rbx
movq (%r15), %rdi
movq 0x8(%r15), %rax
subq %rdi, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
addq $0x18, %r12
cmpq %rbx, %rax
ja 0x20e2b
movq 0x240b3(%rip), %r12     # 0x45008
movq 0x240b4(%rip), %r14     # 0x45010
cmpq %r14, %r12
je 0x2100f
movq %r14, %rbx
subq %r12, %rbx
movq %rbx, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x22f98
cmpq $0x101, %rbx            # imm = 0x101
jl 0x21004
leaq 0x100(%r12), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x23266
cmpq %r14, %r15
je 0x2100f
movl 0x8(%r15), %eax
movl %eax, 0x10(%rsp)
movq (%r15), %rax
movq %rax, 0x8(%rsp)
movss -0x4(%r15), %xmm1
movss 0xc(%r15), %xmm0
ucomiss %xmm0, %xmm1
movq %r15, %rax
jbe 0x20fea
movq %r15, %rcx
leaq -0x10(%rcx), %rax
movups -0x10(%rcx), %xmm1
movups %xmm1, (%rcx)
movss -0x14(%rcx), %xmm1
ucomiss %xmm0, %xmm1
movq %rax, %rcx
ja 0x20fd2
movl 0x10(%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movss %xmm0, 0xc(%rax)
addq $0x10, %r15
jmp 0x20fa6
movq %r12, %rdi
movq %r14, %rsi
callq 0x23266
movq 0x23ffa(%rip), %r14     # 0x45010
movq 0x23feb(%rip), %r15     # 0x45008
movq %r14, %rbx
subq %r15, %rbx
movq %rbx, %rax
sarq $0x4, %rax
movq 0x18(%rsp), %r13
jns 0x21057
movq %rax, %rcx
shrq %rcx
movl %eax, %edx
andl $0x1, %edx
orq %rcx, %rdx
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
addss %xmm0, %xmm0
jmp 0x2105f
callq 0x26c5
jmp 0x20ca7
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
ucomiss 0x654(%r13), %xmm0
jbe 0x210b9
movq %r14, %rax
subq %r15, %rax
leaq (%rax,%r15), %rsi
cmpq %r14, %rsi
je 0x2108b
leaq (%rax,%r15), %rdi
addq $-0x10, %rdi
subq %rsi, %r14
movq %r14, %rdx
callq 0x2470
movq 0x23f7e(%rip), %r14     # 0x45010
addq $-0x10, %r14
movq %r14, 0x23f73(%rip)     # 0x45010
movq 0x23f64(%rip), %r15     # 0x45008
movq %r14, %rbx
subq %r15, %rbx
movq %rbx, %rax
sarq $0x4, %rax
js 0x21031
jmp 0x21057
cmpq %r14, %r15
je 0x21134
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x2332c
cmpq $0x101, %rbx            # imm = 0x101
jl 0x21129
leaq 0x100(%r15), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x235df
cmpq %r14, %r12
je 0x21134
movups (%r12), %xmm0
movq (%r12), %rax
movq %r12, %rcx
cmpq -0x10(%r12), %rax
jge 0x21120
movq %r12, %rdx
leaq -0x10(%rdx), %rcx
movups -0x10(%rdx), %xmm1
movups %xmm1, (%rdx)
cmpq -0x20(%rdx), %rax
movq %rcx, %rdx
jl 0x2110c
movups %xmm0, (%rcx)
addq $0x10, %r12
jmp 0x210f1
movq %r15, %rdi
movq %r14, %rsi
callq 0x235df
movq 0x23ed5(%rip), %rdx     # 0x45010
movq 0x23ec6(%rip), %rdi     # 0x45008
cmpq %rdi, %rdx
je 0x211c6
movq (%rdi), %rax
leaq 0xe10(%rax), %rsi
movq 0x23ea0(%rip), %rcx     # 0x44ff8
cmpq %rcx, %rsi
jge 0x211b0
leaq 0x10(%rdi), %rsi
cmpq %rdx, %rsi
je 0x2116e
subq %rsi, %rdx
callq 0x2470
movq 0x23e9b(%rip), %rax     # 0x45010
addq $-0x10, %rax
movq %rax, 0x23e90(%rip)     # 0x45010
cmpq 0x23e81(%rip), %rax     # 0x45008
jne 0x2128e
cmpl $0x0, 0x181d4(%rip)     # 0x39368
jle 0x2128e
movq %r13, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20c16
cmpq %rcx, %rax
jg 0x211c6
cmpl $0x0, 0x181ac(%rip)     # 0x39368
jg 0x211c6
movq %r13, %rdi
callq 0x20bc6
movq 0x23e3b(%rip), %rax     # 0x45008
cmpq %rax, 0x23e3c(%rip)     # 0x45010
je 0x211e2
movq (%rax), %rax
cmpq 0x23e18(%rip), %rax     # 0x44ff8
jle 0x21209
cmpl $0x0, 0x1817f(%rip)     # 0x39368
jle 0x21209
movq 0x23e06(%rip), %rax     # 0x44ff8
subq 0x23e3f(%rip), %rax     # 0x45038
cmpq $0x259, %rax            # imm = 0x259
jl 0x21209
movq %r13, %rdi
callq 0x20c16
movq 0x23df8(%rip), %rax     # 0x45008
cmpq %rax, 0x23df9(%rip)     # 0x45010
je 0x21264
movq (%rax), %rcx
movq %rcx, %rax
movabsq $0x1845c8a0ce512957, %rdx # imm = 0x1845C8A0CE512957
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xd, %rdx
addq %rax, %rdx
imulq $0x15180, %rdx, %rax    # imm = 0x15180
subq %rax, %rcx
movabsq $0x48d159e26af37c05, %rdx # imm = 0x48D159E26AF37C05
movq %rcx, %rax
imulq %rdx
movq %rdx, %rsi
shrq $0x3f, %rsi
sarq $0xa, %rdx
addq %rdx, %rsi
jmp 0x21272
movq 0x23d8d(%rip), %rsi     # 0x44ff8
subq 0x23dc6(%rip), %rsi     # 0x45038
leaq 0x10f86(%rip), %rdi     # 0x321ff
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq