// File: /workspace/github_c_makefile_star2_O3/schroeder-lvb[P]sissm/src/ftrack.c
// Function: ftrackResync
int ftrackResync( ftrackObj *fPtr ) 
{
    int  i, errCode = 1;
    char currFileName[256];
    unsigned long fileSize;
    int fileChanged;

    if ( fPtr != NULL ) {
        errCode = 0;

        ftrackGetFilename( fPtr->fpr, currFileName );

        fileChanged = (0 != strcmp( currFileName, fPtr->baselineFileName ));

        if ( !fileChanged ) {
            fileSize = _ftrackGetFileSize( fPtr );
            if ( fileSize < fPtr->lastFileSize ) {
                fileChanged = 1;
                fPtr->lastFileSize = 0;
            }
            else {
                fPtr->lastFileSize = fileSize;
            }
        }

        if ( fileChanged ) {

            // printf("\n**%s**\n", fPtr->baselineFileName );
            // printf("\nclosing:  **%p**\n", fPtr->fpr );
            // fclose( fPtr->fpr );

	    logPrintf(LOG_LEVEL_INFO, "ftrack", "LogFile resynching due to possible file rotation by host");

#ifdef _WIN32
            // close the current file (if valid)
            if ( fPtr->fpr != NULL ) { fclose ( fPtr->fpr ); fPtr->fpr = NULL; };

            // try to open it up to 3x (3 seconds) before declaring fault
            for ( i=0; i<3; i++ ) {
                if (NULL != (fPtr->fpr = _fsopen( fPtr->originalFileName, "r", _SH_DENYNO ))) break;
                sleep( 1 );
            }
            if ( fPtr->fpr == NULL ) errCode = 1;
#else
            // close the current file (if valid)
            if ( fPtr->fpr != -1 ) { close( fPtr->fpr );  fPtr->fpr = -1; };

            // try to open it up to 3x (3 seconds) before declaring fault
            for ( i=0; i<3; i++ ) {
                if ( -1  != (fPtr->fpr = open( fPtr->baselineFileName, O_RDONLY | O_NONBLOCK | O_NDELAY  ))) break;
                sleep( 1 );
            }
            if ( fPtr->fpr == -1 ) errCode = 1;
#endif
            logPrintf(LOG_LEVEL_INFO, "ftrack", "LogFile reopen base name ::%s:: errCode %d", fPtr->baselineFileName, errCode );
        }
    }
    return( errCode );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
testq %rdi, %rdi
je 0xf5f1
movq %rdi, %r14
movl (%rdi), %edi
leaq 0x90(%rsp), %r15
movq %r15, %rsi
callq 0xf468
leaq 0x404(%r14), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8220
testl %eax, %eax
jne 0xf569
movq %rsp, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8280
movq 0x30(%r15), %rax
cmpq 0x808(%r14), %rax
jae 0xf5f8
movq $0x0, 0x808(%r14)
leaq 0xdf83(%rip), %rsi      # 0x1d4f3
leaq 0xdf83(%rip), %rdx      # 0x1d4fa
movl $0x2, %edi
xorl %eax, %eax
callq 0x1a3e3
movl (%r14), %edi
cmpl $-0x1, %edi
je 0xf597
callq 0x81d0
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
movl $0x3, %r15d
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x800, %esi            # imm = 0x800
xorl %eax, %eax
callq 0x8310
movl %eax, (%r14)
cmpl $-0x1, %eax
jne 0xf5cf
movl $0x1, %edi
callq 0x83a0
decl %r15d
jne 0xf59f
xorl %ebp, %ebp
cmpl $-0x1, (%r14)
sete %bpl
leaq 0xdf1d(%rip), %rsi      # 0x1d4f3
leaq 0xdf56(%rip), %rdx      # 0x1d533
movl $0x2, %edi
movq %rbx, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x1a3e3
jmp 0xf601
movl $0x1, %ebp
jmp 0xf601
movq %rax, 0x808(%r14)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r14
popq %r15
popq %rbp
retq