// File: lagoproject[P]arti/analysis/analysis.cc
// Function: ReadBlock(double*, int)
int ReadBlock(double *block, int type) {
  int read_line_error = 0, check = 0, read_no_error=1;
  bad_block=0;
  for (int row=0; row<block_rows; row++) {
    if (fgets(line,250,fi)!=NULL) {
      do {
        check=sscanf(
          line, "%le %le %le %le %le %le %le\n", 
          &block[block_cols * row + 0], 
          &block[block_cols * row + 1], 
          &block[block_cols * row + 2], 
          &block[block_cols * row + 3], 
          &block[block_cols * row + 4], 
          &block[block_cols * row + 5], 
          &block[block_cols * row + 6]
        );
      } while (check != block_cols && read_line_error++ < read_tries);
      lines++;
      if (read_line_error) {
        cerr << "Error: Bad block (missing elements) at block "<< type << ", row " << row+1 << endl;
        read_no_error=0;
        break;
      }
    }
    else { 
      cerr << "Error: EOF while reading block " << type << " at line " << row+1 << endl;
      read_no_error=0;
      break;
    }
  }
  if (block[0] != chk_block[type]) {
    // if we read the last event, then while we are trying to read the next event header we are actually reading the run_footer, so...
    if (type == 2 && block[0] == chk_block[4]) {
      events=false;
      for (int i=0; i<block_size; i++) 
        run_footer[i] = block[i];
    }
    else {  
      bad_block = 1;
      fprintf(stderr, "Error: Bad block error (unformated) at block %d. First element should be %.5E, and it is %.5E\n", type, chk_block[type], block[0]);
    }
  }
  return read_no_error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x1, -0x18(%rbp)
movl $0x0, 0x6842(%rip)      # 0x7c60
movl $0x0, -0x1c(%rbp)
cmpl $0x27, -0x1c(%rbp)
jge 0x1600
movq 0x3d02(%rip), %rdx      # 0x5138
leaq 0x6873(%rip), %rdi      # 0x7cb0
movl $0xfa, %esi
callq 0x1150
cmpq $0x0, %rax
je 0x159d
jmp 0x1453
movq -0x8(%rbp), %rdx
imull $0x7, -0x1c(%rbp), %eax
addl $0x0, %eax
cltq
shlq $0x3, %rax
addq %rax, %rdx
movq -0x8(%rbp), %rcx
imull $0x7, -0x1c(%rbp), %eax
addl $0x1, %eax
cltq
shlq $0x3, %rax
addq %rax, %rcx
movq -0x8(%rbp), %r8
imull $0x7, -0x1c(%rbp), %eax
addl $0x2, %eax
cltq
shlq $0x3, %rax
addq %rax, %r8
movq -0x8(%rbp), %r9
imull $0x7, -0x1c(%rbp), %eax
addl $0x3, %eax
cltq
shlq $0x3, %rax
addq %rax, %r9
movq -0x8(%rbp), %r11
imull $0x7, -0x1c(%rbp), %eax
addl $0x4, %eax
cltq
shlq $0x3, %rax
addq %rax, %r11
movq -0x8(%rbp), %r10
imull $0x7, -0x1c(%rbp), %eax
addl $0x5, %eax
cltq
shlq $0x3, %rax
addq %rax, %r10
movq -0x8(%rbp), %rax
imull $0x7, -0x1c(%rbp), %esi
addl $0x6, %esi
movslq %esi, %rsi
shlq $0x3, %rsi
addq %rsi, %rax
leaq 0x67c9(%rip), %rdi      # 0x7cb0
leaq 0x1c8b(%rip), %rsi      # 0x3179
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x10a0
movl %eax, -0x14(%rbp)
xorl %eax, %eax
cmpl $0x7, -0x14(%rbp)
movb %al, -0x21(%rbp)
je 0x1525
movl -0x10(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x10(%rbp)
cmpl $0xa, %eax
setl %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0x1453
movq 0x6711(%rip), %rax      # 0x7c48
addq $0x1, %rax
movq %rax, 0x6706(%rip)      # 0x7c48
cmpl $0x0, -0x10(%rbp)
je 0x159b
movq 0x3aa1(%rip), %rdi      # 0x4ff0
leaq 0x1c40(%rip), %rsi      # 0x3196
callq 0x10b0
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x1170
movq %rax, %rdi
leaq 0x1c54(%rip), %rsi      # 0x31c4
callq 0x10b0
movq %rax, %rdi
movl -0x1c(%rbp), %esi
addl $0x1, %esi
callq 0x1170
movq %rax, %rdi
movq 0x3a23(%rip), %rsi      # 0x4fb0
callq 0x10c0
movl $0x0, -0x18(%rbp)
jmp 0x1600
jmp 0x15f0
movq 0x3a4c(%rip), %rdi      # 0x4ff0
leaq 0x1c20(%rip), %rsi      # 0x31cb
callq 0x10b0
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x1170
movq %rax, %rdi
leaq 0x1c26(%rip), %rsi      # 0x31eb
callq 0x10b0
movq %rax, %rdi
movl -0x1c(%rbp), %esi
addl $0x1, %esi
callq 0x1170
movq %rax, %rdi
movq 0x39ce(%rip), %rsi      # 0x4fb0
callq 0x10c0
movl $0x0, -0x18(%rbp)
jmp 0x1600
jmp 0x15f2
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1425
movq -0x8(%rbp), %rax
movsd (%rax), %xmm0
movslq -0xc(%rbp), %rcx
leaq 0x3acd(%rip), %rax      # 0x50e0
ucomisd (%rax,%rcx,8), %xmm0
jne 0x1621
jp 0x1621
jmp 0x16bb
cmpl $0x2, -0xc(%rbp)
jne 0x167c
movq -0x8(%rbp), %rax
movsd (%rax), %xmm0
ucomisd 0x3ac9(%rip), %xmm0     # 0x5100
jne 0x167c
jp 0x167c
movb $0x0, 0x3ac6(%rip)      # 0x5108
movl $0x0, -0x20(%rbp)
cmpl $0x111, -0x20(%rbp)     # imm = 0x111
jge 0x167a
movq -0x8(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movslq -0x20(%rbp), %rcx
leaq 0x5d26(%rip), %rax      # 0x7390
movsd %xmm0, (%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1649
jmp 0x16b9
movl $0x1, 0x65da(%rip)      # 0x7c60
movq 0x3943(%rip), %rax      # 0x4fd0
movq (%rax), %rdi
movl -0xc(%rbp), %edx
movslq -0xc(%rbp), %rcx
leaq 0x3a42(%rip), %rax      # 0x50e0
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movsd (%rax), %xmm1
leaq 0x1b43(%rip), %rsi      # 0x31f5
movb $0x2, %al
callq 0x1130
jmp 0x16bb
movl -0x18(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)