// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movl $0x1, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x11fed
movl $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %edi
leaq -0x110(%rbp), %rsi
callq 0x11d70
leaq -0x110(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x404, %rsi            # imm = 0x404
callq 0x8200
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x11c(%rbp)
cmpl $0x0, -0x11c(%rbp)
jne 0x11f21
movq -0x8(%rbp), %rdi
callq 0x11e20
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x808(%rcx), %rax
jae 0x11f0d
movl $0x1, -0x11c(%rbp)
movq -0x8(%rbp), %rax
movq $0x0, 0x808(%rax)
jmp 0x11f1f
movq -0x118(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x808(%rax)
jmp 0x11f21
cmpl $0x0, -0x11c(%rbp)
je 0x11feb
movl $0x2, %edi
leaq 0x135e1(%rip), %rsi     # 0x2551b
leaq 0x135e1(%rip), %rdx     # 0x25522
movb $0x0, %al
callq 0x21bf0
movq -0x8(%rbp), %rax
cmpl $-0x1, (%rax)
je 0x11f66
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0x81c0
movq -0x8(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0xc(%rbp)
cmpl $0x3, -0xc(%rbp)
jge 0x11fb2
movq -0x8(%rbp), %rdi
addq $0x404, %rdi            # imm = 0x404
movl $0x800, %esi            # imm = 0x800
movb $0x0, %al
callq 0x8300
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
je 0x11f9d
jmp 0x11fb2
movl $0x1, %edi
callq 0x8380
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x11f6d
movq -0x8(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x11fc2
movl $0x1, -0x10(%rbp)
movq -0x8(%rbp), %rcx
addq $0x404, %rcx            # imm = 0x404
movl -0x10(%rbp), %r8d
movl $0x2, %edi
leaq 0x1353e(%rip), %rsi     # 0x2551b
leaq 0x13577(%rip), %rdx     # 0x2555b
movb $0x0, %al
callq 0x21bf0
jmp 0x11fed
movl -0x10(%rbp), %eax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax)