// File: /workspace/github_c_makefile_star2_O1/ddrown[P]pretend-ntp/ntp-loop.c
// Function: main
int main(int argc, char *argv[]) {
  int sock, opt;
  struct ntp_msg bufs;
  struct sockaddr_in addr;
  struct ntptimes t;
  struct msghdr msgs;
  int status;
  uint8_t cmsgbuf[256];
  uint8_t lines = 0;
  uint32_t stop;

  if(argc < 4) {
    printf("%s [ip] [port] [stop]\n", argv[0]);
    exit(1);
  }
  if(inet_aton(argv[1], &addr.sin_addr) == INADDR_NONE) {
    printf("invalid ip %s\n", argv[1]);
    exit(1);
  }
  stop = strtoul(argv[3], NULL, 10);
  addr.sin_family = AF_INET;

  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock == -1) {
    perror_exit("socket");
  }
  opt = 1;
  if(setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt)) < 0) {
    perror_exit("setsockopt(IP_PKTINFO)");
  }
  addr.sin_port = htons(strtoul(argv[2], NULL, 10));

  memset(&msgs, 0, sizeof(msgs));
  msgs.msg_control    = cmsgbuf;
  msgs.msg_controllen = sizeof(cmsgbuf);

  for(uint32_t i = 0; i < stop; i++) {
    if(!lines) {
      printf("%20s %8s %8s %12s %12s %12s %12s %12s\n","ts","r.delay", "disper", "send", "recv", "proc", "sendto", "recvmsg");
      lines = 80;
    }
    lines--;
    ntp_request(&bufs);

    status = ntp_xchange(sock,&bufs,(struct sockaddr *)&addr,&t,&msgs,DEFAULT_TIMEOUT_MS);

    if(status > 0) {
      print_t(&t.before_sendto);
      printf(" ");

      print_short_ntp(&bufs, &t);
    }

    printf(" ");
    print_diff_ts(&t.after_sendto, &t.before_sendto);
    printf(" ");
    print_diff_ts(&t.after_recvmsg, &t.before_sendto);
    printf("\n");
    fflush(stdout);
    sleep(1);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rsi, %r14
cmpl $0x3, %edi
jle 0x1434
movq 0x8(%r14), %rdi
leaq 0x10(%rsp), %rsi
callq 0x1090
cmpl $-0x1, %eax
je 0x1440
movq 0x18(%r14), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x10e0
movq %rax, %rbx
movw $0x2, 0xc(%rsp)
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x1110
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x128e
leaq 0xda1(%rip), %rdi       # 0x202a
callq 0x1ad0
leaq 0x1c(%rsp), %rcx
movl $0x1, (%rcx)
movl %ebp, %edi
xorl %esi, %esi
movl $0x8, %edx
movl $0x4, %r8d
callq 0x1050
testl %eax, %eax
jns 0x12bd
leaq 0xd79(%rip), %rdi       # 0x2031
callq 0x1ad0
movq 0x10(%r14), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x10e0
rolw $0x8, %ax
movw %ax, 0xe(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x50(%rsp)
leaq 0xc0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq $0x100, 0x48(%rsp)      # imm = 0x100
testl %ebx, %ebx
je 0x1420
xorl %r13d, %r13d
leaq 0x90(%rsp), %r12
leaq 0x60(%rsp), %r14
movq 0x2cba(%rip), %r15      # 0x3fe0
testb %r13b, %r13b
jne 0x1382
subq $0x8, %rsp
leaq 0xd12(%rip), %rdi       # 0x2048
leaq 0xd32(%rip), %rsi       # 0x206f
leaq 0xd2e(%rip), %rdx       # 0x2072
leaq 0xd2f(%rip), %rcx       # 0x207a
leaq 0xd2f(%rip), %r8        # 0x2081
leaq 0xd2d(%rip), %r9        # 0x2086
xorl %eax, %eax
leaq 0xd35(%rip), %r10       # 0x2097
pushq %r10
leaq 0xd25(%rip), %r10       # 0x2090
pushq %r10
leaq 0xd17(%rip), %r10       # 0x208b
pushq %r10
callq 0x1070
addq $0x20, %rsp
movb $0x50, %r13b
movq %r12, %rdi
callq 0x184b
movl %ebp, %edi
movq %r12, %rsi
leaq 0xc(%rsp), %rdx
movq %r14, %rcx
leaq 0x20(%rsp), %r8
movl $0x1f4, %r9d            # imm = 0x1F4
callq 0x18aa
testl %eax, %eax
jle 0x13c8
movq %r14, %rdi
callq 0x19f4
movl $0x20, %edi
callq 0x1030
movq %r12, %rdi
movq %r14, %rsi
callq 0x172b
decb %r13b
movl $0x20, %edi
callq 0x1030
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x1a72
movl $0x20, %edi
callq 0x1030
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
callq 0x1a72
movl $0xa, %edi
callq 0x1030
movq (%r15), %rdi
callq 0x10a0
movl $0x1, %edi
callq 0x1100
decl %ebx
jne 0x1326
xorl %eax, %eax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rsi
leaq 0xbc6(%rip), %rdi       # 0x2004
jmp 0x144b
movq 0x8(%r14), %rsi
leaq 0xbd0(%rip), %rdi       # 0x201b
xorl %eax, %eax
callq 0x1070
movl $0x1, %edi
callq 0x10f0