// File: /workspace/github_cpp_makefile_star2_O2/joao18araujo[P]pierluigi/src/ly_parser.cpp
// Function: LyParser::read_file(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
Song LyParser::read_file(string file_path, bool print){
  std::fstream file(file_path);
  string line, s_note;
  Note prev, note;
  int absolute_time = 0;

  if(!file.is_open()){
    std::cerr << "Error: File not found\n";
    exit(-1);
  }

  getline(file, line);
  Scale scale = SongReader::string_to_scale(line);
  if(print) printf("Key: %s %s\n", scale.base_note.note.c_str(), scale.mode.c_str());

  getline(file, line);
  CompassTime compass_time = SongReader::string_to_compass_time(line);
  if(print) printf("Time: %d/%d\n", compass_time.times, compass_time.base_note);

  Song song(scale, compass_time);

  while(file >> s_note){
    note = SongReader::string_to_note(prev, s_note);
    if(!note.valid) continue;

    note.absolute_time = absolute_time;
    absolute_time += note.duration;

    if(print) std::cout << "[" << s_note << "] ";
    if(print) std::cout << note.description();

    if(prev.valid){
      Interval interval(prev, note);
      Interval new_int(interval.description(), interval.direction);
      Note expected = Interval::interval_to_note(prev,interval);
      if(print){
        std::cout << " | " << interval.full_description() << "," << new_int.full_description() << " | ";
        if(expected.valid) std::cout << expected.description();
        else std::cout << "nullptr";
      }
    }
    if(print) std::cout << std::endl;
    prev = note;
    song.notes.push_back(note);
  }

  file.close();
  return song;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x788, %rsp            # imm = 0x788
movl %edx, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
leaq 0x578(%rsp), %rdi
pushq $0x18
popq %rdx
callq 0x5570
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x120(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x260(%rsp), %rdi
callq 0x12712
leaq 0x190(%rsp), %rdi
callq 0x12712
leaq 0x5f8(%rsp), %rdi
callq 0x50e0
testb %al, %al
je 0x10539
leaq 0x578(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x50a0
leaq 0xf0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x5480
leaq 0x3c0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x1834e
leaq 0xf0(%rsp), %rdi
callq 0x51b0
cmpb $0x0, 0x8(%rsp)
je 0x100ed
movq 0x400(%rsp), %rsi
movq 0x450(%rsp), %rdx
leaq 0x1910a(%rip), %rdi     # 0x291f0
xorl %eax, %eax
callq 0x5060
leaq 0x578(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x50a0
leaq 0xd0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x5480
leaq 0xd0(%rsp), %rdi
callq 0x18626
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x51b0
cmpb $0x0, 0x8(%rsp)
je 0x1014c
movq %rbx, %rdx
shrq $0x20, %rdx
leaq 0x190b9(%rip), %rdi     # 0x291fc
movl %ebx, %esi
xorl %eax, %eax
callq 0x5060
leaq 0x4c8(%rsp), %rdi
leaq 0x3c0(%rsp), %rsi
callq 0x98ec
leaq 0x4c8(%rsp), %rsi
movq 0x10(%rsp), %rdi
movq %rbx, %rdx
callq 0xc2ce
leaq 0x4c8(%rsp), %rdi
callq 0x9946
movl $0x0, 0xc(%rsp)
leaq 0x110(%rsp), %r14
leaq 0x470(%rsp), %r15
leaq 0x260(%rsp), %r12
leaq 0x1e8(%rsp), %rbx
leaq 0x208(%rsp), %rbp
leaq 0x190(%rsp), %r13
leaq 0x578(%rsp), %rdi
movq %r14, %rsi
callq 0x5440
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x104ca
movq %r15, %rdi
movq %r12, %rsi
callq 0x12676
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5480
movq %rbp, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x17d8c
movq %r13, %rdi
movq %rbp, %rsi
callq 0x97e8
movq %rbp, %rdi
callq 0x979a
movq %rbx, %rdi
callq 0x51b0
movq %r15, %rdi
callq 0x979a
cmpb $0x0, 0x1e4(%rsp)
je 0x101bb
movl 0xc(%rsp), %eax
movl %eax, 0x194(%rsp)
addl 0x190(%rsp), %eax
movl %eax, 0xc(%rsp)
cmpb $0x0, 0x8(%rsp)
je 0x1029a
movq 0x29d56(%rip), %rdi     # 0x39fa8
leaq 0x18fb0(%rip), %rsi     # 0x29209
callq 0x5350
movq %rax, %rdi
movq %r14, %rsi
callq 0x5310
movq %rax, %rdi
leaq 0x18f98(%rip), %rsi     # 0x2920b
callq 0x5350
movq %rbp, %rdi
movq %r13, %rsi
callq 0x12a6e
movq 0x29d1e(%rip), %rdi     # 0x39fa8
movq %rbp, %rsi
callq 0x5310
movq %rbp, %rdi
callq 0x51b0
cmpb $0x1, 0x2b4(%rsp)
jne 0x1049a
leaq 0x368(%rsp), %rdi
movq %r12, %rsi
callq 0x12676
leaq 0x310(%rsp), %rdi
movq %r13, %rsi
callq 0x12676
leaq 0x60(%rsp), %rdi
leaq 0x368(%rsp), %rsi
leaq 0x310(%rsp), %rdx
callq 0xf41a
leaq 0x310(%rsp), %rdi
callq 0x979a
leaq 0x368(%rsp), %rdi
callq 0x979a
leaq 0xb0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xf548
xorl %edx, %edx
cmpw $0x0, 0x8c(%rsp)
setne %dl
leaq 0x160(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0xf280
leaq 0xb0(%rsp), %rdi
callq 0x51b0
leaq 0x2b8(%rsp), %rdi
movq %r12, %rsi
callq 0x12676
leaq 0x130(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x97b4
movq %rbp, %rdi
leaq 0x2b8(%rsp), %rsi
leaq 0x130(%rsp), %rdx
callq 0xf750
leaq 0x138(%rsp), %rdi
callq 0x51b0
leaq 0x2b8(%rsp), %rdi
callq 0x979a
cmpb $0x0, 0x8(%rsp)
je 0x1047b
movq 0x29c04(%rip), %rdi     # 0x39fa8
leaq 0x18e63(%rip), %rsi     # 0x2920e
callq 0x5350
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xf62e
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x5310
movq %rax, %rdi
leaq 0x18e35(%rip), %rsi     # 0x29212
callq 0x5350
movq %rax, 0x18(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0xf62e
movq 0x18(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x5310
movq %rax, %rdi
leaq 0x18df6(%rip), %rsi     # 0x2920e
callq 0x5350
leaq 0x90(%rsp), %rdi
callq 0x51b0
leaq 0x20(%rsp), %rdi
callq 0x51b0
cmpb $0x1, 0x25c(%rsp)
jne 0x10468
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x12a6e
movq 0x29b56(%rip), %rdi     # 0x39fa8
leaq 0x20(%rsp), %rsi
callq 0x5310
leaq 0x20(%rsp), %rdi
callq 0x51b0
jmp 0x1047b
movq 0x29b39(%rip), %rdi     # 0x39fa8
leaq 0x18d9e(%rip), %rsi     # 0x29214
callq 0x5350
movq %rbp, %rdi
callq 0x979a
leaq 0x168(%rsp), %rdi
callq 0x51b0
leaq 0x68(%rsp), %rdi
callq 0x51b0
cmpb $0x0, 0x8(%rsp)
je 0x104ad
movq 0x29b00(%rip), %rdi     # 0x39fa8
callq 0x51d0
movq %r12, %rdi
movq %r13, %rsi
callq 0x97e8
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x986e
jmp 0x101bb
leaq 0x578(%rsp), %rdi
callq 0x5070
leaq 0x3c0(%rsp), %rdi
callq 0x9946
leaq 0x190(%rsp), %rdi
callq 0x979a
leaq 0x260(%rsp), %rdi
callq 0x979a
leaq 0x110(%rsp), %rdi
callq 0x51b0
leaq 0x40(%rsp), %rdi
callq 0x51b0
leaq 0x578(%rsp), %rdi
callq 0x50c0
movq 0x10(%rsp), %rax
addq $0x788, %rsp            # imm = 0x788
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x29aa8(%rip), %rdi     # 0x39fe8
leaq 0x18c92(%rip), %rsi     # 0x291d9
callq 0x5350
pushq $-0x1
popq %rdi
callq 0x53f0
jmp 0x10580
jmp 0x1055c
jmp 0x10580
jmp 0x1055c
movq %rax, %rbx
jmp 0x1058d
movq %rax, %rbx
jmp 0x105fc
jmp 0x106ab
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x51b0
jmp 0x10583
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x51b0
leaq 0x208(%rsp), %rdi
jmp 0x105b4
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0x51b0
jmp 0x105ac
movq %rax, %rbx
leaq 0x2b8(%rsp), %rdi
callq 0x979a
leaq 0x168(%rsp), %rdi
callq 0x51b0
leaq 0x68(%rsp), %rdi
callq 0x51b0
jmp 0x106ae
movq %rax, %rbx
jmp 0x105b9
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
jmp 0x105c1
movq %rax, %rbx
jmp 0x105c6
movq %rax, %rbx
leaq 0x310(%rsp), %rdi
callq 0x979a
leaq 0x368(%rsp), %rdi
jmp 0x106a2
movq %rax, %rbx
leaq 0x208(%rsp), %rdi
jmp 0x105cb
jmp 0x106ab
jmp 0x106ab
movq %rax, %rbx
leaq 0x4c8(%rsp), %rdi
callq 0x9946
jmp 0x106b8
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x51b0
jmp 0x106b8
jmp 0x1066c
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x51b0
jmp 0x106c5
jmp 0x10667
movq %rax, %rbx
jmp 0x106d2
movq %rax, %rbx
jmp 0x106df
movq %rax, %rbx
jmp 0x106c5
movq %rax, %rbx
jmp 0x106b8
jmp 0x106ab
movq %rax, %rbx
jmp 0x10688
movq %rax, %rbx
leaq 0x208(%rsp), %rdi
callq 0x979a
leaq 0x1e8(%rsp), %rdi
callq 0x51b0
jmp 0x1069a
movq %rax, %rbx
leaq 0x470(%rsp), %rdi
callq 0x979a
jmp 0x106ae
jmp 0x106ab
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0xc3b0
leaq 0x3c0(%rsp), %rdi
callq 0x9946
leaq 0x190(%rsp), %rdi
callq 0x979a
leaq 0x260(%rsp), %rdi
callq 0x979a
leaq 0x110(%rsp), %rdi
callq 0x51b0
leaq 0x40(%rsp), %rdi
callq 0x51b0
leaq 0x578(%rsp), %rdi
callq 0x50c0
movq %rbx, %rdi
callq 0x55d0
nop