// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x1d1(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x12a5
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0xd70(%rip), %rdi       # 0x2004
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x1120
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x58(%rbp), %rsi
addq $0x4, %rsi
callq 0x10b0
cmpl $-0x1, %eax
jne 0x12df
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xd4d(%rip), %rdi       # 0x201b
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x1120
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x1110
movl %eax, -0x1d8(%rbp)
movw $0x2, -0x58(%rbp)
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x1150
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
jne 0x1324
leaq 0xd0b(%rip), %rdi       # 0x202a
callq 0x1df0
movl $0x1, -0x18(%rbp)
movl -0x14(%rbp), %edi
xorl %esi, %esi
movl $0x8, %edx
leaq -0x18(%rbp), %rcx
movl $0x4, %r8d
callq 0x1040
cmpl $0x0, %eax
jge 0x1355
leaq 0xce1(%rip), %rdi       # 0x2031
callq 0x1df0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x1110
movzwl %ax, %edi
callq 0x1060
movw %ax, -0x56(%rbp)
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x1090
leaq -0x1d0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq $0x100, -0x98(%rbp) # imm = 0x100
movl $0x0, -0x1dc(%rbp)
movl -0x1dc(%rbp), %eax
cmpl -0x1d8(%rbp), %eax
jae 0x151c
cmpb $0x0, -0x1d1(%rbp)
jne 0x1423
leaq 0xc79(%rip), %rdi       # 0x2048
leaq 0xc99(%rip), %rsi       # 0x206f
leaq 0xc95(%rip), %rdx       # 0x2072
leaq 0xc96(%rip), %rcx       # 0x207a
leaq 0xc96(%rip), %r8        # 0x2081
leaq 0xc94(%rip), %r9        # 0x2086
leaq 0xc92(%rip), %r11       # 0x208b
leaq 0xc90(%rip), %r10       # 0x2090
leaq 0xc90(%rip), %rax       # 0x2097
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x1070
movb $0x50, -0x1d1(%rbp)
movb -0x1d1(%rbp), %al
addb $-0x1, %al
movb %al, -0x1d1(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x1a90
movl -0x14(%rbp), %edi
leaq -0x48(%rbp), %rsi
leaq -0x58(%rbp), %rdx
leaq -0x88(%rbp), %rcx
leaq -0xc0(%rbp), %r8
movl $0x1f4, %r9d            # imm = 0x1F4
callq 0x1b10
movl %eax, -0xc4(%rbp)
cmpl $0x0, -0xc4(%rbp)
jle 0x1497
leaq -0x88(%rbp), %rdi
callq 0x1c70
leaq 0xd65(%rip), %rdi       # 0x21e5
movb $0x0, %al
callq 0x1070
leaq -0x48(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x1960
leaq 0xd47(%rip), %rdi       # 0x21e5
movb $0x0, %al
callq 0x1070
leaq -0x88(%rbp), %rdi
addq $0x10, %rdi
leaq -0x88(%rbp), %rsi
callq 0x1d60
leaq 0xd22(%rip), %rdi       # 0x21e5
movb $0x0, %al
callq 0x1070
leaq -0x88(%rbp), %rdi
addq $0x20, %rdi
leaq -0x88(%rbp), %rsi
callq 0x1d60
leaq 0xb31(%rip), %rdi       # 0x2019
movb $0x0, %al
callq 0x1070
movq 0x2aea(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x10c0
movl $0x1, %edi
callq 0x1140
movl -0x1dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1dc(%rbp)
jmp 0x13ad
movl -0x4(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
nopl (%rax,%rax)