// File: /workspace/github_c_makefile_star2_O1/ryancdotorg[P]bloomslice/bfstool.c
// Function: main
int main(int argc, char **argv) {
  hash160_t hash;
  FILE *ifile = stdin, *ofile = stdout;
  FILE *dfile = NULL, *hfile = NULL, *bfile = NULL, *ffile = NULL, *rfile = NULL;

  mmapf_ctx bloom_mmapf, reference_mmapf, diff_mmapf;
  struct stat sb;

  uint8_t kopt = 0;
  uint8_t wopt = DEFAULT_MAX_BIT_WIDTH;
  double sopt = DEFAULT_MAX_SATURATION;
  double eopt = DEFAULT_MAX_ERROR_RATE;

  unsigned char *bopt = NULL, *xopt = NULL, *ropt = NULL;
  unsigned char *dopt = NULL, *iopt = NULL, *oopt = NULL;

  char mode = 0;
  char hfmt = 0;

  unsigned char *bloom;

  char *line = NULL;
  size_t line_sz = 0;

  unsigned char buf[41];

  double pct, err_rate, sat;
  uint64_t mask = 0, bloom_size = 0, i, items;
  uint8_t h = 254;

  int c, r;

  while ((c = getopt(argc, argv, "hABHWRDPb:x:d:r:f:i:o:w:k:e:s:")) != -1) {
    switch (c) {
      case 'A':
        for (int i = 0; i < 256; ++i) {
          printf("%3u: %8s        ", i, bloom_deschash(i));
          if (i % 4 == 3) printf("\n");
        }
        return 0;
      case 'W':
      case 'R':
      case 'D':
      case 'P':
        if (mode) bail(1, "[!] Mode '%c' already selected, can't also specify '%c'\n", mode, c);
        mode = c; break;
      case 'H':
      case 'B':
        if (hfmt) bail(1, "[!] Format '%c' already selected, can't also specify '%c'\n", hfmt, c);
        hfmt = c; break;
      case 'b':
        bopt = optarg; break;
      case 'x':
        xopt = optarg; break;
      case 'r':
        ropt = optarg; break;
      case 'd':
        dopt = optarg; break;
      case 'i':
        iopt = optarg; break;
      case 'o':
        oopt = optarg; break;
      case 'w':
        wopt = atoi(optarg); break;
      case 'k':
        kopt = atoi(optarg); break;
      case 'e':
        eopt = atof(optarg); break;
      case 's':
        sopt = atof(optarg); break;
      case 'h':
        // show help
        usage(argv[0]);
        return 0;
      case '?':
        // show error
        return 1;
      default:
        // should never be reached...
        printf("got option '%c' (%d)\n", c, c);
        return 1;
    }
  }

  if (mode == 'W') {
    // #####################
    // ##                 ##
    // ##   CREATE MODE   ##
    // ##                 ##
    // #####################
    if (!bopt) bail(1, "[!] Bloom filter file must be specified with '-b'\n");
    if (!xopt) bail(1, "[!] Hash file must be specified with '-x'\n");
    if (dopt || ropt || iopt || oopt) {
      bail(1, "[!] Invalid combination of file options for create mode\n");
    }

    // manually specified number of hashes
    if (kopt) {
      fprintf(stderr, "bloom_pick_hash_wk w:%u k:%u\n", wopt, kopt);
      if ((h = bloom_pick_hash_wk(wopt, kopt)) == 255) {
        bail(1, "[!] No hash routine found for specified parameters\n");
      }
    }

    // open input hash file
    if ((hfile = fopen(xopt, "r")) == NULL) {
      bail(1, "[!] Failed to open hash file '%s': %s\n", xopt, strerror(errno));
    }
    if ((r = fstat(fileno(hfile), &sb)) != 0) {
      bail(1, "[!] Failed to stat hash file '%s': %s\n", xopt, strerror(errno));
    }
    if ((sb.st_size % 20) && (sb.st_size % 41)) {
      bail(1, "[!] Hash file '%s' is not a valid size\n", xopt);
    }
    if (hfmt == 0) {
      if (!(sb.st_size % 20) != !(sb.st_size % 41)) {
        hfmt = !(sb.st_size % 20) ? 'B' : 'H';
        fprintf(stderr, "[*] Auto-detected hash format %c by size\n", hfmt);
      } else {
        if ((hfmt = hash_file_type(hfile)) < 0) {
          bail(1, "[!] fgetc/ungetc failed on hash file\n");
        }
        if (hfmt == 0) {
          bail(1, "[!] Unable to determine type of hash file, please specify -B or -H\n");
        }
        fprintf(stderr, "[*] Auto-detected hash format %c by content\n", hfmt);
      }
    }

    items = sb.st_size / (hfmt == 'H' ? 41 : 20);

    fprintf(stderr, "defaults h:%u w:%u\n", h, wopt);
    // if a hash routine still hasn't been chosen, pick one now
    if (items == 0) {
      bail(1, "[!] No hashes to load\n");
    } else if (items == 1) {
      bloom_size = bloom_width_to_size(BFS_TYPE_SINGLE);
      h = BFS_TYPE_SINGLE;
    } else if (h >= 254) {
      if (eopt < 0) {
        fprintf(stderr, "bloom_pick_hash_wi w:%u i:%lu\n", wopt, items);
        if ((h = bloom_pick_hash_wi(wopt, items, &kopt)) >= 254) {
          bail(1, "[!] No hash routine found for specified parameters\n");
        }
      } else {
        fprintf(stderr, "bloom_pick_hash_es e:%.3e s:%.3f i:%lu w:%u k:%u\n", eopt, sopt, items, wopt, kopt);
        if ((h = bloom_pick_hash_es(eopt, sopt, items, &wopt, &kopt)) >= 254) {
          bail(1, "[!] No hash routine found for specified parameters\n");
        }
      }
    }

    if (bloom_size == 0 && (bloom_size = bloom_width_to_size(wopt)) == 0) {
      bail(1, "[!] Failed to compute bloom filter file size (bug?)\n");
    }

    if (stat(bopt, &sb) == 0) {
      bail(1, "[!] Bloom filter file '%s' already exists\n", bopt);
    } else {
      if ((r = open64(bopt, O_RDWR|O_CREAT|O_EXCL, 0644)) < 0) {
        bail(1, "[!] Failed to create bloom filter file '%s': %s\n", bopt, strerror(errno));
      } else if ((bfile = fdopen(r, "w+")) == NULL) {
        bail(1, "[!] Failed fdopen on bloom filter file descriptor\n");
      }
    }

    fprintf(stderr, "parameters h:%u w:%u k:%u i:%lu\n", h, wopt, kopt, items);
    mask = bloom_width_to_mask(wopt);
    sat = bloom_saturation(kopt, 1ULL<<wopt, items);
    err_rate = pow(sat, kopt);

    fprintf(stderr, "[*] Selected function %s (%u) with mask 0x%zx\n", bloom_deschash(h), h, mask);
    fprintf(stderr, "[*] Have %zu hashes to load into %zu bit filter (%zu bytes)\n", items, (bloom_size - 9) * 8, bloom_size);
    if (items > 0) {
      fprintf(stderr, "[*] Saturation: ~%.3f\n", sat);
      fprintf(stderr, "[*] False positive rate: ~%.3e (1 in ~%.3e)\n", err_rate, 1/err_rate);
    }

    bloom = chkmalloc(bloom_size);
    fprintf(stderr, "[*] Zeroing memory...\n");
    memset(bloom, 0, bloom_size);

    fprintf(stderr, "[*] Loading hash160s from '%s'   0.0%%", xopt);
    for (i = 0; i < items; ++i) {
      if (hfmt == 'H') {
        if ((r = fread(buf, 41, 1, hfile)) != 1) {
          bail(1, "[!] Error reading hex hashes\n");
        }
        unhex(buf, 40, hash.uc, sizeof(hash.uc));
      } else { // hfmt == 'B'
        if ((r = fread(hash.uc, 20, 1, hfile)) != 1) {
          bail(1, "[!] Error reading binary hashes\n");
        }
      }

      bloom_h160_set(bloom, hash.uc, h, mask);

      if ((i & 0x7ffff) == 0) {
        pct = 100.0 * i / items;
        fprintf(stderr, "\033[7D %5.1f%%", pct);
        fflush(stderr);
      }
    }

    fprintf(stderr, "\033[7D 100.0%%\n");

    bloom_set_hash(bloom, bloom_size, h);
    bloom_set_items(bloom, bloom_size, items);

    fprintf(stderr, "[*] Writing bloom filter to '%s'...\n", bopt);
    if (fwrite(bloom, bloom_size, 1, bfile) != 1) {
      bail(1, "[!] Failed to write bloom filter file '%s'\n", bopt);
    }
    fprintf(stderr, "[+] Success!\n");

    return 0;
  } else if (mode == 'R') {
    // ####################
    // ##                ##
    // ##   CHECK MODE   ##
    // ##                ##
    // ####################
    if (!bopt) bail(1, "[!] Bloom filter file must be specified with '-b'\n");
    if (dopt || xopt || ropt) {
      bail(1, "[!] Invalid combination of file options for check mode\n");
    }
    if (iopt && (ifile = fopen(iopt, "r")) == NULL) {
      bail(1, "[!] Failed to open input file '%s': %s\n", iopt, strerror(errno));
    }

    if (stat(bopt, &sb) == 0) {
      if (!S_ISREG(sb.st_mode)) {
        bail(1, "[!] Bloom filter file '%s' is not a regular file\n", bopt);
      }
      bloom_size = sb.st_size;
      if (!bloom_chk_size(bloom_size)) {
        bail(1, "[!] Bloom filter file '%s' is not a valid size\n", bopt);
      }
    } else {
      bail(1, "[!] Failed to stat '%s': %s\n", bopt, strerror(errno));
    }

    if ((r = mmapf(&bloom_mmapf, bopt, bloom_size, MMAPF_RNDRD)) != MMAPF_OKAY) {
      bail(1, "[!] Failed to open bloom filter '%s': %s\n", bopt, mmapf_strerror(r));
    } else if (bloom_mmapf.mem == NULL) {
      bail(1, "[!] Got NULL pointer trying to set up bloom filter\n");
    }

    bloom = bloom_mmapf.mem;
    h = bloom_get_hash(bloom, bloom_size);

    mask = bloom_size_to_mask(sb.st_size); // h == BFS_TYPE_SINGLE ? 0 : ((sb.st_size<<3ULL) & 0xffffffffff00)-1;
    //items = bloom_get_items(bloom, bloom_size);

    fprintf(stderr, "[*] Using function %s (0x%02x) with mask 0x%zx\n", bloom_deschash(h), h, mask);

    while ((r = getline(&line, &line_sz, ifile)) > 0) {
      if (r > 40) {
        unhex(line, 40, hash.uc, sizeof(hash.uc));
        if (bloom_h160_chk(bloom, hash.ul, h, mask)) {
          fprintf(ofile, "%s", line);
        }
      }
    }
  } else if (mode == 'D') {
    // ###################
    // ##               ##
    // ##   DIFF MODE   ##
    // ##               ##
    // ###################
    if (!ropt) bail(1, "[!] Old bloom filter file must be specified with '-r'\n");
    if (!bopt) bail(1, "[!] New bloom filter file must be specified with '-b'\n");
    if (!dopt) bail(1, "[!] Bloom filter diff file must be specified with '-d'\n");
    if (xopt) {
      bail(1, "[!] Invalid combination of file options for diff mode\n");
    }

    if (stat(bopt, &sb) == 0) {
      if (!S_ISREG(sb.st_mode)) {
        bail(1, "[!] Bloom filter file '%s' is not a regular file\n", bopt);
      }
      if (!bloom_chk_size(sb.st_size)) {
        bail(1, "[!] Bloom filter file '%s' is not a valid size\n", bopt);
      }
    } else {
      bail(1, "[!] Failed to stat '%s': %s\n", bopt, strerror(errno));
    }

    if ((r = mmapf(&bloom_mmapf, bopt, sb.st_size, MMAPF_SEQRD)) != MMAPF_OKAY) {
      bail(1, "[!] Failed to open bloom filter '%s': %s\n", bopt, mmapf_strerror(r));
    } else if (bloom_mmapf.mem == NULL) {
      bail(1, "[!] Got NULL pointer trying to set up bloom filter '%s'\n", bopt);
    }

    if (stat(ropt, &sb) == 0) {
      if (!S_ISREG(sb.st_mode)) {
        bail(1, "[!] Bloom filter file '%s' is not a regular file\n", ropt);
      }
      if (!bloom_chk_size(sb.st_size)) {
        bail(1, "[!] Bloom filter file '%s' is not a valid size\n", ropt);
      }
    } else {
      bail(1, "[!] Failed to stat '%s': %s\n", ropt, strerror(errno));
    }

    if ((r = mmapf(&reference_mmapf, ropt, sb.st_size, MMAPF_SEQRD)) != MMAPF_OKAY) {
      bail(1, "[!] Failed to open bloom filter '%s': %s\n", ropt, mmapf_strerror(r));
    } else if (reference_mmapf.mem == NULL) {
      bail(1, "[!] Got NULL pointer trying to set up bloom filter '%s'\n", ropt);
    }

    if (bloom_mmapf.file_sz != reference_mmapf.file_sz) {
      bail(1, "[!] Old and new bloom filter files are different sizes!\n");
    }

    if ((r = mmapf(&diff_mmapf, dopt, bloom_mmapf.file_sz, MMAPF_SEQCR)) != MMAPF_OKAY) {
      bail(1, "[!] Failed to open bloom filter diff '%s': %s\n", dopt, mmapf_strerror(r));
    } else if (diff_mmapf.mem == NULL) {
      bail(1, "[!] Got NULL pointer trying to set up bloom filter diff '%s'\n", ropt);
    }

    fprintf(stderr, "[*] Generating diff between '%s' and '%s'   0.0%%", ropt, bopt);
    for (int i = 0; i < bloom_mmapf.file_sz; ++i) {
      ((unsigned char *)diff_mmapf.mem)[i] = ((unsigned char *)reference_mmapf.mem)[i] ^ ((unsigned char *)bloom_mmapf.mem)[i];
      if ((i & 0x7ffff) == 0) {
        pct = 100.0 * i / bloom_mmapf.file_sz;
        fprintf(stderr, "\033[7D %5.1f%%", pct);
        fflush(stderr);
      }
    }
    fprintf(stderr, "\033[7D 100.0%%\n");
  } else if (mode == 'P') {
    // ####################
    // ##                ##
    // ##   PATCH MODE   ##
    // ##                ##
    // ####################
    if (!ropt) bail(1, "[!] Old bloom filter file must be specified with '-r'\n");
    if (!bopt) bail(1, "[!] New bloom filter file must be specified with '-b'\n");
    if (!dopt) bail(1, "[!] Bloom filter diff file must be specified with '-d'\n");
    if (xopt) {
      bail(1, "[!] Invalid combination of file options for diff mode\n");
    }
  } else {
    bail(1, "[!] No valid mode selected\n");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rsi, %rbx
movl %edi, %r14d
movq 0x9262(%rip), %rax      # 0xafc8
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x924b(%rip), %rax      # 0xafc0
movq (%rax), %rax
movq %rax, 0xb0(%rsp)
movb $0x0, 0xf(%rsp)
movb $0x23, 0xe(%rsp)
xorl %eax, %eax
movq %rax, 0x58(%rsp)
movq $0x0, 0x20(%rsp)
movq %rax, 0x78(%rsp)
movsd 0x5261(%rip), %xmm0     # 0x7008
movsd %xmm0, 0x30(%rsp)
movsd 0x525b(%rip), %xmm0     # 0x7010
movsd %xmm0, 0x40(%rsp)
leaq 0x5536(%rip), %r13      # 0x72f8
leaq 0x5287(%rip), %r12      # 0x7050
leaq 0x52a8(%rip), %r15      # 0x7078
movq $0x0, 0x60(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x28(%rsp)
movl %r14d, %edi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x1210
cmpl $0x51, %eax
jle 0x1e3c
leal -0x62(%rax), %ecx
cmpl $0x16, %ecx
ja 0x1e5f
movslq (%r15,%rcx,4), %rcx
addq %r15, %rcx
jmpq *%rcx
movq 0x91a6(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x1e07
leal -0x3f(%rax), %ecx
cmpl $0x9, %ecx
ja 0x1e6e
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
movl 0x28(%rsp), %ecx
testb %cl, %cl
jne 0x29c2
movl %eax, 0x28(%rsp)
jmp 0x1e07
cmpl $0x52, %eax
je 0x1e77
cmpl $0x57, %eax
je 0x1e77
jmp 0x1fd5
cmpl $0x50, %eax
jne 0x1f4c
testb %bpl, %bpl
jne 0x29b7
movl %eax, %ebp
jmp 0x1e07
movq 0x914d(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x1230
movb %al, 0xe(%rsp)
jmp 0x1e07
movq 0x9135(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, 0x60(%rsp)
jmp 0x1e07
movq 0x9121(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x1e07
movq 0x910d(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x1070
movsd %xmm0, 0x30(%rsp)
jmp 0x1e07
movq 0x90f3(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, 0x50(%rsp)
jmp 0x1e07
movq 0x90df(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x1e07
movq 0x90cb(%rip), %rax      # 0xafd8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x1e07
movq 0x90b7(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x1070
movsd %xmm0, 0x40(%rsp)
jmp 0x1e07
movq 0x909d(%rip), %rax      # 0xafd8
movq (%rax), %rdi
callq 0x1230
movb %al, 0xf(%rsp)
jmp 0x1e07
cmpl $-0x1, %eax
jne 0x1fd5
cmpb $0x50, %bpl
jne 0x2000
cmpq $0x0, 0x10(%rsp)
movq 0x60(%rsp), %rax
je 0x29f1
cmpq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rcx
je 0x29f6
testq %rcx, %rcx
je 0x29fb
testq %rax, %rax
je 0x1fd1
callq 0x12f4
leaq 0x537c(%rip), %rbx      # 0x7317
xorl %ebp, %ebp
movzbl %bpl, %edi
callq 0x5b64
movq %rbx, %rdi
movl %ebp, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10c0
movl %ebp, %eax
notl %eax
testb $0x3, %al
jne 0x1fc7
movl $0xa, %edi
callq 0x1030
incl %ebp
cmpl $0x100, %ebp            # imm = 0x100
jne 0x1f9d
xorl %ebp, %ebp
jmp 0x1fec
leaq 0x53c0(%rip), %rdi      # 0x739c
movl %eax, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x10c0
movl $0x1, %ebp
movl %ebp, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %bpl, %eax
cmpl $0x44, %eax
movq 0x60(%rsp), %r12
je 0x2359
cmpl $0x52, %eax
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %rcx
je 0x2194
cmpl $0x57, %eax
jne 0x2af0
testq %r15, %r15
je 0x2a00
testq %r12, %r12
je 0x2a0f
testq %rcx, %rcx
jne 0x2a23
cmpq $0x0, 0x10(%rsp)
jne 0x2a23
cmpq $0x0, 0x50(%rsp)
jne 0x2a23
cmpq $0x0, 0x48(%rsp)
jne 0x2a23
movb 0xf(%rsp), %al
movb $-0x2, %r14b
testb %al, %al
je 0x2098
movzbl %al, %esi
leaq 0xe(%rsp), %rdi
leaq 0xf(%rsp), %rdx
leaq 0xd8(%rsp), %rbx
movq %rbx, %rcx
callq 0x17e6
movb (%rbx), %r14b
leaq 0x603d(%rip), %rsi      # 0x80dc
movq %r12, %rdi
callq 0x11f0
testq %rax, %rax
je 0x2a30
movq %rax, %r13
movq %rax, %rdi
callq 0x1160
leaq 0xd8(%rsp), %rsi
movl %eax, %edi
callq 0x1280
testl %eax, %eax
jne 0x2a45
movq 0x108(%rsp), %rbx
movabsq $0x6666666666666667, %rcx # imm = 0x6666666666666667
movq %rbx, %rax
imulq %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x3, %rdx
addq %rax, %rdx
shlq $0x2, %rdx
leaq (%rdx,%rdx,4), %rax
movq %rbx, %rcx
subq %rax, %rcx
sete %sil
movabsq $0x63e7063e7063e707, %rdx # imm = 0x63E7063E7063E707
movq %rbx, %rax
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x4, %rdx
addq %rax, %rdx
leaq (%rdx,%rdx,4), %rax
leaq (%rdx,%rax,8), %rdx
movq %rbx, %rax
subq %rdx, %rax
sete %dl
orb %sil, %dl
je 0x2a5d
movl 0x28(%rsp), %ebp
testb %bpl, %bpl
jne 0x257b
testq %rcx, %rcx
sete %dl
testq %rax, %rax
setne %al
xorb %dl, %al
je 0x2551
movq %r13, %rdi
callq 0x1cec
testb %al, %al
js 0x2b1d
movq 0x8e7e(%rip), %rcx      # 0xaff8
movq (%rcx), %rdi
je 0x2b22
movl %eax, %ebp
movsbl %al, %edx
leaq 0x5416(%rip), %rsi      # 0x75a5
jmp 0x2574
testq %r15, %r15
je 0x2a05
testq %rcx, %rcx
jne 0x2a19
testq %r12, %r12
jne 0x2a19
cmpq $0x0, 0x10(%rsp)
jne 0x2a19
movq 0x50(%rsp), %rbx
testq %rbx, %rbx
je 0x21e2
leaq 0x5f10(%rip), %rsi      # 0x80dc
movq %rbx, %rdi
callq 0x11f0
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x2b0b
leaq 0xd8(%rsp), %rsi
movq %r15, %rdi
callq 0x1140
testl %eax, %eax
jne 0x2a28
movl $0xf000, %eax           # imm = 0xF000
andl 0xf0(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x2a3d
movq 0x108(%rsp), %rbx
movq %rbx, %rdi
callq 0x5bf7
testl %eax, %eax
je 0x2a55
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl $0x2501, %ecx           # imm = 0x2501
callq 0x60d7
testl %eax, %eax
jne 0x2a6d
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x2a7f
movq %rdi, 0x28(%rsp)
movq %rbx, %rsi
callq 0x5c23
movl %eax, %ebx
movq 0x108(%rsp), %rdi
callq 0x5bca
movq %rax, %r14
movq 0x8d78(%rip), %rax      # 0xaff8
movq (%rax), %r12
movzbl %bl, %ebx
movl %ebx, %edi
callq 0x5b64
leaq 0x5790(%rip), %rsi      # 0x7a24
xorl %ebp, %ebp
movq %r12, %rdi
movq %rax, %rdx
movl %ebx, %ecx
movq %r14, 0x20(%rsp)
movq %r14, %r8
xorl %eax, %eax
callq 0x1130
leaq 0x58(%rsp), %rdi
leaq 0x78(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0x1240
testl %eax, %eax
jle 0x1fec
leaq 0x4e10(%rip), %r14      # 0x70e0
leaq 0x4f09(%rip), %r15      # 0x71e0
leaq 0x58(%rsp), %r13
leaq 0x78(%rsp), %r12
xorl %ebp, %ebp
cmpl $0x29, %eax
jb 0x2340
movq 0x58(%rsp), %rax
xorl %ecx, %ecx
movq 0x28(%rsp), %rdi
movzbl (%rax,%rcx,2), %edx
movzbl 0x1(%rax,%rcx,2), %esi
movb (%rsi,%r15), %sil
orb (%rdx,%r14), %sil
movb %sil, 0xb8(%rsp,%rcx)
incq %rcx
cmpq $0x14, %rcx
jne 0x22f4
leaq 0xb8(%rsp), %rsi
movl %ebx, %edx
movq 0x20(%rsp), %rcx
callq 0x2b44
testl %eax, %eax
je 0x2340
movq 0x58(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x10e0
movq %r13, %rdi
movq %r12, %rsi
movq 0x38(%rsp), %rdx
callq 0x1240
testl %eax, %eax
jg 0x22e3
jmp 0x1fec
movq 0x10(%rsp), %r15
testq %r15, %r15
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r13
je 0x2a0a
testq %r14, %r14
je 0x2a14
testq %r13, %r13
je 0x2a1e
testq %r12, %r12
jne 0x2a38
leaq 0xd8(%rsp), %rsi
movq %r14, %rdi
callq 0x1140
testl %eax, %eax
jne 0x2a4d
movl $0xf000, %eax           # imm = 0xF000
andl 0xf0(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x2a65
movq 0x108(%rsp), %rbx
movq %rbx, %rdi
callq 0x5bf7
testl %eax, %eax
je 0x2a77
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl $0x2201, %ecx           # imm = 0x2201
callq 0x60d7
testl %eax, %eax
jne 0x2a84
cmpq $0x0, 0x80(%rsp)
je 0x2a96
leaq 0xd8(%rsp), %rsi
movq %r15, %rdi
callq 0x1140
testl %eax, %eax
jne 0x2aa6
movl $0xf000, %eax           # imm = 0xF000
andl 0xf0(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x2ab3
movq 0x108(%rsp), %rbx
movq %rbx, %rdi
callq 0x5bf7
testl %eax, %eax
je 0x2abb
leaq 0xb8(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl $0x2201, %ecx           # imm = 0x2201
callq 0x60d7
testl %eax, %eax
jne 0x2ac3
cmpq $0x0, 0xb8(%rsp)
je 0x2acd
movq 0x90(%rsp), %rdx
cmpq 0xc8(%rsp), %rdx
jne 0x2ad5
leaq 0x168(%rsp), %rdi
movq %r13, %rsi
movl $0x20e, %ecx            # imm = 0x20E
callq 0x60d7
testl %eax, %eax
jne 0x2ada
cmpq $0x0, 0x168(%rsp)
movq 0x8b3d(%rip), %r12      # 0xaff8
movq (%r12), %rdi
je 0x2ae4
leaq 0x5744(%rip), %rsi      # 0x7c10
xorl %ebp, %ebp
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1130
cmpq $0x0, 0x90(%rsp)
jne 0x24fd
movq (%r12), %rdi
leaq 0x5389(%rip), %rsi      # 0x787a
xorl %eax, %eax
callq 0x1130
jmp 0x1fec
leaq 0x90(%rsp), %r14
xorl %r15d, %r15d
movq 0xb8(%rsp), %rax
movq 0x80(%rsp), %rcx
movb (%rcx,%r15), %cl
xorb (%rax,%r15), %cl
movq 0x168(%rsp), %rax
movb %cl, (%rax,%r15)
testl $0x7ffff, %r15d         # imm = 0x7FFFF
je 0x2544
incq %r15
cmpq %r15, 0x90(%rsp)
ja 0x2508
jmp 0x24e6
movq %r15, %rdi
movq %r14, %rsi
callq 0x1531
jmp 0x2535
testq %rcx, %rcx
movl $0x42, %eax
movl $0x48, %ebp
cmovel %eax, %ebp
movq 0x8a90(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x4f9f(%rip), %rsi      # 0x7511
movl %ebp, %edx
xorl %eax, %eax
callq 0x1130
movl %ebp, 0x28(%rsp)
cmpb $0x48, %bpl
movl $0x29, %eax
movl $0x14, %ecx
cmoveq %rax, %rcx
movq %rbx, %rax
cqto
idivq %rcx
movq %rax, %rbx
movq 0x8a55(%rip), %rbp      # 0xaff8
movq (%rbp), %rdi
movzbl %r14b, %edx
movzbl 0xe(%rsp), %ecx
leaq 0x501b(%rip), %rsi      # 0x75d2
xorl %eax, %eax
callq 0x1130
cmpq $0x1, %rbx
je 0x261e
testq %rbx, %rbx
je 0x2b13
cmpb $-0x2, %r14b
jb 0x2680
xorpd %xmm0, %xmm0
movsd 0x30(%rsp), %xmm1
ucomisd %xmm1, %xmm0
movq (%rbp), %rdi
movzbl 0xe(%rsp), %ecx
jbe 0x262d
leaq 0x5006(%rip), %rsi      # 0x75fd
movl %ecx, %edx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1130
movzbl 0xe(%rsp), %edi
leaq 0xf(%rsp), %rdx
movq %rbx, %rsi
callq 0x5cfa
cmpb $-0x2, %al
jb 0x267d
callq 0x1a5b
movl $0x1, %edi
callq 0x5b73
movb $0x1, %r14b
jmp 0x2682
movapd %xmm1, %xmm0
leaq 0xf(%rsp), %rax
movzbl (%rax), %r8d
leaq 0x4fdb(%rip), %rsi      # 0x761c
movsd %xmm1, 0x30(%rsp)
movsd 0x40(%rsp), %xmm1
movq %rbx, %rdx
movb $0x2, %al
callq 0x1130
leaq 0xe(%rsp), %rsi
movsd 0x30(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movq %rbx, %rdi
leaq 0xf(%rsp), %rdx
callq 0x5def
cmpb $-0x2, %al
jae 0x2b27
movl %eax, %r14d
xorl %eax, %eax
testq %rax, %rax
jne 0x269a
movzbl 0xe(%rsp), %edi
callq 0x5b73
testq %rax, %rax
je 0x2b18
movq %rax, 0x48(%rsp)
leaq 0xd8(%rsp), %rsi
movq %r15, %rdi
callq 0x1140
testl %eax, %eax
je 0x2a8e
movq %r15, %rdi
movl $0xc2, %esi
movl $0x1a4, %edx            # imm = 0x1A4
xorl %eax, %eax
callq 0x11d0
testl %eax, %eax
js 0x2a9e
movq %r13, 0x10(%rsp)
leaq 0x5000(%rip), %rsi      # 0x76df
movl %eax, %edi
callq 0x11a0
movq (%rbp), %rdi
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x2aae
movzbl %r14b, %r13d
movzbl 0xe(%rsp), %ecx
movzbl 0xf(%rsp), %r8d
leaq 0x5007(%rip), %rsi      # 0x7715
movl %r13d, %edx
movq %rbx, %r9
xorl %eax, %eax
callq 0x1130
movzbl 0xe(%rsp), %edi
callq 0x5ba5
movq %rbx, %r14
movq %rax, %rbx
movzbl 0xf(%rsp), %edi
movb 0xe(%rsp), %cl
movl $0x1, %esi
shlq %cl, %rsi
movq %r14, %rdx
callq 0x5ae8
movsd %xmm0, 0x40(%rsp)
movzbl 0xf(%rsp), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
callq 0x1090
movsd %xmm0, 0x30(%rsp)
movq (%rbp), %r15
movl %r13d, %edi
callq 0x5b64
leaq 0x4fc2(%rip), %rsi      # 0x7736
movq %r15, %rdi
movq %rax, %rdx
movl %r13d, 0x18(%rsp)
movl %r13d, %ecx
movq %rbx, 0x50(%rsp)
movq %rbx, %r8
xorl %eax, %eax
callq 0x1130
movq (%rbp), %rdi
movq 0x48(%rsp), %rbx
leaq -0x48(,%rbx,8), %rcx
leaq 0x4fbc(%rip), %rsi      # 0x7765
movq %r14, %rdx
movq %rbx, %r8
xorl %eax, %eax
callq 0x1130
movq (%rbp), %rdi
leaq 0x4fe1(%rip), %rsi      # 0x77a2
movsd 0x40(%rsp), %xmm0
movb $0x1, %al
callq 0x1130
movq (%rbp), %rdi
movsd 0x483e(%rip), %xmm1     # 0x7018
movsd 0x30(%rsp), %xmm0
divsd %xmm0, %xmm1
leaq 0x4fce(%rip), %rsi      # 0x77b9
movb $0x2, %al
callq 0x1130
movq %rbx, %rdi
callq 0x2b2c
movq %rax, %r13
movq (%rbp), %rcx
leaq 0x4fe8(%rip), %rdi      # 0x77f0
movl $0x16, %esi
movl $0x1, %edx
callq 0x1260
movq %r13, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x10f0
movq (%rbp), %rdi
leaq 0x4fd8(%rip), %rsi      # 0x7807
movq %r12, %rdx
xorl %eax, %eax
callq 0x1130
movq %r14, %rbx
testq %r14, %r14
jne 0x28c6
movq 0x87ac(%rip), %r15      # 0xaff8
movq (%r15), %rdi
leaq 0x5024(%rip), %rsi      # 0x787a
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x1130
movq %r13, %rdi
movq 0x48(%rsp), %r12
movq %r12, %rsi
movl 0x18(%rsp), %edx
callq 0x5c34
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x5c4b
movq (%r15), %rdi
leaq 0x4ffd(%rip), %rsi      # 0x7888
movq 0x20(%rsp), %r14
movq %r14, %rdx
xorl %eax, %eax
callq 0x1130
movl $0x1, %edx
movq %r13, %rdi
movq %r12, %rsi
movq 0x38(%rsp), %rcx
callq 0x1260
movq (%r15), %rdi
cmpq $0x1, %rax
jne 0x2af5
callq 0x199d
jmp 0x1fec
movq %rbx, %xmm0
punpckldq 0x475d(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4765(%rip), %xmm0     # 0x7040
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x60(%rsp)
xorl %r15d, %r15d
leaq 0x47e9(%rip), %rbp      # 0x70e0
leaq 0x48e2(%rip), %r14      # 0x71e0
leaq 0xb8(%rsp), %r12
cmpb $0x48, 0x28(%rsp)
jne 0x295d
movl $0x29, %esi
movl $0x1, %edx
leaq 0x80(%rsp), %rdi
movq 0x10(%rsp), %rcx
callq 0x1060
cmpl $0x1, %eax
jne 0x29e7
xorl %eax, %eax
movzbl 0x80(%rsp,%rax,2), %ecx
movzbl 0x81(%rsp,%rax,2), %edx
movb (%rdx,%r14), %dl
orb (%rcx,%rbp), %dl
movb %dl, 0xb8(%rsp,%rax)
incq %rax
cmpq $0x14, %rax
jne 0x2934
jmp 0x2979
movl $0x14, %esi
movl $0x1, %edx
movq %r12, %rdi
movq 0x10(%rsp), %rcx
callq 0x1060
cmpl $0x1, %eax
jne 0x29ec
movq %r13, %rdi
movq %r12, %rsi
movl 0x18(%rsp), %edx
movq 0x50(%rsp), %rcx
callq 0x56d0
movq %r15, %rax
shlq $0x2d, %rax
je 0x29a7
incq %r15
cmpq %rbx, %r15
jne 0x2906
jmp 0x2845
movq %r15, %rdi
movapd 0x60(%rsp), %xmm0
callq 0x1949
jmp 0x2996
movzbl %bpl, %edi
movl %eax, %esi
callq 0x12ca
movzbl %cl, %edi
movl %eax, %esi
callq 0x12a0
movq (%rbx), %rsi
leaq 0x490a(%rip), %rdi      # 0x72e0
xorl %eax, %eax
callq 0x10c0
movl $0x1, %edi
callq 0x1250
callq 0x1924
callq 0x18ff
callq 0x1363
callq 0x133e
callq 0x1319
callq 0x1b49
callq 0x17c1
callq 0x165d
callq 0x1b24
callq 0x1638
callq 0x179c
callq 0x1613
callq 0x1aff
movq %r15, %rdi
callq 0x16be
movq %r12, %rdi
callq 0x1ac3
callq 0x1388
movq %r15, %rdi
callq 0x16fa
movq %r12, %rdi
callq 0x1855
movq %r14, %rdi
callq 0x13ad
movq %r15, %rdi
callq 0x1778
movq %r12, %rdi
callq 0x1891
movq %r14, %rdi
callq 0x13e9
movl %eax, %edi
movq %r15, %rsi
callq 0x171e
movq %r14, %rdi
callq 0x15ef
callq 0x1753
movl %eax, %edi
movq %r14, %rsi
callq 0x140d
movq %r15, %rdi
callq 0x1a12
movq %r14, %rdi
callq 0x15cb
movq %r15, %rdi
callq 0x19d6
movq %r15, %rdi
callq 0x1442
callq 0x19b8
movq %r15, %rdi
callq 0x147e
movq %r15, %rdi
callq 0x15a7
movl %eax, %edi
movq %r15, %rsi
callq 0x14a2
movq %r15, %rdi
callq 0x1583
callq 0x14d7
movl %eax, %edi
movq %r13, %rsi
callq 0x14fc
leaq 0x50e7(%rip), %rsi      # 0x7bd2
movq %r15, %rdx
jmp 0x2aff
callq 0x1b6e
leaq 0x4db1(%rip), %rsi      # 0x78ad
movq %r14, %rdx
xorl %eax, %eax
callq 0x1130
jmp 0x29dd
movq %rbx, %rdi
callq 0x1682
callq 0x18b5
callq 0x1a36
callq 0x1a9e
callq 0x1a80
callq 0x18da