// File: /workspace/github_cpp_makefile_star2_O3/wwdatabase[P]database/./rcdmana/rm_filescan.h
// Function: RM_FileScan::getNextRec(RM_Record&)
RC RM_FileScan::getNextRec(RM_Record &rec) {
    cout << "Get record" << endl;
  char data[this->fh->recordSize];
  bool isSelected = false;
  bool rid_error = false;
  do {
    if (this->recordScanNum >= this->fh->recordNumForAllPages) {
        cout << "File EOF" << endl;
        this->record.clean();
        break;
    }

    while (this->fh->getRec(rid, this->record) == 108) {
        cout << "Unused record, ignore it." << endl;
        incRID();
    }

    char *td = data;
    this->record.getData(td);
    char comValue[this->attrLength];
    strncpy(comValue, data+this->attrOffset, this->attrLength);
    if (attrType == ATTRINT) {
      int *intValue = (int*)(comValue);
      // int c = 40100200;
      // int *intValue = &c;
      int *cmpValue = (int*)(value);
      cout << *intValue << " : " << *cmpValue << endl;
      switch (this->compOp) {
          case EQ_OP:
              if ((*intValue) == (*cmpValue))
                  isSelected = true;
              cout << isSelected << endl;
              break;
          case LT_OP:
              if (*intValue < *cmpValue)
                  isSelected = true;
              break;
          case GT_OP:
              if (*intValue > *cmpValue)
                  isSelected = true;
              break;
          case LE_OP:
              if (*intValue <= *cmpValue)
                  isSelected = true;
              break;
          case GE_OP:
              if (*intValue >= *cmpValue)
                  isSelected = true;
              break;
          case NE_OP:
              if (*intValue != *cmpValue)
                  isSelected = true;
              break;
          case NO_OP:
              /* No comparision (when value is a null pointer) */
              isSelected = true;
              break;
          default:
              cout << "compOp Error at compare INT" << endl;
              break;
      }
    }
    else if (attrType == ATTRFLOAT) {
      float *floatValue = (float*)(comValue);
      float *cmpValue = (float*)(value);
      switch (this->compOp) {
          case EQ_OP:
              if (*floatValue == *cmpValue)
                  isSelected = true;
              break;
          case LT_OP:
              if (*floatValue < *cmpValue)
                  isSelected = true;
              break;
          case GT_OP:
              if (*floatValue > *cmpValue)
                  isSelected = true;
              break;
          case LE_OP:
              if (*floatValue <= *cmpValue)
                  isSelected = true;
              break;
          case GE_OP:
              if (*floatValue >= *cmpValue)
                  isSelected = true;
              break;
          case NE_OP:
              if (*floatValue != *cmpValue)
                  isSelected = true;
              break;
          case NO_OP:
              /* No comparision (when value is a null pointer) */
              isSelected = true;
              break;
          default:
              cout << "Compop error at compare FLOAT" << endl;
              break;
      }
    }
    else if (attrType == ATTRSTRING) {
      isSelected = true;
      char *strValue = (char*)(comValue);
      char* cmpValue = (char*)(value);
      switch (this->compOp) {
          case EQ_OP:
              if (strncmp(strValue, cmpValue, this->attrLength) == 0)
                  isSelected = true;
              break;
          case LT_OP:
              if (strncmp(strValue, cmpValue, this->attrLength) < 0)
                  isSelected = true;
              break;
          case GT_OP:
              if (strncmp(strValue, cmpValue, this->attrLength) > 0)
                  isSelected = true;
              break;
          case LE_OP:
              if (strncmp(strValue, cmpValue, this->attrLength) <= 0)
                  isSelected = true;
              break;
          case GE_OP:
              if (strncmp(strValue, cmpValue, this->attrLength) >= 0)
                  isSelected = true;
              break;
          case NE_OP:
              if (strncmp(strValue, cmpValue, this->attrLength) != 0)
                  isSelected = true;
              break;
          case NO_OP:
              /* No comparision (when value is a null pointer) */
              isSelected = true;
              break;
          default:
              cout << "Compop error at compare FLOAT" << endl;
              break;
      }
    }

    incRID();
    ++recordScanNum;
  } while ((value != NULL) && !isSelected);

  rec = this->record;
  // rec.setData(this->record.data);
  // rec.rid = this->record.rid;
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, -0x50(%rbp)
movq %rdi, %r14
movq 0x5655(%rip), %r15      # 0x8fd8
leaq 0x2911(%rip), %rsi      # 0x629b
movl $0xa, %edx
movq %r15, %rdi
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movq (%r14), %rax
movl 0xc(%rax), %eax
movq %rsp, %rcx
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x60(%rbp)
movq %rcx, %rsp
leaq 0x34(%r14), %rbx
leaq 0x20(%r14), %r12
movl $0x0, -0x2c(%rbp)
leaq 0x28c0(%rip), %r13      # 0x62af
movq %r12, -0x38(%rbp)
movl 0x30(%r14), %eax
movq (%r14), %rdi
cmpl 0x68(%rdi), %eax
jl 0x3a51
jmp 0x3d87
movl $0x19, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movl 0x38(%r14), %eax
incl %eax
movq (%r14), %rdi
cmpl 0x64(%rdi), %eax
jl 0x3a4d
incl (%rbx)
xorl %eax, %eax
movl %eax, 0x38(%r14)
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2534
cmpl $0x6c, %eax
je 0x3a04
movq %r12, %rdi
movq -0x60(%rbp), %r12
movq %r12, %rsi
callq 0x45c0
movq %rsp, -0x40(%rbp)
movl 0xc(%r14), %eax
movq %rsp, %r13
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movslq 0x10(%r14), %rsi
addq %r12, %rsi
movslq 0xc(%r14), %rdx
movq %r13, %rdi
callq 0x2080
movl 0x8(%r14), %eax
cmpl $0x3, %eax
je 0x3bce
cmpl $0x2, %eax
je 0x3b86
cmpl $0x1, %eax
jne 0x3d44
movq 0x18(%r14), %r12
movl (%r13), %esi
movq %r15, %rdi
callq 0x21f0
movq %rax, -0x58(%rbp)
movl $0x3, %edx
movq %rax, %rdi
leaq 0x26d8(%rip), %rsi      # 0x61b6
callq 0x2170
movq %r12, -0x48(%rbp)
movl (%r12), %esi
movq -0x58(%rbp), %rdi
callq 0x21f0
movq %rax, %r12
movq (%rax), %rcx
movq -0x18(%rcx), %rdi
addq %rax, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r12, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movl 0x14(%r14), %eax
decl %eax
cmpl $0x6, %eax
ja 0x3cd8
leaq 0x2500(%rip), %rcx      # 0x6034
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%r13), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
movl -0x2c(%rbp), %esi
movzbl %sil, %esi
movl $0x1, %eax
cmovel %eax, %esi
movl %esi, -0x2c(%rbp)
andl $0x1, %esi
movq %r15, %rdi
callq 0x21d0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r13, %rdi
jmp 0x3c10
movl 0x14(%r14), %ecx
decl %ecx
cmpl $0x6, %ecx
ja 0x3be2
movq 0x18(%r14), %rax
leaq 0x247c(%rip), %rdx      # 0x6018
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movss (%r13), %xmm0
ucomiss (%rax), %xmm0
movq -0x38(%rbp), %r12
leaq 0x26f6(%rip), %r13      # 0x62af
movq -0x40(%rbp), %rdx
jne 0x3d53
jnp 0x3d08
jmp 0x3d53
movl 0x14(%r14), %eax
decl %eax
movb $0x1, %cl
movl %ecx, -0x2c(%rbp)
cmpl $0x7, %eax
jb 0x3d44
movl $0x1d, %edx
movq %r15, %rdi
leaq 0x26f4(%rip), %rsi      # 0x62e5
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
jmp 0x3d44
movb $0x1, %al
movl %eax, -0x2c(%rbp)
jmp 0x3d44
movss (%r13), %xmm0
ucomiss (%rax), %xmm0
jmp 0x3c68
movl (%r13), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
movl -0x2c(%rbp), %ecx
movzbl %cl, %ecx
movl $0x1, %eax
cmovlel %eax, %ecx
jmp 0x3d41
movss (%r13), %xmm0
ucomiss (%rax), %xmm0
jmp 0x3ca8
movss (%rax), %xmm0
ucomiss (%r13), %xmm0
movq -0x38(%rbp), %r12
leaq 0x263c(%rip), %r13      # 0x62af
movq -0x40(%rbp), %rdx
jae 0x3d08
jmp 0x3d53
movl (%r13), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
movl -0x2c(%rbp), %ecx
movzbl %cl, %ecx
movl $0x1, %eax
cmovll %eax, %ecx
jmp 0x3d41
movss (%rax), %xmm0
ucomiss (%r13), %xmm0
movq -0x38(%rbp), %r12
leaq 0x25fc(%rip), %r13      # 0x62af
movq -0x40(%rbp), %rdx
ja 0x3d08
jmp 0x3d53
movl (%r13), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
movl -0x2c(%rbp), %ecx
movzbl %cl, %ecx
movl $0x1, %eax
cmovgl %eax, %ecx
jmp 0x3d41
movl $0x1b, %edx
movq %r15, %rdi
leaq 0x25e2(%rip), %rsi      # 0x62c9
jmp 0x3bf1
movss (%r13), %xmm0
ucomiss (%rax), %xmm0
movq -0x38(%rbp), %r12
leaq 0x25af(%rip), %r13      # 0x62af
movq -0x40(%rbp), %rdx
jne 0x3d08
jnp 0x3d53
movb $0x1, %al
movl %eax, -0x2c(%rbp)
jmp 0x3d53
movl (%r13), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
movl -0x2c(%rbp), %ecx
movzbl %cl, %ecx
movl $0x1, %eax
cmovgel %eax, %ecx
jmp 0x3d41
movl (%r13), %eax
movq -0x48(%rbp), %rcx
cmpl (%rcx), %eax
movl -0x2c(%rbp), %ecx
movzbl %cl, %ecx
movl $0x1, %eax
cmovnel %eax, %ecx
movl %ecx, -0x2c(%rbp)
movq -0x38(%rbp), %r12
leaq 0x2560(%rip), %r13      # 0x62af
movq -0x40(%rbp), %rdx
movl 0x38(%r14), %eax
incl %eax
movq (%r14), %rcx
cmpl 0x64(%rcx), %eax
jl 0x3d65
incl (%rbx)
xorl %eax, %eax
movq %rdx, %rsp
movl %eax, 0x38(%r14)
incl 0x30(%r14)
cmpq $0x0, 0x18(%r14)
je 0x3d81
testb $0x1, -0x2c(%rbp)
je 0x39f3
movq (%r12), %rsi
jmp 0x3dda
leaq 0x2518(%rip), %rsi      # 0x62a6
movl $0x8, %edx
movq %r15, %rdi
callq 0x2170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movq (%r12), %rdi
testq %rdi, %rdi
je 0x3dd8
callq 0x2190
movq $0x0, (%r12)
xorl %esi, %esi
movq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x44ea
movq 0x28(%r14), %rax
movq %rax, 0x8(%rbx)
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop