// File: Marm0t[P]dji-phantom3-parser/packet.cpp
// Function: Packet::dateFromFourBytes[abi:cxx11](unsigned char const*)
string Packet::dateFromFourBytes(const uint8_t* iBytes)
{
    // NOTE: it's only for test purpose!
    // We are not sure that date and time envoded in this particular format!!!

    //Convert 4 bytes to datetime according to this rule
    // YYYYYYYMMMMDDDDDHHHHMMMMMMSSSSSS
    //    7     4   5    4    6     6  
    // stored as little endian 32bit unsigned integer
    
    unsigned int aValue;
    memcpy(&aValue, iBytes, sizeof(unsigned int)); 
    
    int sec = aValue &  0x3f; //0x3F(16) = 0011 1111 (2)
    aValue = aValue >> 6; // move to minutes
    int min = aValue & 0x3f;
    aValue = aValue >> 6; // move to hours
    int hour = aValue & 0xf; // 0xf = 1111
    aValue = aValue >> 4; // move to day
    int day = aValue & 0x1f; // 0x1f = 0001 1111
    aValue = aValue >> 5; // move to month
    int month = aValue & 0xf; // 0xf = 1111
    aValue = aValue >> 4; // ove to year
    int year = aValue & 0x7F; // 0x7F = 0011 1111
    stringstream ss;
    ss << day<<"/"<<month<<"/"<<year<<" "
       << hour<<":"<<min<<":"<<sec;
    return ss.str();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x1e0(%rbp)
movq %rdi, %rax
movq %rax, -0x1d8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
shrl $0x6, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
shrl $0x6, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x20(%rbp)
movl -0x14(%rbp), %eax
shrl $0x4, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0x1f, %eax
movl %eax, -0x24(%rbp)
movl -0x14(%rbp), %eax
shrl $0x5, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x28(%rbp)
movl -0x14(%rbp), %eax
shrl $0x4, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0x7f, %eax
movl %eax, -0x2c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x2110
leaq -0x1a8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x2300
movq %rax, -0x1d0(%rbp)
jmp 0x4714
movq -0x1d0(%rbp), %rdi
leaq 0x2a6e(%rip), %rsi      # 0x7190
callq 0x21b0
movq %rax, -0x1e8(%rbp)
jmp 0x4730
movq -0x1e8(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x2300
movq %rax, -0x1f0(%rbp)
jmp 0x4748
movq -0x1f0(%rbp), %rdi
leaq 0x2a3a(%rip), %rsi      # 0x7190
callq 0x21b0
movq %rax, -0x1f8(%rbp)
jmp 0x4764
movq -0x1f8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x2300
movq %rax, -0x200(%rbp)
jmp 0x477c
movq -0x200(%rbp), %rdi
leaq 0x2b1c(%rip), %rsi      # 0x72a6
callq 0x21b0
movq %rax, -0x208(%rbp)
jmp 0x4798
movq -0x208(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x2300
movq %rax, -0x210(%rbp)
jmp 0x47b0
movq -0x210(%rbp), %rdi
leaq 0x2b68(%rip), %rsi      # 0x7326
callq 0x21b0
movq %rax, -0x218(%rbp)
jmp 0x47cc
movq -0x218(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x2300
movq %rax, -0x220(%rbp)
jmp 0x47e4
movq -0x220(%rbp), %rdi
leaq 0x2b34(%rip), %rsi      # 0x7326
callq 0x21b0
movq %rax, -0x228(%rbp)
jmp 0x4800
movq -0x228(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x2300
jmp 0x4811
movq -0x1e0(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x21a0
jmp 0x4826
leaq -0x1b8(%rbp), %rdi
callq 0x2140
movq -0x1d8(%rbp), %rax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c0(%rbp)
movl %eax, -0x1c4(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x2140
movq -0x1c0(%rbp), %rdi
callq 0x2320
nopl (%rax)