// File: madpilot[P]mDNSResolver/mocks/WiFiUdp.cpp
// Function: WiFiUDP::loadFromFile(char const*)
WiFiUDP* WiFiUDP::loadFromFile(const char *path) {
  unsigned char *source = NULL;
  WiFiUDP* udp = new WiFiUDP;

  FILE *fp = fopen(path, "rb");

  if(fp != NULL) {
    if(fseek(fp, 0L, SEEK_END) != 0) {
      fprintf(stderr, "ERROR: Unable to seek to the end of the file: %s\n", path);
      fclose(fp);
      return udp;
    }

    long bufsize = ftell(fp);
    if(bufsize == -1) {
      fprintf(stderr, "ERROR: Unable to get file position\n");
      fclose(fp);
      return udp;
    }

    // Need to do something more c++ friendly, as this is a memory leak
    source = (unsigned char *)malloc(sizeof(unsigned char) * (bufsize + 1));
    if(fseek(fp, 0L, SEEK_SET) != 0) {
      fprintf(stderr, "ERROR: Unable to see to the beginning of the file: %s\n", path);
      fclose(fp);
      return udp;
    }

    size_t len = fread(source, sizeof(unsigned char), bufsize, fp);
    if(ferror(fp) != 0) {
      fprintf(stderr, "ERROR: Unable to read the file (%i): %s\n", ferror(fp), path);
      fclose(fp);
      return udp;
    }

    udp->setReadBuffer(source, len);
    fclose(fp);
    return udp;
  } else {
    fprintf(stderr, "ERROR: Unable to seek to open file: %s\n", path);
  }

  return udp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x18, %edi
callq 0xc4d0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x50(%rbp)
callq 0x82b00
jmp 0x82c1f
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x548a(%rip), %rsi      # 0x880bc
callq 0xc5a0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x82dd6
movq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0xc550
cmpl $0x0, %eax
je 0x82ca9
movq 0x35354(%rip), %rax     # 0xb7fb8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x544d(%rip), %rsi      # 0x880bf
movb $0x0, %al
callq 0xc6e0
movq -0x38(%rbp), %rdi
callq 0xc4c0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x82dfa
movq -0x50(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0xc470
jmp 0x82e04
movq -0x38(%rbp), %rdi
callq 0xc030
movq %rax, -0x40(%rbp)
cmpq $-0x1, -0x40(%rbp)
jne 0x82ceb
movq 0x352f4(%rip), %rax     # 0xb7fb8
movq (%rax), %rdi
leaq 0x5423(%rip), %rsi      # 0x880f1
movb $0x0, %al
callq 0xc6e0
movq -0x38(%rbp), %rdi
callq 0xc4c0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x82dfa
movq -0x40(%rbp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0xc670
movq %rax, -0x18(%rbp)
movq -0x38(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0xc550
cmpl $0x0, %eax
je 0x82d46
movq 0x3529d(%rip), %rax     # 0xb7fb8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x53ec(%rip), %rsi      # 0x88115
movb $0x0, %al
callq 0xc6e0
movq -0x38(%rbp), %rdi
callq 0xc4c0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x82dfa
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rcx
movl $0x1, %esi
callq 0xc730
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
callq 0xc930
cmpl $0x0, %eax
je 0x82db0
movq 0x35243(%rip), %rax     # 0xb7fb8
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rdi
callq 0xc930
movq -0x58(%rbp), %rdi
movl %eax, %edx
movq -0x10(%rbp), %rcx
leaq 0x53b6(%rip), %rsi      # 0x8814c
movb $0x0, %al
callq 0xc6e0
movq -0x38(%rbp), %rdi
callq 0xc4c0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x82dfa
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rax
movl %eax, %edx
callq 0x82b80
movq -0x38(%rbp), %rdi
callq 0xc4c0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x82dfa
movq 0x351db(%rip), %rax     # 0xb7fb8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x538a(%rip), %rsi      # 0x88175
movb $0x0, %al
callq 0xc6e0
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0xc8b0
nopl (%rax)