// File: /workspace/github_c_makefile_star2_O0/canboat[P]canboat/analyzer/analyzer.c
// Function: setSystemClock
void setSystemClock(void)
{
#ifndef SKIP_SETSYSTEMCLOCK
  static uint16_t prevDate        = UINT16_MAX;
  static uint32_t prevTime        = UINT32_MAX;
  const uint32_t  unitspersecond  = 10000;
  const uint32_t  microsperunit   = 100;
  const uint32_t  microspersecond = 1000000;
  const uint32_t  secondsperday   = 86400;
  struct timeval  now;
  struct timeval  gps;
  struct timeval  delta;
  struct timeval  olddelta;

#ifdef HAS_ADJTIME
  const int maxDelta = 30;
#else
  const int maxDelta = 1;
#endif

  logDebug("setSystemClock = %u/%u\n", currentDate, currentTime);

  if (prevDate == UINT16_MAX)
  {
    logDebug("setSystemClock: first time\n");
    prevDate = currentDate;
    prevTime = currentTime;
    return;
  }
  if (prevTime == currentTime && prevDate == currentDate)
  {
    logDebug("System clock not changed\n");
    return;
  }

  if (gettimeofday(&now, 0))
  {
    logError("Can't get system clock\n");
    return;
  }

  gps.tv_sec  = currentDate * secondsperday + currentTime / unitspersecond;
  gps.tv_usec = (currentTime % unitspersecond) * microsperunit;

  if (gps.tv_sec < now.tv_sec - maxDelta || gps.tv_sec > now.tv_sec + maxDelta)
  {
    if (settimeofday(&gps, 0))
    {
      logError("Failed to adjust system clock to %" PRIu64 "/%06u\n", (uint64_t) gps.tv_sec, gps.tv_usec);
      return;
    }
    logDebug("Set system clock to %" PRIu64 "/%06u\n", (uint64_t) gps.tv_sec, gps.tv_usec);
    return;
  }

#ifdef HAS_ADJTIME

  delta.tv_sec  = 0;
  delta.tv_usec = gps.tv_usec - now.tv_usec + microspersecond * (gps.tv_sec - now.tv_sec);

  if (delta.tv_usec < 2000 && delta.tv_usec > -2000)
  {
    logDebug("Forget about small system clock skew %d\n", delta.tv_usec);
    return;
  }

  if (adjtime(&delta, &olddelta))
  {
    logError("Failed to adjust system clock by %d usec\n", delta.tv_usec);
    return;
  }

  if (isLogLevelEnabled(LOG_DEBUG))
  {
    logDebug("Now = %" PRIu64 "/%06u ", (uint64_t) now.tv_sec, now.tv_usec);
    logDebug("GPS = %" PRIu64 "/%06u ", (uint64_t) gps.tv_sec, gps.tv_usec);
    logDebug("Adjusting system clock by %d usec\n", delta.tv_usec);
    if (olddelta.tv_sec || olddelta.tv_usec)
    {
      logDebug("(Old delta not yet completed %" PRIu64 "/%d\n", (uint64_t) olddelta.tv_sec, olddelta.tv_usec);
    }
  }

#endif
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x2710, -0x4(%rbp)     # imm = 0x2710
movl $0x64, -0x8(%rbp)
movl $0xf4240, -0xc(%rbp)    # imm = 0xF4240
movl $0x15180, -0x10(%rbp)   # imm = 0x15180
movl $0x1e, -0x54(%rbp)
movzwl 0x80a3a(%rip), %esi     # 0x8e1dc
movl 0x80a38(%rip), %edx     # 0x8e1e0
leaq 0x1bf89(%rip), %rdi     # 0x29738
movb $0x0, %al
callq 0x22570
movzwl 0x80a17(%rip), %eax     # 0x8e1d4
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0xd7f1
leaq 0x1bf85(%rip), %rdi     # 0x29750
movb $0x0, %al
callq 0x22570
movw 0x80a03(%rip), %ax      # 0x8e1dc
movw %ax, 0x809f4(%rip)      # 0x8e1d4
movl 0x809fa(%rip), %eax     # 0x8e1e0
movl %eax, 0x809ec(%rip)     # 0x8e1d8
jmp 0xd9e2
movl 0x809e1(%rip), %eax     # 0x8e1d8
cmpl 0x809e3(%rip), %eax     # 0x8e1e0
jne 0xd824
movzwl 0x809ce(%rip), %eax     # 0x8e1d4
movzwl 0x809cf(%rip), %ecx     # 0x8e1dc
cmpl %ecx, %eax
jne 0xd824
leaq 0x1bf54(%rip), %rdi     # 0x2976c
movb $0x0, %al
callq 0x22570
jmp 0xd9e2
leaq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb140
cmpl $0x0, %eax
je 0xd849
leaq 0x1bf49(%rip), %rdi     # 0x29786
movb $0x0, %al
callq 0x22620
jmp 0xd9e2
movzwl 0x8098c(%rip), %eax     # 0x8e1dc
imull $0x15180, %eax, %eax    # imm = 0x15180
movl %eax, -0x58(%rbp)
movl 0x80981(%rip), %eax     # 0x8e1e0
movl $0x2710, %ecx           # imm = 0x2710
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movl -0x58(%rbp), %eax
addl %ecx, %eax
movl %eax, %eax
movq %rax, -0x30(%rbp)
movl 0x80965(%rip), %eax     # 0x8e1e0
movl $0x2710, %ecx           # imm = 0x2710
xorl %edx, %edx
divl %ecx
imull $0x64, %edx, %eax
movl %eax, %eax
movq %rax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1e, %rcx
cmpq %rcx, %rax
jl 0xd8af
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
addq $0x1e, %rcx
cmpq %rcx, %rax
jle 0xd8f7
leaq -0x30(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb200
cmpl $0x0, %eax
je 0xd8dc
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq 0x1bece(%rip), %rdi     # 0x2979e
movb $0x0, %al
callq 0x22620
jmp 0xd9e2
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq 0x1bede(%rip), %rdi     # 0x297c9
movb $0x0, %al
callq 0x22570
jmp 0xd9e2
movq $0x0, -0x40(%rbp)
movq -0x28(%rbp), %rax
subq -0x18(%rbp), %rax
movq -0x30(%rbp), %rcx
subq -0x20(%rbp), %rcx
imulq $0xf4240, %rcx, %rcx    # imm = 0xF4240
addq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $0x7d0, -0x38(%rbp)     # imm = 0x7D0
jge 0xd948
cmpq $-0x7d0, -0x38(%rbp)    # imm = 0xF830
jle 0xd948
movq -0x38(%rbp), %rsi
leaq 0x1beab(%rip), %rdi     # 0x297e7
movb $0x0, %al
callq 0x22570
jmp 0xd9e2
leaq -0x40(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xb190
cmpl $0x0, %eax
je 0xd96e
movq -0x38(%rbp), %rsi
leaq 0x1beab(%rip), %rdi     # 0x29810
movb $0x0, %al
callq 0x22620
jmp 0xd9e2
movl $0x7, %edi
callq 0x22880
testb $0x1, %al
jne 0xd97e
jmp 0xd9e2
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq 0x1bead(%rip), %rdi     # 0x2983a
movb $0x0, %al
callq 0x22570
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq 0x1bea7(%rip), %rdi     # 0x2984a
movb $0x0, %al
callq 0x22570
movq -0x38(%rbp), %rsi
leaq 0x1bea5(%rip), %rdi     # 0x2985a
movb $0x0, %al
callq 0x22570
cmpq $0x0, -0x50(%rbp)
jne 0xd9ca
cmpq $0x0, -0x48(%rbp)
je 0xd9e0
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq 0x1bea4(%rip), %rdi     # 0x2987d
movb $0x0, %al
callq 0x22570
jmp 0xd9e2
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)