// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/unifi-motion.c
// Function: open_log
FILE *open_log(bool seekBackOneLine)
{
  FILE *fp = NULL;
  int i=0;

  // Try to open log file a number of times, with pause inbetween.  Do this for logroatate
  // as the file may get moved and not re-created for a small period of time.
  while (fp == NULL)
  {
    if ( NULL != (fp = fopen(_config.log_file_to_monitor, "r")))
      break;
    
    i++;
    fprintf(stderr, "Open log file '%s' error\n%s\n", _config.log_file_to_monitor, strerror(errno));
    
    if (i > LOGFILE_OPEN_TRIES) {
      fprintf(stderr, "ERROR: Can't open logfile '%s', giving up\n", _config.log_file_to_monitor);
      cleanup();
      exit(EXIT_FAILURE);
    }
    sleep(1);
  }

  if (seekBackOneLine == false)
  {
    if (fseek(fp, 0L, SEEK_END) != 0)
    {
      fprintf(stderr, "Seek to end of file log error\n%s\n", strerror(errno));
    }
  }
  else
  {
    char c;
    fseek(fp, -1, SEEK_END); //next to last char, last is EOF
    c = fgetc(fp);
    
    while (c == '\n') //define macro EOL
    {
      if (fseek(fp, -2, SEEK_CUR) != 0){break;}
      c = fgetc(fp);
    }
    while (c != '\n')
    {
      if (fseek(fp, -2, SEEK_CUR) != 0){break;}
      c = fgetc(fp);
    }
    if (c == '\n')
      fseek(fp, 1, SEEK_CUR);
  }

  _umHandles.logfile = fp;
  return fp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebp
pushq $0x5
popq %r15
leaq 0x125b2(%rip), %r14     # 0x16120
pushq $0x1
popq %r12
movq 0x1a857(%rip), %rdi     # 0x1e3d0
movq %r14, %rsi
callq 0x3520
testq %rax, %rax
jne 0x3bce
movq 0x1a463(%rip), %rax     # 0x1dff0
movq (%rax), %rbx
movq 0x1a839(%rip), %r13     # 0x1e3d0
callq 0x30a0
movl (%rax), %edi
callq 0x3600
movq %rbx, %rdi
leaq 0x104a7(%rip), %rsi     # 0x14054
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3340
subl $0x1, %r15d
jb 0x3c9c
movl %r12d, %edi
callq 0x3620
jmp 0x3b72
movq %rax, %rbx
testb %bpl, %bpl
je 0x3c38
pushq $-0x1
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x3480
pushq $-0x2
popq %r14
pushq $0x1
popq %rbp
movq %rbx, %rdi
callq 0x3270
movl %eax, %r15d
cmpb $0xa, %r15b
jne 0x3c0d
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x3480
testl %eax, %eax
je 0x3beb
pushq $-0x2
popq %r14
pushq $0x1
popq %rbp
cmpb $0xa, %r15b
je 0x3c75
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x3480
testl %eax, %eax
jne 0x3c83
movq %rbx, %rdi
callq 0x3270
movl %eax, %r15d
jmp 0x3c14
pushq $0x2
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3480
testl %eax, %eax
je 0x3c83
movq 0x1a3a0(%rip), %rax     # 0x1dff0
movq (%rax), %r14
callq 0x30a0
movl (%rax), %edi
callq 0x3600
leaq 0x10436(%rip), %rsi     # 0x1409c
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3340
jmp 0x3c83
pushq $0x1
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x3480
movq %rbx, 0x1a906(%rip)     # 0x1e590
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1a34d(%rip), %rax     # 0x1dff0
movq (%rax), %rdi
movq 0x1a723(%rip), %rdx     # 0x1e3d0
leaq 0x103bd(%rip), %rsi     # 0x14071
xorl %eax, %eax
callq 0x3340
callq 0x3cc8
pushq $0x1
popq %rdi
callq 0x35b0