// File: /workspace/github_c_makefile_star2_O1/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 0xf2b1
movq %rdi, %rbx
movl (%rdi), %edi
leaq 0x90(%rsp), %r15
movq %r15, %rsi
callq 0xf130
leaq 0x404(%rbx), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x8220
testl %eax, %eax
jne 0xf231
movq %rsp, %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x8280
movq 0x30(%r15), %rax
cmpq 0x808(%rbx), %rax
jae 0xf2b8
movq $0x0, 0x808(%rbx)
leaq 0xe2e3(%rip), %rsi      # 0x1d51b
leaq 0xe2e3(%rip), %rdx      # 0x1d522
movl $0x2, %edi
xorl %eax, %eax
callq 0x1a227
movl (%rbx), %edi
cmpl $-0x1, %edi
je 0xf25d
callq 0x81d0
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movl $0x3, %ebp
movq %r14, %rdi
movl $0x800, %esi            # imm = 0x800
xorl %eax, %eax
callq 0x8310
movl %eax, (%rbx)
cmpl $-0x1, %eax
jne 0xf286
movl $0x1, %edi
callq 0x83a0
decl %ebp
jne 0xf262
xorl %ebp, %ebp
cmpl $-0x1, (%rbx)
sete %bpl
leaq 0xe285(%rip), %rsi      # 0x1d51b
leaq 0xe2be(%rip), %rdx      # 0x1d55b
movl $0x2, %edi
movq %r14, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x1a227
jmp 0xf2c1
movl $0x1, %ebp
jmp 0xf2c1
movq %rax, 0x808(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r14
popq %r15
popq %rbp
retq