// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/mshalign/mshalign.cpp
// Function: ReadWeights(char const*, double*&, int&)
static RNScalar *
ReadWeights(const char *filename, RNScalar *& weights, int& nweights)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Open file
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    RNFail("Unable to open edge weight file %s\n", filename);
    return NULL;
  }

  // Count weights
  nweights = 0;
  RNScalar dummy;
  while (fscanf(fp, "%lf", &dummy) == 1) nweights++;
  fseek(fp, 0, SEEK_SET);

  // Check number of weights
  if (nweights == 0) {
    RNFail("There are no weights in %s\n", filename);
    return NULL;
  }

  // Allocate array for weights
  weights = new RNScalar [ nweights ];
  if (!weights) {
    RNFail("Unable to allocate weights for %s\n", filename);
    return NULL;
  }

  // Read weights
  for (int i = 0; i < nweights; i++) {
    if (fscanf(fp, "%lf", &weights[i]) != 1) {
      RNFail("Unable to read weight %d from %s\n", i, filename);
      return NULL;
    }
  }

  // Close file
  fclose(fp);

  // Print message
  if (print_verbose) {
    printf("Read weights from %s ...\n", filename);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Weights = %d\n", nweights);
  }

  // Return weights
  return weights;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r15
movq %rsi, (%rsp)
movq %rdi, %r14
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x4dc92
movq %r12, %rdi
callq 0x10fda
leaq 0x4273a(%rip), %rsi     # 0x52620
movq %r14, %rdi
callq 0xc460
testq %rax, %rax
je 0xff9a
movq %rax, %r12
andl $0x0, (%r15)
leaq 0x41c4a(%rip), %r13     # 0x51b4f
leaq 0x10(%rsp), %rbp
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xc6a0
cmpl $0x1, %eax
jne 0xff24
incl (%r15)
jmp 0xff0a
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc410
movslq (%r15), %rbx
testq %rbx, %rbx
je 0xffa3
movq %r14, 0x8(%rsp)
movq %rbx, %rax
shlq $0x3, %rax
testl %ebx, %ebx
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0xc030
movq (%rsp), %rcx
movq %rax, (%rcx)
leaq 0x41bef(%rip), %rbp     # 0x51b4f
xorl %r14d, %r14d
xorl %r13d, %r13d
movslq %ebx, %rax
cmpq %rax, %r13
jge 0xffb8
movq (%rsp), %rax
movq (%rax), %rdx
addq %r14, %rdx
movq %r12, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0xc6a0
cmpl $0x1, %eax
jne 0x1000e
incq %r13
movl (%r15), %ebx
addq $0x8, %r14
jmp 0xff66
leaq 0x4129e(%rip), %rdi     # 0x5123f
jmp 0xffaa
leaq 0x412b9(%rip), %rdi     # 0x51263
xorl %ebx, %ebx
movq %r14, %rsi
xorl %eax, %eax
callq 0x5009a
jmp 0x10026
movq %r12, %rdi
callq 0xc370
cmpb $0x1, 0x68b21(%rip)     # 0x78ae8
jne 0x10005
leaq 0x412d1(%rip), %rdi     # 0x512a1
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0xc070
leaq 0x18(%rsp), %rdi
callq 0x4dccc
leaq 0x41208(%rip), %rdi     # 0x511f5
movb $0x1, %al
callq 0xc070
movl (%r15), %esi
leaq 0x412bd(%rip), %rdi     # 0x512bb
xorl %eax, %eax
callq 0xc070
movq (%rsp), %rax
movq (%rax), %rbx
jmp 0x10026
leaq 0x4126a(%rip), %rdi     # 0x5127f
xorl %ebx, %ebx
movl %r13d, %esi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x5009a
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq