// File: /workspace/github_c_makefile_star2_O2/canboat[P]canboat/replay/replay.c
// Function: main
int main(int argc, char **argv)
{
  char      line[8192];
  struct tm tm;
  char     *r;
  int       ms;
  uint64_t  now;
  uint64_t  prev = UINT64_C(0);

  setProgName(argv[0]);
  while (argc > 1)
  {
    if (strcasecmp(argv[1], "-version") == 0)
    {
      printf("%s\n", VERSION);
      exit(0);
    }
    else if (strcasecmp(argv[1], "-d") == 0)
    {
      setLogLevel(LOGLEVEL_DEBUG);
    }
    argc--;
    argv++;
  }

  while (fgets(line, sizeof(line), stdin))
  {
    memset(&tm, 0, sizeof(tm));
    ms = 0;

    r = strptime(line, FORMAT_DT, &tm);
    if (r)
    {
      sscanf(r + 1, FORMAT_MS, &ms);
    }
    now = timegm(&tm);
    logDebug("%-1.24s = %" PRIu64 " s r='%-1.10s'\n", line, now, r);
    now = now * UINT64_C(1000) + ms;
    logDebug("%-1.24s = %" PRIu64 " ms\n", line, now);

    if (now > prev && now < prev + UINT64_C(10000))
    {
      uint64_t       diff    = now - prev;
      struct timeval timeout = {diff / UINT64_C(1000), (diff % UINT64_C(1000)) * UINT64_C(1000)};

      logDebug("%-1.24s = %" PRIu64 " zzz=%" PRIu64 "\n", line, now, diff);
      select(1, NULL, NULL, NULL, &timeout);
    }
    else
    {
      logDebug("%-1.24s = %" PRIu64 "\n", line, now);
    }
    prev = now;

    fprintf(stdout, "%s", line);
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2068, %rsp           # imm = 0x2068
movq %rsi, %rbx
movl %edi, %ebp
movq (%rsi), %rdi
callq 0x19bd
addq $0x8, %rbx
leaq 0x1c2f(%rip), %r14      # 0x3004
leaq 0x1c37(%rip), %r15      # 0x3013
pushq $0x3
popq %r12
cmpl $0x1, %ebp
jle 0x141a
movq (%rbx), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x1040
testl %eax, %eax
je 0x157e
movq %r13, %rdi
movq %r15, %rsi
callq 0x1040
testl %eax, %eax
jne 0x1412
movl %r12d, %edi
callq 0x1996
decl %ebp
addq $0x8, %rbx
jmp 0x13e0
leaq 0x60(%rsp), %rbx
leaq 0x20(%rsp), %r15
movq 0x3ba5(%rip), %r12      # 0x4fd0
xorl %r13d, %r13d
movq 0x3ba3(%rip), %rax      # 0x4fd8
movq (%rax), %rdx
movq %rbx, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x1140
testq %rax, %rax
je 0x156a
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x20(%rsp)
andl $0x0, 0xc(%rsp)
movq %rbx, %rdi
leaq 0x1ba1(%rip), %rsi      # 0x3016
movq %r15, %rdx
callq 0x1250
movq %rax, %rbp
testq %rax, %rax
je 0x149c
leaq 0x1(%rbp), %rdi
leaq 0x1b98(%rip), %rsi      # 0x3028
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x11b0
movq %r15, %rdi
callq 0x11d0
movq %rax, %r14
leaq 0x1b7d(%rip), %rdi      # 0x302b
movq %rbx, %rsi
movq %rax, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x1788
imulq $0x3e8, %r14, %rax      # imm = 0x3E8
movslq 0xc(%rsp), %rbp
addq %rax, %rbp
leaq 0x1b74(%rip), %rdi      # 0x3048
movq %rbx, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1788
movq %rbp, %rcx
subq %r13, %rcx
setbe %al
addq $0x2710, %r13           # imm = 0x2710
cmpq %r13, %rbp
setae %dl
orb %al, %dl
jne 0x1542
movq %rcx, %rax
xorl %edx, %edx
movl $0x3e8, %esi            # imm = 0x3E8
divq %rsi
movq %rax, 0x10(%rsp)
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
movq %rax, 0x18(%rsp)
leaq 0x1b3a(%rip), %rdi      # 0x305a
movq %rbx, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1788
pushq $0x1
popq %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
callq 0x1180
jmp 0x1556
leaq 0x1b28(%rip), %rdi      # 0x3071
movq %rbx, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1788
movq (%r12), %rsi
movq %rbx, %rdi
callq 0x1120
movq %rbp, %r13
jmp 0x142e
xorl %eax, %eax
addq $0x2068, %rsp           # imm = 0x2068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a88(%rip), %rdi      # 0x300d
callq 0x1080
xorl %edi, %edi
callq 0x1210
nopl (%rax)