// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movl %edx, %ebp
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
callq 0x1f720
movl %eax, %r12d
leaq 0x1(%r14), %rax
movq %rax, 0x8(%rsp)
movq 0x17eba(%rip), %rbx     # 0x46f48
leaq 0x20(%rsp), %r13
movl %r12d, 0x14(%rsp)
movzbl (%r14), %edi
movzwl (%rbx), %r8d
movl $0x72, %esi
movl $0x2, %edx
movq 0x8(%rsp), %rcx
callq 0x1f630
movzbl 0x1(%r14), %eax
shll $0x8, %eax
movzbl 0x2(%r14), %ecx
movswl %ax, %r15d
orl %ecx, %r15d
cmpl %ebp, %r15d
jle 0x2f1b4
movswl %r15w, %eax
cmpl $0xc9, %eax
jl 0x2f138
movzbl (%r14), %edi
movl $0x6a, %esi
movl $0x2, %edx
movl $0x1, %ecx
callq 0x1f980
movzbl (%r14), %edi
movzwl (%rbx), %r8d
movl $0x72, %esi
movl $0x2, %edx
movq 0x8(%rsp), %rcx
callq 0x1f630
movzwl 0x1(%r14), %r15d
rolw $0x8, %r15w
testw %r15w, %r15w
jne 0x2f1ba
callq 0x1f720
subl %r12d, %eax
cmpl $0x2af9, %eax           # imm = 0x2AF9
jb 0x2f0f4
jmp 0x2f1f7
movzbl (%r14), %edi
movzwl (%rbx), %r8d
movl $0x72, %esi
movl $0x2, %edx
movq 0x8(%rsp), %rcx
callq 0x1f630
movzbl 0x1(%r14), %eax
shll $0x8, %eax
movzbl 0x2(%r14), %ecx
movswl %ax, %r15d
orl %ecx, %r15d
cmpl %ebp, %r15d
jle 0x2f1af
subw %bp, %r15w
je 0x2f138
cmpw $0x20, %r15w
movl $0x20, %r12d
cmovll %r15d, %r12d
testb %r12b, %r12b
je 0x2f1a2
movzbl (%r14), %edi
movzwl (%rbx), %r8d
movzbl %r12b, %edx
movl $0x74, %esi
movq %r13, %rcx
callq 0x1f630
jmp 0x2f1a7
movb $0x0, 0x20(%rsp)
subw %r12w, %r15w
jne 0x2f173
jmp 0x2f138
movl 0x14(%rsp), %r12d
testw %r15w, %r15w
je 0x2f1f7
callq 0x1f720
subl %r12d, %eax
cmpl $0x2af8, %eax           # imm = 0x2AF8
ja 0x2f1f7
movswl %r15w, %eax
cmpl %ebp, %eax
jne 0x2f098
testb %bpl, %bpl
je 0x2f208
movzbl (%r14), %edi
movzwl (%rbx), %r8d
movzbl %bpl, %edx
movl $0x74, %esi
movq 0x18(%rsp), %rcx
callq 0x1f630
jmp 0x2f210
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rax
movb $0x0, (%rax)
movb $0x1, %al
jmp 0x2f1f9