// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movb %dil, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movq $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3e3a
movq 0x2370f(%rip), %rdi     # 0x274a0
leaq 0x1d36f(%rip), %rsi     # 0x21107
callq 0x3560
movq %rax, %rcx
movq %rcx, -0x10(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x3db0
jmp 0x3e3a
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq 0x23230(%rip), %rax     # 0x26ff0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq 0x236d2(%rip), %rax     # 0x274a0
movq %rax, -0x20(%rbp)
callq 0x3090
movl (%rax), %edi
callq 0x3650
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq %rax, %rcx
leaq 0x1b264(%rip), %rsi     # 0x1f054
movb $0x0, %al
callq 0x3370
cmpl $0x5, -0x14(%rbp)
jle 0x3e2b
movq 0x231ec(%rip), %rax     # 0x26ff0
movq (%rax), %rdi
movq 0x23692(%rip), %rdx     # 0x274a0
leaq 0x1b25c(%rip), %rsi     # 0x1f071
movb $0x0, %al
callq 0x3370
callq 0x3f50
movl $0x1, %edi
callq 0x35f0
movl $0x1, %edi
callq 0x3670
jmp 0x3d7f
movb -0x1(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3e92
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x34b0
cmpl $0x0, %eax
je 0x3e8d
movq 0x2318b(%rip), %rax     # 0x26ff0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
callq 0x3090
movl (%rax), %edi
callq 0x3650
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0x1b216(%rip), %rsi     # 0x1f09c
movb $0x0, %al
callq 0x3370
jmp 0x3f39
movq -0x10(%rbp), %rdi
movq $-0x1, %rsi
movl $0x2, %edx
callq 0x34b0
movq -0x10(%rbp), %rdi
callq 0x3290
movb %al, -0x15(%rbp)
movsbl -0x15(%rbp), %eax
cmpl $0xa, %eax
jne 0x3ee6
movq -0x10(%rbp), %rdi
movq $-0x2, %rsi
movl $0x1, %edx
callq 0x34b0
cmpl $0x0, %eax
je 0x3ed8
jmp 0x3ee6
movq -0x10(%rbp), %rdi
callq 0x3290
movb %al, -0x15(%rbp)
jmp 0x3eb3
jmp 0x3ee8
movsbl -0x15(%rbp), %eax
cmpl $0xa, %eax
je 0x3f1b
movq -0x10(%rbp), %rdi
movq $-0x2, %rsi
movl $0x1, %edx
callq 0x34b0
cmpl $0x0, %eax
je 0x3f0d
jmp 0x3f1b
movq -0x10(%rbp), %rdi
callq 0x3290
movb %al, -0x15(%rbp)
jmp 0x3ee8
movsbl -0x15(%rbp), %eax
cmpl $0xa, %eax
jne 0x3f37
movq -0x10(%rbp), %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x34b0
jmp 0x3f39
movq -0x10(%rbp), %rax
movq %rax, 0x2371c(%rip)     # 0x27660
movq -0x10(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nop