// File: /workspace/github_c_makefile_star2_O1/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 0x1a32
cmpl $0x2, %ebp
jl 0x141d
incl %ebp
addq $0x8, %rbx
leaq 0x1c28(%rip), %r14      # 0x3004
leaq 0x1c30(%rip), %r15      # 0x3013
movq (%rbx), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x1040
testl %eax, %eax
je 0x15bd
movq %r12, %rdi
movq %r15, %rsi
callq 0x1040
testl %eax, %eax
jne 0x1412
movl $0x3, %edi
callq 0x1a09
decl %ebp
addq $0x8, %rbx
cmpl $0x2, %ebp
jg 0x13e3
movq 0x3bb4(%rip), %rax      # 0x4fd8
movq (%rax), %rdx
leaq 0x60(%rsp), %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x1140
testq %rax, %rax
je 0x15a9
leaq 0x60(%rsp), %r14
leaq 0x20(%rsp), %r15
movq 0x3b80(%rip), %r12      # 0x4fd0
xorl %ebp, %ebp
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x50(%rsp)
movl $0x0, 0xc(%rsp)
movq %r14, %rdi
leaq 0x1b97(%rip), %rsi      # 0x3016
movq %r15, %rdx
callq 0x1250
movq %rax, %r13
testq %rax, %rax
je 0x14a6
leaq 0x1(%r13), %rdi
leaq 0x1b8e(%rip), %rsi      # 0x3028
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x11b0
movq %r15, %rdi
callq 0x11d0
movq %rax, %rbx
leaq 0x1b73(%rip), %rdi      # 0x302b
movq %r14, %rsi
movq %rax, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x17f1
imulq $0x3e8, %rbx, %rax      # imm = 0x3E8
movslq 0xc(%rsp), %rbx
addq %rax, %rbx
leaq 0x1b6a(%rip), %rdi      # 0x3048
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x17f1
movq %rbx, %rcx
subq %rbp, %rcx
setbe %al
addq $0x2710, %rbp           # imm = 0x2710
cmpq %rbp, %rbx
setae %dl
orb %al, %dl
jne 0x1566
movq %rcx, %rax
shrq $0x3, %rax
movabsq $0x20c49ba5e353f7cf, %rdx # imm = 0x20C49BA5E353F7CF
mulq %rdx
shrq $0x4, %rdx
movq %rdx, 0x10(%rsp)
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
movq %rcx, %rdx
subq %rax, %rdx
imulq $0x3e8, %rdx, %rax      # imm = 0x3E8
movq %rax, 0x18(%rsp)
leaq 0x1b18(%rip), %rdi      # 0x305a
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x17f1
movl $0x1, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
callq 0x1180
jmp 0x157a
leaq 0x1b04(%rip), %rdi      # 0x3071
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x17f1
movq (%r12), %rsi
movq %r14, %rdi
callq 0x1120
movq 0x3a4b(%rip), %rax      # 0x4fd8
movq (%rax), %rdx
movq %r14, %rdi
movl $0x2000, %esi           # imm = 0x2000
callq 0x1140
movq %rbx, %rbp
testq %rax, %rax
jne 0x1452
xorl %eax, %eax
addq $0x2068, %rsp           # imm = 0x2068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a49(%rip), %rdi      # 0x300d
callq 0x1080
xorl %edi, %edi
callq 0x1210