// File: /workspace/github_c_makefile_star2_O0/ddrown[P]pretend-ntp/pretend-ntp.c
// Function: main
int main(int argc, char *argv[]) {
  struct sockaddr_in addr;
  struct thread_info tinfo[THREADS];
  int status;

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

  memset(&tinfo, 0, sizeof(tinfo));

  for (uint32_t i = 0; i < THREADS; i++) {
    tinfo[i].thread_num = i;
    tinfo[i].addr = &addr;
    status = pthread_create(&tinfo[i].thread_id, NULL, &ntp_server, &tinfo[i]);
    if (status != 0) {
      errno = status;
      perror("pthread_create(ntp_server) failed");
      exit(EXIT_FAILURE);
    }
  }

  printf("threads created\n");

  for(uint32_t i = 0; i < THREADS; i++) {
    void *res;
    status = pthread_join(tinfo[i].thread_id, &res);
    if (status != 0) {
      errno = status;
      perror("pthread_join(ntp_server) failed");
      exit(EXIT_FAILURE);
    }

    printf("reader thread %d done q=%" UINT64_FMT " !v=%" UINT64_FMT " !m=%" UINT64_FMT " ~s=%" UINT64_FMT "\n", tinfo[i].thread_num, tinfo[i].thread_queries,
        tinfo[i].unknown_version, tinfo[i].unknown_mode, tinfo[i].failed_send);
  }

  exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x3, -0x8(%rbp)
jge 0x169e
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x1a2a(%rip), %rdi      # 0x30b7
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x1160
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x20(%rbp), %rsi
addq $0x4, %rsi
callq 0x10d0
cmpl $-0x1, %eax
jne 0x16d8
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x1a00(%rip), %rdi      # 0x30c7
movb $0x0, %al
callq 0x1070
movl $0x1, %edi
callq 0x1160
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x1150
movzwl %ax, %edi
callq 0x1060
movw %ax, -0x1e(%rbp)
movw $0x2, -0x20(%rbp)
leaq -0x100(%rbp), %rdi
xorl %esi, %esi
movl $0xe0, %edx
callq 0x1090
movl $0x0, -0x108(%rbp)
cmpl $0x4, -0x108(%rbp)
jae 0x17f3
movl -0x108(%rbp), %ecx
movl -0x108(%rbp), %eax
movl %eax, %edx
leaq -0x100(%rbp), %rax
imulq $0x38, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x108(%rbp), %eax
movl %eax, %ecx
leaq -0x100(%rbp), %rax
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
leaq -0x20(%rbp), %rcx
movq %rcx, 0x30(%rax)
movl -0x108(%rbp), %eax
leaq -0x100(%rbp), %rdi
imulq $0x38, %rax, %rax
addq %rax, %rdi
movl -0x108(%rbp), %eax
leaq -0x100(%rbp), %rcx
imulq $0x38, %rax, %rax
addq %rax, %rcx
xorl %eax, %eax
movl %eax, %esi
leaq -0x4fa(%rip), %rdx      # 0x12a0
callq 0x1130
movl %eax, -0x104(%rbp)
cmpl $0x0, -0x104(%rbp)
je 0x17dd
movl -0x104(%rbp), %eax
movl %eax, -0x11c(%rbp)
callq 0x1030
movl -0x11c(%rbp), %ecx
movl %ecx, (%rax)
leaq 0x1908(%rip), %rdi      # 0x30d6
callq 0x1140
movl $0x1, %edi
callq 0x1160
jmp 0x17df
movl -0x108(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x108(%rbp)
jmp 0x171d
leaq 0x18fe(%rip), %rdi      # 0x30f8
movb $0x0, %al
callq 0x1070
movl $0x0, -0x10c(%rbp)
cmpl $0x4, -0x10c(%rbp)
jae 0x191e
movl -0x10c(%rbp), %eax
movl %eax, %ecx
leaq -0x100(%rbp), %rax
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
leaq -0x118(%rbp), %rsi
callq 0x1170
movl %eax, -0x104(%rbp)
cmpl $0x0, -0x104(%rbp)
je 0x187b
movl -0x104(%rbp), %eax
movl %eax, -0x120(%rbp)
callq 0x1030
movl -0x120(%rbp), %ecx
movl %ecx, (%rax)
leaq 0x189d(%rip), %rdi      # 0x3109
callq 0x1140
movl $0x1, %edi
callq 0x1160
movl -0x10c(%rbp), %eax
movl %eax, %ecx
leaq -0x100(%rbp), %rax
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
movl -0x10c(%rbp), %eax
movl %eax, %ecx
leaq -0x100(%rbp), %rax
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdx
movl -0x10c(%rbp), %eax
movl %eax, %ecx
leaq -0x100(%rbp), %rax
imulq $0x38, %rcx, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rcx
movl -0x10c(%rbp), %eax
movl %eax, %edi
leaq -0x100(%rbp), %rax
imulq $0x38, %rdi, %rdi
addq %rdi, %rax
movq 0x20(%rax), %r8
movl -0x10c(%rbp), %eax
movl %eax, %edi
leaq -0x100(%rbp), %rax
imulq $0x38, %rdi, %rdi
addq %rdi, %rax
movq 0x28(%rax), %r9
leaq 0x1826(%rip), %rdi      # 0x3129
movb $0x0, %al
callq 0x1070
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0x180b
xorl %edi, %edi
callq 0x1160
nopw %cs:(%rax,%rax)
nop