// File: /workspace/github_cpp_makefile_star2_O2/mrlordkaj[P]i2cdevlib-pi/MPU6050/MPU6050.cpp
// Function: MPU6050::GetCurrentFIFOPacket(unsigned char*, unsigned char)
int8_t MPU6050::GetCurrentFIFOPacket(uint8_t *data, uint8_t length) { // overflow proof
     int16_t fifoC;
     // This section of code is for when we allowed more than 1 packet to be acquired
     uint32_t BreakTimer = micros();
     do {
         if ((fifoC = getFIFOCount())  > length) {

             if (fifoC > 200) { // if you waited to get the FIFO buffer to > 200 bytes it will take longer to get the last packet in the FIFO Buffer than it will take to  reset the buffer and wait for the next to arrive
                 resetFIFO(); // Fixes any overflow corruption
                 fifoC = 0;
                 while (!(fifoC = getFIFOCount()) && ((micros() - BreakTimer) <= (11000))); // Get Next New Packet
                 } else { //We have more than 1 packet but less than 200 bytes of data in the FIFO Buffer
                 uint8_t Trash[BUFFER_LENGTH];
                 while ((fifoC = getFIFOCount()) > length) {  // Test each time just in case the MPU is writing to the FIFO Buffer
                     fifoC = fifoC - length; // Save the last packet
                     uint16_t  RemoveBytes;
                     while (fifoC) { // fifo count will reach zero so this is safe
                         RemoveBytes = min((int)fifoC, BUFFER_LENGTH); // Buffer Length is different than the packet length this will efficiently clear the buffer
                         getFIFOBytes(Trash, (uint8_t)RemoveBytes);
                         fifoC -= RemoveBytes;
                     }
                 }
             }
         }
         if (!fifoC) return 0; // Called too early no data or we timed out after FIFO Reset
         // We have 1 packet
         if ((micros() - BreakTimer) > (11000)) return 0;
     } while (fifoC != length);
     getFIFOBytes(data, length); //Get 1 packet
     return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebp
movq %rsi, 0x8(%rsp)
movq %rdi, %r14
callq 0x1fa00
movl %eax, (%rsp)
movzwl %bp, %eax
movl %eax, 0x4(%rsp)
pushq $0x20
popq %rbx
leaq 0x10(%rsp), %r12
movq %r14, %rdi
callq 0x1f5f0
movl %eax, %r13d
cwtl
cmpl %ebp, %eax
jle 0x2d888
cmpw $0xc9, %r13w
jl 0x2d84d
movq %r14, %rdi
callq 0x1fe20
movq %r14, %rdi
callq 0x1f5f0
testw %ax, %ax
jne 0x2d8ab
callq 0x1fa00
subl (%rsp), %eax
cmpl $0x2af9, %eax           # imm = 0x2AF9
jb 0x2d82f
jmp 0x2d8b0
movq %r14, %rdi
callq 0x1f5f0
movl %eax, %r13d
cwtl
cmpl %ebp, %eax
jle 0x2d888
subl 0x4(%rsp), %r13d
testw %r13w, %r13w
je 0x2d84d
cmpw $0x20, %r13w
movl %ebx, %r15d
cmovll %r13d, %r15d
movzbl %r15b, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x20030
subl %r15d, %r13d
jmp 0x2d862
testw %r13w, %r13w
je 0x2d8b0
callq 0x1fa00
subl (%rsp), %eax
cmpl $0x2af8, %eax           # imm = 0x2AF8
ja 0x2d8b0
movswl %r13w, %eax
cmpl %ebp, %eax
jne 0x2d80f
jmp 0x2d8c1
movl %eax, %r13d
jmp 0x2d88e
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %bpl, %edx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x20030
movb $0x1, %al
jmp 0x2d8b2