// File: Necrelox[P]Auto_Presence/src/automatic_presence.cpp
// Function: automatic_presence::AutomaticPresence()
void automatic_presence::AutomaticPresence()
{
    filehandle handle(this->path);
    std::string buff;
    this->newfile << "login;present" << std::endl;
    while (std::getline(handle.file, buff)) {
        short count = std::count(buff.begin(), buff.end(), '\t');
        if (count == 5) {
            short valid = 0;
            std::stringstream manipule(buff);
            std::vector<std::string> tab;
            std::string push;
            while(getline(manipule, push, ' '))
                tab.push_back(push);

            int key = 0;
            this->time_player_start = 0;
            this->time_player_end = 0;
            for (size_t i = 0, check = 0; i < tab.size(); i++) {
                check = std::count(tab[i].begin(), tab[i].end(), ':');
                if (check == 2) {
                    std::istringstream flux_player(tab[i]);
                    std::string split_player;
                    for (int t = 0, div = 10000; t < 3; t++) {
                        getline(flux_player, split_player, ':');
                        split_player.erase(std::remove(split_player.begin(), split_player.end(), 0), split_player.end()); 
                        split_player.erase(split_player.begin() + 2, split_player.end());
                        for (size_t j = 0; j < split_player.size() ; j++)
                            if (!std::isdigit(split_player[j])) {
                                valid = 1;
                                break;
                            }
                        if (key == 0)
                            this->time_player_start += std::atoi(split_player.c_str()) * div;
                        else 
                            this->time_player_end += std::atoi(split_player.c_str()) * div;
                        div /= 100;

                        if (t == 0 && std::atoi(split_player.c_str()) > 24) {
                            valid = 1;
                            break;
                        }
                        if (t > 0 && std::atoi(split_player.c_str()) > 60) {
                            valid = 1;
                            break;
                        }
                    }
                    if (valid == 1) {
                        valid = 0;
                        break;
                    }
                    key++;
                }
                tab[i].erase(std::remove(tab[i].begin(), tab[i].end(), 0), tab[i].end()); 
                if (tab[i].find("@epitech.eu") != std::string::npos) {
                    tab[i].erase(0, tab[i].find("\t")+1);
                    tab[i].erase(tab[i].find("@epitech.eu")+11);
                    if (tab[i].find("\t") != std::string::npos)
                        tab[i].erase(0, tab[i].find("\t")+1);
                    this->email = tab[i];
                }
            }
            if (key == 2 && !this->email.empty() && this->time_player_start != 0 && this->time_player_end != 0) {
                this->newfile << this->email << ";";
                int presence = 1;
                int hour_p = this->time_player_start / 10000;
                int hour_r = this->time_rules_start / 10000;
                int min_p = (this->time_player_start - (hour_p * 10000))/100;
                int min_r = (this->time_rules_start - (hour_r * 10000))/100;

                if (hour_p <= hour_r) {
                    if (hour_p < hour_r) {
                        hour_p = hour_r;
                        min_p = min_r;
                    }
                    if (min_p > min_r + this->late_authorized)
                        presence = 0;
                }
                else
                    presence = 0;

                if (this->time_player_end < this->time_rules_end)
                    presence = 0;

                if (presence == 0)
                    this->newfile << "absent" << std::endl;
                else
                    this->newfile << "present" << std::endl;
            }

        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x810, %rsp            # imm = 0x810
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x700(%rbp)
leaq -0x230(%rbp), %rdi
movq %rdi, -0x6f8(%rbp)
callq 0x3140
movq -0x6f8(%rbp), %rsi
leaq -0x210(%rbp), %rdi
callq 0x6ea0
jmp 0x4082
leaq -0x230(%rbp), %rdi
callq 0x31d0
leaq -0x260(%rbp), %rdi
callq 0x33d0
movq -0x700(%rbp), %rdi
addq $0x20, %rdi
leaq 0x3f88(%rip), %rsi      # 0x8034
callq 0x32e0
movq %rax, -0x708(%rbp)
jmp 0x40ba
movq -0x708(%rbp), %rdi
movq 0x6ef0(%rip), %rsi      # 0xafb8
callq 0x3310
jmp 0x40cf
jmp 0x40d1
leaq -0x210(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x3060
movq %rax, -0x710(%rbp)
jmp 0x40ed
movq -0x710(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x33b0
movb %al, -0x711(%rbp)
jmp 0x410b
movb -0x711(%rbp), %al
testb $0x1, %al
jne 0x411a
jmp 0x4ce3
leaq -0x260(%rbp), %rdi
movq %rdi, -0x728(%rbp)
callq 0x3290
movq -0x728(%rbp), %rdi
movq %rax, -0x270(%rbp)
callq 0x31b0
movq %rax, -0x278(%rbp)
movb $0x9, -0x279(%rbp)
movq -0x270(%rbp), %rdi
movq -0x278(%rbp), %rsi
leaq -0x279(%rbp), %rdx
callq 0x5070
movq %rax, -0x720(%rbp)
jmp 0x4171
movq -0x720(%rbp), %rax
movw %ax, -0x262(%rbp)
movswl -0x262(%rbp), %eax
cmpl $0x5, %eax
jne 0x4cde
movw $0x0, -0x27c(%rbp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x51a0
movl %eax, -0x72c(%rbp)
jmp 0x41af
movl -0x72c(%rbp), %edx
leaq -0x408(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x3440
jmp 0x41ca
leaq -0x420(%rbp), %rdi
callq 0x51c0
leaq -0x440(%rbp), %rdi
callq 0x33d0
leaq -0x408(%rbp), %rdi
leaq -0x440(%rbp), %rsi
movl $0x20, %edx
callq 0x34f0
movq %rax, -0x738(%rbp)
jmp 0x4203
movq -0x738(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x33b0
movb %al, -0x739(%rbp)
jmp 0x4221
movb -0x739(%rbp), %al
testb $0x1, %al
jne 0x422d
jmp 0x4295
leaq -0x420(%rbp), %rdi
leaq -0x440(%rbp), %rsi
callq 0x51e0
jmp 0x4242
jmp 0x41e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x31d0
jmp 0x4d1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x4d04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
jmp 0x4cb8
movq -0x700(%rbp), %rax
movl $0x0, -0x444(%rbp)
movl $0x0, 0x228(%rax)
movl $0x0, 0x22c(%rax)
movq $0x0, -0x450(%rbp)
movq $0x0, -0x458(%rbp)
movq -0x450(%rbp), %rax
movq %rax, -0x748(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x5250
movq %rax, %rcx
movq -0x748(%rbp), %rax
cmpq %rcx, %rax
jae 0x4a74
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
movq %rdi, -0x758(%rbp)
callq 0x5270
movq %rax, %rdi
callq 0x3290
movq -0x758(%rbp), %rdi
movq %rax, -0x460(%rbp)
movq -0x450(%rbp), %rsi
callq 0x5270
movq %rax, %rdi
callq 0x31b0
movq %rax, -0x468(%rbp)
movb $0x3a, -0x469(%rbp)
movq -0x460(%rbp), %rdi
movq -0x468(%rbp), %rsi
leaq -0x469(%rbp), %rdx
callq 0x5070
movq %rax, -0x750(%rbp)
jmp 0x4372
movq -0x750(%rbp), %rax
movq %rax, -0x458(%rbp)
cmpq $0x2, -0x458(%rbp)
jne 0x4782
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
callq 0x5270
movq %rax, %rsi
leaq -0x5f0(%rbp), %rdi
movl $0x8, %edx
callq 0x3480
jmp 0x43b7
leaq -0x610(%rbp), %rdi
callq 0x33d0
movl $0x0, -0x614(%rbp)
movl $0x2710, -0x618(%rbp)   # imm = 0x2710
cmpl $0x3, -0x614(%rbp)
jge 0x471d
leaq -0x5f0(%rbp), %rdi
leaq -0x610(%rbp), %rsi
movl $0x3a, %edx
callq 0x34f0
jmp 0x43fe
leaq -0x610(%rbp), %rdi
movq %rdi, -0x768(%rbp)
callq 0x3290
movq -0x768(%rbp), %rdi
movq %rax, -0x630(%rbp)
callq 0x31b0
movq %rax, -0x638(%rbp)
movl $0x0, -0x63c(%rbp)
movq -0x630(%rbp), %rdi
movq -0x638(%rbp), %rsi
leaq -0x63c(%rbp), %rdx
callq 0x50c0
movq %rax, -0x760(%rbp)
jmp 0x4458
movq -0x760(%rbp), %rax
movq %rax, -0x628(%rbp)
leaq -0x620(%rbp), %rdi
leaq -0x628(%rbp), %rsi
callq 0x5110
leaq -0x610(%rbp), %rdi
movq %rdi, -0x778(%rbp)
callq 0x31b0
movq %rax, -0x650(%rbp)
leaq -0x648(%rbp), %rdi
leaq -0x650(%rbp), %rsi
callq 0x5110
movq -0x778(%rbp), %rdi
movq -0x620(%rbp), %rsi
movq -0x648(%rbp), %rdx
callq 0x3080
movq %rax, -0x770(%rbp)
jmp 0x44c9
movq -0x770(%rbp), %rax
movq %rax, -0x658(%rbp)
leaq -0x610(%rbp), %rdi
movq %rdi, -0x788(%rbp)
callq 0x3290
movq %rax, -0x670(%rbp)
leaq -0x670(%rbp), %rdi
movl $0x2, %esi
callq 0x5290
movq %rax, -0x668(%rbp)
leaq -0x660(%rbp), %rdi
leaq -0x668(%rbp), %rsi
callq 0x5110
movq -0x788(%rbp), %rdi
callq 0x31b0
movq %rax, -0x680(%rbp)
leaq -0x678(%rbp), %rdi
leaq -0x680(%rbp), %rsi
callq 0x5110
movq -0x788(%rbp), %rdi
movq -0x660(%rbp), %rsi
movq -0x678(%rbp), %rdx
callq 0x3080
movq %rax, -0x780(%rbp)
jmp 0x4565
movq -0x780(%rbp), %rax
movq %rax, -0x688(%rbp)
movq $0x0, -0x690(%rbp)
movq -0x690(%rbp), %rax
movq %rax, -0x790(%rbp)
leaq -0x610(%rbp), %rdi
callq 0x31f0
movq %rax, %rcx
movq -0x790(%rbp), %rax
cmpq %rcx, %rax
jae 0x462e
movq -0x690(%rbp), %rsi
leaq -0x610(%rbp), %rdi
callq 0x3550
movq %rax, -0x798(%rbp)
jmp 0x45c7
movq -0x798(%rbp), %rax
movsbl (%rax), %edi
callq 0x32c0
cmpl $0x0, %eax
jne 0x4615
movw $0x1, -0x27c(%rbp)
jmp 0x462e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x238(%rbp)
movl %eax, -0x23c(%rbp)
leaq -0x610(%rbp), %rdi
callq 0x31d0
leaq -0x5f0(%rbp), %rdi
callq 0x3170
jmp 0x4cb8
jmp 0x4617
movq -0x690(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x690(%rbp)
jmp 0x457e
cmpl $0x0, -0x444(%rbp)
jne 0x4669
leaq -0x610(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3430
movl %eax, %ecx
movq -0x700(%rbp), %rax
imull -0x618(%rbp), %ecx
addl 0x228(%rax), %ecx
movl %ecx, 0x228(%rax)
jmp 0x4699
leaq -0x610(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3430
movl %eax, %ecx
movq -0x700(%rbp), %rax
imull -0x618(%rbp), %ecx
addl 0x22c(%rax), %ecx
movl %ecx, 0x22c(%rax)
movl -0x618(%rbp), %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, -0x618(%rbp)
cmpl $0x0, -0x614(%rbp)
jne 0x46da
leaq -0x610(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3430
cmpl $0x18, %eax
jle 0x46da
movw $0x1, -0x27c(%rbp)
jmp 0x471d
cmpl $0x0, -0x614(%rbp)
jle 0x4707
leaq -0x610(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3430
cmpl $0x3c, %eax
jle 0x4707
movw $0x1, -0x27c(%rbp)
jmp 0x471d
jmp 0x4709
movl -0x614(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x614(%rbp)
jmp 0x43d7
movswl -0x27c(%rbp), %eax
cmpl $0x1, %eax
jne 0x473e
movw $0x0, -0x27c(%rbp)
movl $0x6, -0x694(%rbp)
jmp 0x4757
movl -0x444(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x444(%rbp)
movl $0x0, -0x694(%rbp)
leaq -0x610(%rbp), %rdi
callq 0x31d0
leaq -0x5f0(%rbp), %rdi
callq 0x3170
movl -0x694(%rbp), %eax
testl %eax, %eax
je 0x4780
jmp 0x477b
jmp 0x4a74
jmp 0x4782
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
movq %rdi, -0x7a8(%rbp)
callq 0x5270
movq -0x7a8(%rbp), %rdi
movq %rax, -0x7b0(%rbp)
movq -0x450(%rbp), %rsi
callq 0x5270
movq %rax, %rdi
callq 0x3290
movq -0x7a8(%rbp), %rdi
movq %rax, -0x6b0(%rbp)
movq -0x450(%rbp), %rsi
callq 0x5270
movq %rax, %rdi
callq 0x31b0
movq %rax, -0x6b8(%rbp)
movl $0x0, -0x6bc(%rbp)
movq -0x6b0(%rbp), %rdi
movq -0x6b8(%rbp), %rsi
leaq -0x6bc(%rbp), %rdx
callq 0x50c0
movq %rax, -0x7a0(%rbp)
jmp 0x4814
movq -0x7a0(%rbp), %rax
movq %rax, -0x6a8(%rbp)
leaq -0x6a0(%rbp), %rdi
leaq -0x6a8(%rbp), %rsi
callq 0x5110
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
callq 0x5270
movq %rax, %rdi
callq 0x31b0
movq %rax, -0x6d0(%rbp)
leaq -0x6c8(%rbp), %rdi
leaq -0x6d0(%rbp), %rsi
callq 0x5110
movq -0x7b0(%rbp), %rdi
movq -0x6a0(%rbp), %rsi
movq -0x6c8(%rbp), %rdx
callq 0x3080
movq %rax, -0x7b8(%rbp)
jmp 0x488d
movq -0x7b8(%rbp), %rax
movq %rax, -0x6d8(%rbp)
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
callq 0x5270
movq %rax, %rdi
leaq 0x378a(%rip), %rsi      # 0x8042
xorl %eax, %eax
movl %eax, %edx
callq 0x3540
cmpq $-0x1, %rax
je 0x4a5b
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
movq %rdi, -0x7d0(%rbp)
callq 0x5270
movq -0x7d0(%rbp), %rdi
movq %rax, -0x7c8(%rbp)
movq -0x450(%rbp), %rsi
callq 0x5270
movq %rax, %rdi
leaq 0x3745(%rip), %rsi      # 0x804e
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x7c0(%rbp)
callq 0x3540
movq -0x7c8(%rbp), %rdi
movq -0x7c0(%rbp), %rsi
movq %rax, %rdx
incq %rdx
callq 0x3090
jmp 0x4934
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
movq %rdi, -0x7e0(%rbp)
callq 0x5270
movq -0x7e0(%rbp), %rdi
movq %rax, -0x7d8(%rbp)
movq -0x450(%rbp), %rsi
callq 0x5270
movq %rax, %rdi
leaq 0x36d0(%rip), %rsi      # 0x8042
xorl %eax, %eax
movl %eax, %edx
callq 0x3540
movq -0x7d8(%rbp), %rdi
movq %rax, %rsi
addq $0xb, %rsi
movq $-0x1, %rdx
callq 0x3090
jmp 0x4997
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
callq 0x5270
movq %rax, %rdi
leaq 0x369a(%rip), %rsi      # 0x804e
xorl %eax, %eax
movl %eax, %edx
callq 0x3540
cmpq $-0x1, %rax
je 0x4a2e
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
movq %rdi, -0x7f8(%rbp)
callq 0x5270
movq -0x7f8(%rbp), %rdi
movq %rax, -0x7f0(%rbp)
movq -0x450(%rbp), %rsi
callq 0x5270
movq %rax, %rdi
leaq 0x364d(%rip), %rsi      # 0x804e
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x7e8(%rbp)
callq 0x3540
movq -0x7f0(%rbp), %rdi
movq -0x7e8(%rbp), %rsi
movq %rax, %rdx
incq %rdx
callq 0x3090
jmp 0x4a2c
jmp 0x4a2e
movq -0x450(%rbp), %rsi
leaq -0x420(%rbp), %rdi
callq 0x5270
movq -0x700(%rbp), %rdi
movq %rax, %rsi
addq $0x238, %rdi            # imm = 0x238
callq 0x3040
jmp 0x4a59
jmp 0x4a5b
jmp 0x4a5d
movq -0x450(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x450(%rbp)
jmp 0x42d0
cmpl $0x2, -0x444(%rbp)
jne 0x4c92
movq -0x700(%rbp), %rdi
addq $0x238, %rdi            # imm = 0x238
callq 0x3470
testb $0x1, %al
jne 0x4c92
movq -0x700(%rbp), %rax
cmpl $0x0, 0x228(%rax)
je 0x4c92
movq -0x700(%rbp), %rax
cmpl $0x0, 0x22c(%rax)
je 0x4c92
movq -0x700(%rbp), %rsi
movq %rsi, %rdi
addq $0x20, %rdi
addq $0x238, %rsi            # imm = 0x238
callq 0x32b0
movq %rax, -0x800(%rbp)
jmp 0x4ae7
movq -0x800(%rbp), %rdi
leaq 0x355b(%rip), %rsi      # 0x8050
callq 0x32e0
jmp 0x4afc
movq -0x700(%rbp), %rax
movl $0x1, -0x6dc(%rbp)
movl 0x228(%rax), %eax
movl $0x2710, %ecx           # imm = 0x2710
cltd
idivl %ecx
movl %eax, %ecx
movq -0x700(%rbp), %rax
movl %ecx, -0x6e0(%rbp)
movl 0x220(%rax), %eax
movl $0x2710, %ecx           # imm = 0x2710
cltd
idivl %ecx
movl %eax, %ecx
movq -0x700(%rbp), %rax
movl %ecx, -0x6e4(%rbp)
movl 0x228(%rax), %eax
imull $0x2710, -0x6e0(%rbp), %ecx # imm = 0x2710
subl %ecx, %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x700(%rbp), %rax
movl %ecx, -0x6e8(%rbp)
movl 0x220(%rax), %eax
imull $0x2710, -0x6e4(%rbp), %ecx # imm = 0x2710
subl %ecx, %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, -0x6ec(%rbp)
movl -0x6e0(%rbp), %eax
cmpl -0x6e4(%rbp), %eax
jg 0x4bf0
movl -0x6e0(%rbp), %eax
cmpl -0x6e4(%rbp), %eax
jge 0x4bc4
movl -0x6e4(%rbp), %eax
movl %eax, -0x6e0(%rbp)
movl -0x6ec(%rbp), %eax
movl %eax, -0x6e8(%rbp)
movq -0x700(%rbp), %rdx
movl -0x6e8(%rbp), %eax
movl -0x6ec(%rbp), %ecx
movswl 0x230(%rdx), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jle 0x4bee
movl $0x0, -0x6dc(%rbp)
jmp 0x4bfa
movl $0x0, -0x6dc(%rbp)
movq -0x700(%rbp), %rcx
movl 0x22c(%rcx), %eax
cmpl 0x224(%rcx), %eax
jge 0x4c19
movl $0x0, -0x6dc(%rbp)
cmpl $0x0, -0x6dc(%rbp)
jne 0x4c59
movq -0x700(%rbp), %rdi
addq $0x20, %rdi
leaq 0x341e(%rip), %rsi      # 0x8052
callq 0x32e0
movq %rax, -0x808(%rbp)
jmp 0x4c42
movq -0x808(%rbp), %rdi
movq 0x6368(%rip), %rsi      # 0xafb8
callq 0x3310
jmp 0x4c57
jmp 0x4c90
movq -0x700(%rbp), %rdi
addq $0x20, %rdi
leaq 0x33cf(%rip), %rsi      # 0x803a
callq 0x32e0
movq %rax, -0x810(%rbp)
jmp 0x4c79
movq -0x810(%rbp), %rdi
movq 0x6331(%rip), %rsi      # 0xafb8
callq 0x3310
jmp 0x4c8e
jmp 0x4c90
jmp 0x4c92
leaq -0x440(%rbp), %rdi
callq 0x31d0
leaq -0x420(%rbp), %rdi
callq 0x52d0
leaq -0x408(%rbp), %rdi
callq 0x3230
jmp 0x4cde
leaq -0x440(%rbp), %rdi
callq 0x31d0
leaq -0x420(%rbp), %rdi
callq 0x52d0
leaq -0x408(%rbp), %rdi
callq 0x3230
jmp 0x4d04
jmp 0x40d1
leaq -0x260(%rbp), %rdi
callq 0x31d0
leaq -0x210(%rbp), %rdi
callq 0x6f20
addq $0x810, %rsp            # imm = 0x810
popq %rbp
retq
leaq -0x260(%rbp), %rdi
callq 0x31d0
leaq -0x210(%rbp), %rdi
callq 0x6f20
movq -0x238(%rbp), %rdi
callq 0x34b0
nopl (%rax,%rax)