// File: /workspace/github_cpp_makefile_star2_O3/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, 0x4(%rsp)
movl %edx, (%rsp)
movq %rsi, %rbp
movq %rdi, %rbx
cmpb $0x1, 0x244e1(%rip)     # 0x45000
jne 0x20b2f
leaq 0x116db(%rip), %rdi     # 0x32203
xorl %eax, %eax
callq 0x2040
movb 0x244eb(%rip), %al      # 0x45020
testb %al, %al
je 0x21172
leaq 0x244b4(%rip), %rdi     # 0x44ff8
callq 0x2250
movq 0x244a8(%rip), %rcx     # 0x44ff8
cmpl $0x1f5, %r12d           # imm = 0x1F5
jl 0x20b88
movq %rcx, 0x244d8(%rip)     # 0x45038
cmpl $0x0, 0x18801(%rip)     # 0x39368
movl 0x4(%rsp), %esi
movl (%rsp), %edi
jg 0x20b8f
movq %rbp, %rdi
callq 0x20a5a
movl (%rsp), %edi
movl 0x4(%rsp), %esi
movq 0x24472(%rip), %rcx     # 0x44ff8
jmp 0x20b8f
movl 0x4(%rsp), %esi
movl (%rsp), %edi
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
movslq %ecx, %rax
imulq $-0x77777777, %rax, %rcx # imm = 0x88888889
shrq $0x20, %rcx
addl %ecx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0x5, %eax
addl %ecx, %eax
cmpl %edi, %eax
setle %cl
cmpl %esi, %eax
setge %dl
orb %cl, %dl
jne 0x20be9
movl $0x0, 0x18787(%rip)     # 0x39370
cmpl %esi, %eax
setle %cl
cmpl %edi, %eax
setge %al
testb %al, %cl
jne 0x20ff2
cmpl $0x0, 0x1876e(%rip)     # 0x39370
movss 0x654(%rbp), %xmm0
jle 0x20c1f
cvtsi2ssl 0x18758(%rip), %xmm1 # 0x3936c
ucomiss %xmm1, %xmm0
jne 0x20c1f
jnp 0x20ff2
movl $0x1, 0x18747(%rip)     # 0x39370
cvttss2si %xmm0, %eax
movl %eax, 0x18739(%rip)     # 0x3936c
movq 0x243ce(%rip), %r12     # 0x45008
movq 0x243cf(%rip), %r13     # 0x45010
cmpq %r12, %r13
je 0x20c50
movq %r12, 0x243c3(%rip)     # 0x45010
movq %r12, %r13
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x20dfe
movq %rbp, 0x8(%rsp)
movl %edi, %ecx
subl %esi, %ecx
movl %ecx, %edx
addl $0x5a0, %edx            # imm = 0x5A0
movslq %edx, %rdx
imulq $-0x77777777, %rdx, %rdx # imm = 0x88888889
shrq $0x20, %rdx
addl %edx, %ecx
addl $0x5a0, %ecx            # imm = 0x5A0
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x5, %ecx
addl %edx, %ecx
movslq %ecx, %r11
movl $0x8, %ebp
xorl %r14d, %r14d
movabsq $0xfedcba987654321, %r8 # imm = 0xFEDCBA987654321
movabsq $0x91a2b3c4d5e6f0, %r9  # imm = 0x91A2B3C4D5E6F0
movabsq $0x123456789abcde, %r10 # imm = 0x123456789ABCDE
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
movq %rbx, 0x20(%rsp)
movq 0x2433b(%rip), %r12     # 0x45008
movq %r13, %rcx
subq %r12, %rcx
sarq $0x4, %rcx
cmpq %r11, %rcx
jae 0x20df9
movq -0x8(%rax,%rbp), %rcx
movq %rcx, 0x2433c(%rip)     # 0x45028
movss (%rax,%rbp), %xmm0
movss %xmm0, 0x2433b(%rip)    # 0x45034
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
movq %rcx, %rdx
subq %rax, %rdx
movslq %edx, %rdx
imulq $-0x77777777, %rdx, %rax # imm = 0x88888889
shrq $0x20, %rax
addl %eax, %edx
movl %edx, %eax
shrl $0x1f, %eax
sarl $0x5, %edx
addl %eax, %edx
cmpl %esi, %edx
setg %al
cmpl %edi, %edx
setl %dl
imulq %r8, %rcx
addq %r9, %rcx
rorq $0x4, %rcx
cmpq %r10, %rcx
ja 0x20dd0
orb %dl, %al
je 0x20dd0
cmpq 0x242b5(%rip), %r13     # 0x45018
je 0x20d85
movups 0x242bc(%rip), %xmm0    # 0x45028
movups %xmm0, (%r13)
movq 0x24298(%rip), %r13     # 0x45010
addq $0x10, %r13
movq %r13, 0x2428d(%rip)     # 0x45010
jmp 0x20dd0
leaq 0x2427c(%rip), %rdi     # 0x45008
movq %r13, %rsi
leaq 0x24292(%rip), %rdx     # 0x45028
movq %r8, %r12
movq %r9, %r13
movq %r10, %rbx
movq %r11, %r15
callq 0x24054
movq %r15, %r11
movabsq $-0x5555555555555555, %r15 # imm = 0xAAAAAAAAAAAAAAAB
movq %rbx, %r10
movq 0x20(%rsp), %rbx
movq %r13, %r9
movq %r12, %r8
movl (%rsp), %edi
movl 0x4(%rsp), %esi
movq 0x24240(%rip), %r13     # 0x45010
incq %r14
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
imulq %r15, %rcx
addq $0x18, %rbp
cmpq %r14, %rcx
ja 0x20cc6
movq 0x2420f(%rip), %r12     # 0x45008
movq 0x8(%rsp), %rbp
cmpq %r13, %r12
je 0x20eb1
movq %r13, %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 %r13, %rsi
callq 0x22ee3
cmpq $0x101, %rbx            # imm = 0x101
jl 0x20ea6
leaq 0x100(%r12), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x2319e
cmpq %r13, %r14
je 0x20eb1
movl 0x8(%r14), %eax
movl %eax, 0x18(%rsp)
movq (%r14), %rax
movq %rax, 0x10(%rsp)
movss -0x4(%r14), %xmm1
movss 0xc(%r14), %xmm0
ucomiss %xmm0, %xmm1
movq %r14, %rax
jbe 0x20e8c
movq %r14, %rcx
leaq -0x10(%rcx), %rax
movups -0x10(%rcx), %xmm1
movups %xmm1, (%rcx)
movss -0x14(%rcx), %xmm1
ucomiss %xmm0, %xmm1
movq %rax, %rcx
ja 0x20e74
movl 0x18(%rsp), %ecx
movl %ecx, 0x8(%rax)
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movss %xmm0, 0xc(%rax)
addq $0x10, %r14
jmp 0x20e48
movq %r12, %rdi
movq %r13, %rsi
callq 0x2319e
movq 0x24158(%rip), %r14     # 0x45010
movq 0x24149(%rip), %r15     # 0x45008
movq %r14, %rbx
subq %r15, %rbx
movq %rbx, %rax
sarq $0x4, %rax
js 0x20ed8
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
jmp 0x20ef2
movq %rax, %rcx
shrq %rcx
movl %eax, %edx
andl $0x1, %edx
orq %rcx, %rdx
xorps %xmm1, %xmm1
cvtsi2ss %rdx, %xmm1
addss %xmm1, %xmm1
movss 0x654(%rbp), %xmm0
ucomiss %xmm0, %xmm1
jbe 0x20f77
movq %r14, %rax
subq %r15, %rax
leaq (%rax,%r15), %rsi
cmpq %r14, %rsi
je 0x20f37
leaq (%rax,%r15), %rdi
addq $-0x10, %rdi
subq %rsi, %r14
movq %r14, %rdx
callq 0x2470
movq 0x240e8(%rip), %r14     # 0x45010
movq 0x240d9(%rip), %r15     # 0x45008
movss 0x654(%rbp), %xmm0
addq $-0x10, %r14
movq %r14, 0x240ce(%rip)     # 0x45010
movq %r14, %rbx
subq %r15, %rbx
movq %rbx, %rax
sarq $0x4, %rax
js 0x20f5b
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
jmp 0x20efa
movq %rax, %rcx
shrq %rcx
movl %eax, %edx
andl $0x1, %edx
orq %rcx, %rdx
xorps %xmm1, %xmm1
cvtsi2ss %rdx, %xmm1
addss %xmm1, %xmm1
jmp 0x20efa
cmpq %r14, %r15
je 0x20ff2
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x23264
cmpq $0x101, %rbx            # imm = 0x101
jl 0x20fe7
leaq 0x100(%r15), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x23504
cmpq %r14, %r12
je 0x20ff2
movups (%r12), %xmm0
movq (%r12), %rax
movq %r12, %rcx
cmpq %rax, -0x10(%r12)
jle 0x20fde
movq %r12, %rdx
leaq -0x10(%rdx), %rcx
movups -0x10(%rdx), %xmm1
movups %xmm1, (%rdx)
cmpq %rax, -0x20(%rdx)
movq %rcx, %rdx
jg 0x20fca
movups %xmm0, (%rcx)
addq $0x10, %r12
jmp 0x20faf
movq %r15, %rdi
movq %r14, %rsi
callq 0x23504
movq 0x24017(%rip), %rdx     # 0x45010
movq 0x24008(%rip), %rdi     # 0x45008
cmpq %rdi, %rdx
je 0x21099
movq (%rdi), %rax
leaq 0xe10(%rax), %rsi
movq 0x23fde(%rip), %rcx     # 0x44ff8
cmpq %rcx, %rsi
jge 0x21075
leaq 0x10(%rdi), %rsi
cmpq %rdx, %rsi
je 0x2103e
subq %rsi, %rdx
callq 0x2470
movq 0x23fd9(%rip), %rdx     # 0x45010
movq 0x23fca(%rip), %rdi     # 0x45008
addq $-0x10, %rdx
movq %rdx, 0x23fc7(%rip)     # 0x45010
cmpq %rdi, %rdx
jne 0x21163
cmpl $0x0, 0x1830f(%rip)     # 0x39368
jle 0x21163
movq %rbp, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20aaa
cmpq %rcx, %rax
jg 0x21099
cmpl $0x0, 0x182e7(%rip)     # 0x39368
jg 0x21099
movq %rbp, %rdi
callq 0x20a5a
movq 0x23f7e(%rip), %rdx     # 0x45010
movq 0x23f6f(%rip), %rdi     # 0x45008
cmpq %rdi, %rdx
je 0x210b5
movq 0x23f53(%rip), %rax     # 0x44ff8
cmpq %rax, (%rdi)
jle 0x210ea
cmpl $0x0, 0x182b7(%rip)     # 0x39368
jg 0x210c5
jmp 0x210ea
cmpl $0x0, 0x182ac(%rip)     # 0x39368
jle 0x21139
movq 0x23f33(%rip), %rax     # 0x44ff8
subq 0x23f6c(%rip), %rax     # 0x45038
cmpq $0x259, %rax            # imm = 0x259
jl 0x210ea
movq %rbp, %rdi
callq 0x20aaa
movq 0x23f2d(%rip), %rdx     # 0x45010
movq 0x23f1e(%rip), %rdi     # 0x45008
cmpq %rdi, %rdx
je 0x21139
movq (%rdi), %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
movslq %ecx, %rax
imulq $-0x6e5d4c3b, %rax, %rcx # imm = 0x91A2B3C5
shrq $0x20, %rcx
addl %ecx, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
sarl $0xb, %eax
addl %ecx, %eax
movslq %eax, %rsi
jmp 0x21147
movq 0x23eb8(%rip), %rsi     # 0x44ff8
subq 0x23ef1(%rip), %rsi     # 0x45038
leaq 0x110b9(%rip), %rdi     # 0x32207
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
callq 0x26c5
jmp 0x20b3d