// File: 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:
subq $0xa8, %rsp
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movl %edx, 0x94(%rsp)
movl %ecx, 0x90(%rsp)
movl %r8d, 0x8c(%rsp)
testb $0x1, 0x4386c(%rip)     # 0x7a060
je 0x36804
leaq 0x2b6b2(%rip), %rdi     # 0x61eaf
movb $0x0, %al
callq 0x2040
cmpb $0x0, 0x43875(%rip)     # 0x7a080
jne 0x36850
leaq 0x4386c(%rip), %rdi     # 0x7a080
callq 0x24f0
cmpl $0x0, %eax
je 0x36850
leaq 0x43843(%rip), %rdi     # 0x7a068
callq 0x1c830
leaq -0x19ff1(%rip), %rdi    # 0x1c840
leaq 0x43830(%rip), %rsi     # 0x7a068
leaq 0x37a89(%rip), %rdx     # 0x6e2c8
callq 0x2260
leaq 0x43835(%rip), %rdi     # 0x7a080
callq 0x21b0
leaq 0x43801(%rip), %rdi     # 0x7a058
callq 0x2280
cmpl $0x1f4, 0x8c(%rsp) # imm = 0x1F4
jle 0x3688f
movq 0x437e8(%rip), %rax     # 0x7a058
movq %rax, 0x43821(%rip)     # 0x7a098
cmpl $0x0, 0x37b2a(%rip)     # 0x6e3a8
jg 0x3688d
movq 0x98(%rsp), %rdi
callq 0x36700
jmp 0x3688f
movq 0x437c2(%rip), %rax     # 0x7a058
movl $0x15180, %ecx          # imm = 0x15180
cqto
idivq %rcx
movq %rdx, %rax
movl $0x3c, %ecx
cqto
idivq %rcx
movslq 0x94(%rsp), %rcx
cmpq %rcx, %rax
jle 0x368ef
movq 0x43797(%rip), %rax     # 0x7a058
movl $0x15180, %ecx          # imm = 0x15180
cqto
idivq %rcx
movq %rdx, %rax
movl $0x3c, %ecx
cqto
idivq %rcx
movslq 0x90(%rsp), %rcx
cmpq %rcx, %rax
jge 0x368ef
movl $0x0, 0x37ac1(%rip)     # 0x6e3b0
movq 0x43762(%rip), %rax     # 0x7a058
movl $0x15180, %ecx          # imm = 0x15180
cqto
idivq %rcx
movq %rdx, %rax
movl $0x3c, %ecx
cqto
idivq %rcx
movslq 0x90(%rsp), %rcx
cmpq %rcx, %rax
jg 0x36949
movq 0x43737(%rip), %rax     # 0x7a058
movl $0x15180, %ecx          # imm = 0x15180
cqto
idivq %rcx
movq %rdx, %rax
movl $0x3c, %ecx
cqto
idivq %rcx
movslq 0x94(%rsp), %rcx
cmpq %rcx, %rax
jge 0x36bfa
cmpl $0x1, 0x37a60(%rip)     # 0x6e3b0
jl 0x36976
movq 0x98(%rsp), %rax
movss 0x654(%rax), %xmm0
cvtsi2ssl 0x37a42(%rip), %xmm1 # 0x6e3ac
ucomiss %xmm1, %xmm0
jne 0x36976
jp 0x36976
jmp 0x36bfa
movl $0x1, 0x37a30(%rip)     # 0x6e3b0
movq 0x98(%rsp), %rax
cvttss2si 0x654(%rax), %eax
movl %eax, 0x37a16(%rip)     # 0x6e3ac
leaq 0x436cb(%rip), %rdi     # 0x7a068
callq 0x3e9d0
movl 0x94(%rsp), %eax
addl $0x5a0, %eax            # imm = 0x5A0
subl 0x90(%rsp), %eax
movl $0x3c, %ecx
cltd
idivl %ecx
movl %eax, 0x88(%rsp)
movl $0x0, 0x84(%rsp)
movslq 0x84(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xa0(%rsp), %rdi
callq 0x1ce80
movq 0x8(%rsp), %rcx
movq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x17(%rsp)
jae 0x36a1a
leaq 0x43665(%rip), %rdi     # 0x7a068
callq 0x1ce40
movslq 0x88(%rsp), %rcx
cmpq %rcx, %rax
setb %al
movb %al, 0x17(%rsp)
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x36a27
jmp 0x36aef
movq 0xa0(%rsp), %rdi
movslq 0x84(%rsp), %rsi
callq 0x1ce20
movq (%rax), %rax
movq %rax, 0x43642(%rip)     # 0x7a088
movq 0xa0(%rsp), %rdi
movslq 0x84(%rsp), %rsi
callq 0x1ce20
movss 0x8(%rax), %xmm0
movss %xmm0, 0x4362c(%rip)    # 0x7a094
movq 0x43619(%rip), %rax     # 0x7a088
movl $0x15180, %ecx          # imm = 0x15180
cqto
idivq %rcx
movq %rdx, %rax
movl $0x3c, %ecx
cqto
idivq %rcx
movl %eax, 0x80(%rsp)
movl 0x80(%rsp), %eax
cmpl 0x90(%rsp), %eax
jg 0x36aad
movl 0x80(%rsp), %eax
cmpl 0x94(%rsp), %eax
jge 0x36ad7
movq 0x435d4(%rip), %rax     # 0x7a088
movl $0xe10, %ecx            # imm = 0xE10
cqto
idivq %rcx
cmpq $0x0, %rdx
jne 0x36ad7
leaq 0x4359d(%rip), %rdi     # 0x7a068
leaq 0x435b6(%rip), %rsi     # 0x7a088
callq 0x3e9f0
jmp 0x36ad9
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x369cf
leaq 0x43572(%rip), %rdi     # 0x7a068
callq 0x3ea60
movq %rax, 0x78(%rsp)
leaq 0x43561(%rip), %rdi     # 0x7a068
callq 0x3ea90
movq %rax, 0x70(%rsp)
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rsi
callq 0x36da0
leaq 0x43541(%rip), %rdi     # 0x7a068
callq 0x1ce40
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, (%rsp)
testq %rax, %rax
movss %xmm0, 0x4(%rsp)
js 0x36b63
movss (%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0x4(%rsp), %xmm0
movq 0x98(%rsp), %rax
ucomiss 0x654(%rax), %xmm0
jbe 0x36bc9
leaq 0x434e7(%rip), %rdi     # 0x7a068
callq 0x3ea90
movq %rax, 0x50(%rsp)
leaq 0x50(%rsp), %rdi
movl $0x1, %esi
callq 0x3eb30
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x3eb80
movq 0x60(%rsp), %rsi
leaq 0x434ae(%rip), %rdi     # 0x7a068
callq 0x3eac0
movq %rax, 0x48(%rsp)
jmp 0x36b20
leaq 0x43498(%rip), %rdi     # 0x7a068
callq 0x3ea60
movq %rax, 0x40(%rsp)
leaq 0x43487(%rip), %rdi     # 0x7a068
callq 0x3ea90
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x36de0
leaq 0x43467(%rip), %rdi     # 0x7a068
callq 0x1ce40
cmpq $0x0, %rax
jbe 0x36cc9
leaq 0x43451(%rip), %rdi     # 0x7a068
xorl %eax, %eax
movl %eax, %esi
callq 0x1ce60
movq (%rax), %rax
addq $0xe10, %rax            # imm = 0xE10
cmpq 0x43428(%rip), %rax     # 0x7a058
jge 0x36c95
leaq 0x4342f(%rip), %rdi     # 0x7a068
callq 0x3ea60
movq %rax, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3eb80
movq 0x28(%rsp), %rsi
leaq 0x4340a(%rip), %rdi     # 0x7a068
callq 0x3eac0
movq %rax, 0x18(%rsp)
leaq 0x433f9(%rip), %rdi     # 0x7a068
callq 0x1ce40
cmpq $0x0, %rax
jne 0x36c90
cmpl $0x0, 0x37727(%rip)     # 0x6e3a8
jle 0x36c90
movq 0x98(%rsp), %rdi
callq 0x36760
jmp 0x36d8e
leaq 0x433cc(%rip), %rdi     # 0x7a068
xorl %eax, %eax
movl %eax, %esi
callq 0x1ce60
movq (%rax), %rax
cmpq 0x433a9(%rip), %rax     # 0x7a058
jg 0x36cc7
cmpl $0x0, 0x376f0(%rip)     # 0x6e3a8
jg 0x36cc7
movq 0x98(%rsp), %rdi
callq 0x36700
jmp 0x36cc9
leaq 0x43398(%rip), %rdi     # 0x7a068
callq 0x1ce40
cmpq $0x0, %rax
je 0x36cf7
leaq 0x43386(%rip), %rdi     # 0x7a068
xorl %eax, %eax
movl %eax, %esi
callq 0x1ce60
movq (%rax), %rax
cmpq 0x43363(%rip), %rax     # 0x7a058
jle 0x36d23
cmpl $0x0, 0x376aa(%rip)     # 0x6e3a8
jle 0x36d23
movq 0x43351(%rip), %rax     # 0x7a058
subq 0x4338a(%rip), %rax     # 0x7a098
cmpq $0x258, %rax            # imm = 0x258
jle 0x36d23
movq 0x98(%rsp), %rdi
callq 0x36760
leaq 0x4333e(%rip), %rdi     # 0x7a068
callq 0x1ce40
cmpq $0x0, %rax
jbe 0x36d72
leaq 0x4332c(%rip), %rdi     # 0x7a068
xorl %eax, %eax
movl %eax, %esi
callq 0x1ce60
movq (%rax), %rax
movl $0x15180, %ecx          # imm = 0x15180
cqto
idivq %rcx
movq %rdx, %rax
movl $0xe10, %ecx            # imm = 0xE10
cqto
idivq %rcx
movq %rax, %rsi
leaq 0x2b14a(%rip), %rdi     # 0x61eb3
movb $0x0, %al
callq 0x2040
jmp 0x36d8e
movq 0x432df(%rip), %rsi     # 0x7a058
subq 0x43318(%rip), %rsi     # 0x7a098
leaq 0x2b12c(%rip), %rdi     # 0x61eb3
movb $0x0, %al
callq 0x2040
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)