// File: 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
movq %rsp, %rbp
subq $0x8c0, %rsp            # imm = 0x8C0
movq %rsi, -0x850(%rbp)
movq %rdi, -0x860(%rbp)
movb %dl, %al
movq %rdi, %rcx
movq %rcx, -0x858(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movl $0x8, %edi
movl $0x10, %esi
callq 0x20d40
movq -0x850(%rbp), %rsi
movl %eax, %edx
leaq -0x228(%rbp), %rdi
callq 0x6770
leaq -0x248(%rbp), %rdi
callq 0x6650
leaq -0x268(%rbp), %rdi
callq 0x6650
leaq -0x2c0(%rbp), %rdi
callq 0x22dc0
jmp 0x1ea8c
leaq -0x328(%rbp), %rdi
callq 0x22dc0
jmp 0x1ea9a
movl $0x0, -0x32c(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x67f0
movb %al, -0x861(%rbp)
jmp 0x1eab8
movb -0x861(%rbp), %al
testb $0x1, %al
jne 0x1eb28
jmp 0x1eac4
movq 0x6351d(%rip), %rdi     # 0x81fe8
leaq 0x416e7(%rip), %rsi     # 0x601b9
callq 0x6480
jmp 0x1ead9
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x6570
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f407
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f3fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f3ef
leaq -0x228(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x60e0
jmp 0x1eb3d
leaq -0x400(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x61f0
jmp 0x1eb52
leaq -0x3e0(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0x2e970
jmp 0x1eb67
leaq -0x400(%rbp), %rdi
callq 0x62d0
testb $0x1, -0x11(%rbp)
je 0x1ebee
leaq -0x3a0(%rbp), %rdi
callq 0x61d0
movq %rax, -0x870(%rbp)
leaq -0x350(%rbp), %rdi
callq 0x61d0
movq -0x870(%rbp), %rsi
movq %rax, %rdx
leaq 0x41627(%rip), %rdi     # 0x601d0
xorl %eax, %eax
callq 0x6090
jmp 0x1ebb2
jmp 0x1ebee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x400(%rbp), %rdi
callq 0x62d0
jmp 0x1f3ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f3e3
leaq -0x228(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x60e0
jmp 0x1ec03
leaq -0x428(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x61f0
jmp 0x1ec18
leaq -0x428(%rbp), %rdi
callq 0x2edd0
movq %rax, -0x878(%rbp)
jmp 0x1ec2d
movq -0x878(%rbp), %rax
movq %rax, -0x408(%rbp)
leaq -0x428(%rbp), %rdi
callq 0x62d0
testb $0x1, -0x11(%rbp)
je 0x1ec8e
movl -0x408(%rbp), %esi
movl -0x404(%rbp), %edx
leaq 0x4157c(%rip), %rdi     # 0x601dc
xorl %eax, %eax
callq 0x6090
jmp 0x1ec69
jmp 0x1ec8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x428(%rbp), %rdi
callq 0x62d0
jmp 0x1f3e3
movb $0x0, -0x429(%rbp)
leaq -0x4e0(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
callq 0x10110
jmp 0x1ecaa
movq -0x860(%rbp), %rdi
movq -0x408(%rbp), %rax
movq %rax, -0x4e8(%rbp)
movq -0x4e8(%rbp), %rdx
leaq -0x4e0(%rbp), %rsi
callq 0x165a0
jmp 0x1ecd4
leaq -0x4e0(%rbp), %rdi
callq 0x101b0
leaq -0x228(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x65e0
movq %rax, -0x880(%rbp)
jmp 0x1ecfc
movq -0x880(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x65b0
movb %al, -0x881(%rbp)
jmp 0x1ed1a
movb -0x881(%rbp), %al
testb $0x1, %al
jne 0x1ed29
jmp 0x1f355
leaq -0x598(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x22ce0
jmp 0x1ed3e
leaq -0x5b8(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x61f0
jmp 0x1ed53
leaq -0x540(%rbp), %rdi
leaq -0x598(%rbp), %rsi
leaq -0x5b8(%rbp), %rdx
callq 0x2de50
jmp 0x1ed6f
leaq -0x328(%rbp), %rdi
leaq -0x540(%rbp), %rsi
callq 0xfe00
jmp 0x1ed84
leaq -0x540(%rbp), %rdi
callq 0xfd80
leaq -0x5b8(%rbp), %rdi
callq 0x62d0
leaq -0x598(%rbp), %rdi
callq 0xfd80
testb $0x1, -0x2d4(%rbp)
jne 0x1ee57
jmp 0x1ece0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x4e0(%rbp), %rdi
callq 0x101b0
jmp 0x1f3e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f3d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1ee46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1ee3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x540(%rbp), %rdi
callq 0xfd80
leaq -0x5b8(%rbp), %rdi
callq 0x62d0
leaq -0x598(%rbp), %rdi
callq 0xfd80
jmp 0x1f3d7
movl -0x32c(%rbp), %eax
movl %eax, -0x324(%rbp)
movl -0x328(%rbp), %eax
addl -0x32c(%rbp), %eax
movl %eax, -0x32c(%rbp)
testb $0x1, -0x11(%rbp)
je 0x1eeca
movq 0x63126(%rip), %rdi     # 0x81fa8
leaq 0x41360(%rip), %rsi     # 0x601e9
callq 0x6480
movq %rax, -0x890(%rbp)
jmp 0x1ee97
movq -0x890(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x6410
movq %rax, -0x898(%rbp)
jmp 0x1eeb3
movq -0x898(%rbp), %rdi
leaq 0x4132a(%rip), %rsi     # 0x601eb
callq 0x6480
jmp 0x1eec8
jmp 0x1eeca
testb $0x1, -0x11(%rbp)
je 0x1ef2b
leaq -0x5d8(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x23360
jmp 0x1eee5
movq 0x630bc(%rip), %rdi     # 0x81fa8
leaq -0x5d8(%rbp), %rsi
callq 0x6410
jmp 0x1eefa
leaq -0x5d8(%rbp), %rdi
callq 0x62d0
jmp 0x1ef2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x5d8(%rbp), %rdi
callq 0x62d0
jmp 0x1f3d7
testb $0x1, -0x26c(%rbp)
je 0x1f309
leaq -0x660(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x22ce0
jmp 0x1ef4d
leaq -0x6b8(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0x22ce0
jmp 0x1ef62
leaq -0x608(%rbp), %rdi
leaq -0x660(%rbp), %rsi
leaq -0x6b8(%rbp), %rdx
callq 0x1bf30
jmp 0x1ef7e
leaq -0x6b8(%rbp), %rdi
callq 0xfd80
leaq -0x660(%rbp), %rdi
callq 0xfd80
leaq -0x708(%rbp), %rdi
leaq -0x608(%rbp), %rsi
callq 0x1c100
jmp 0x1efab
movw -0x5dc(%rbp), %ax
testw %ax, %ax
setne %al
movzbl %al, %edx
leaq -0x6e8(%rbp), %rdi
leaq -0x708(%rbp), %rsi
callq 0x1bbe0
jmp 0x1efd0
leaq -0x708(%rbp), %rdi
callq 0x62d0
leaq -0x7b8(%rbp), %rdi
leaq -0x2c0(%rbp), %rsi
callq 0x22ce0
jmp 0x1eff1
leaq -0x7e8(%rbp), %rdi
leaq -0x608(%rbp), %rsi
callq 0xfdb0
jmp 0x1f006
leaq -0x760(%rbp), %rdi
leaq -0x7b8(%rbp), %rsi
leaq -0x7e8(%rbp), %rdx
callq 0x1c440
jmp 0x1f022
leaq -0x7e8(%rbp), %rdi
callq 0xfc90
leaq -0x7b8(%rbp), %rdi
callq 0xfd80
testb $0x1, -0x11(%rbp)
je 0x1f2ba
movq 0x62f5d(%rip), %rdi     # 0x81fa8
leaq 0x4119c(%rip), %rsi     # 0x601ee
callq 0x6480
movq %rax, -0x8a0(%rbp)
jmp 0x1f060
leaq -0x808(%rbp), %rdi
leaq -0x608(%rbp), %rsi
callq 0x1c290
jmp 0x1f075
movq -0x8a0(%rbp), %rdi
leaq -0x808(%rbp), %rsi
callq 0x6410
movq %rax, -0x8a8(%rbp)
jmp 0x1f091
movq -0x8a8(%rbp), %rdi
leaq 0x41153(%rip), %rsi     # 0x601f2
callq 0x6480
movq %rax, -0x8b0(%rbp)
jmp 0x1f0ad
leaq -0x828(%rbp), %rdi
leaq -0x6e8(%rbp), %rsi
callq 0x1c290
jmp 0x1f0c2
movq -0x8b0(%rbp), %rdi
leaq -0x828(%rbp), %rsi
callq 0x6410
movq %rax, -0x8b8(%rbp)
jmp 0x1f0de
movq -0x8b8(%rbp), %rdi
leaq 0x41102(%rip), %rsi     # 0x601ee
callq 0x6480
jmp 0x1f0f3
leaq -0x828(%rbp), %rdi
callq 0x62d0
leaq -0x808(%rbp), %rdi
callq 0x62d0
testb $0x1, -0x70c(%rbp)
je 0x1f2a1
leaq -0x848(%rbp), %rdi
leaq -0x760(%rbp), %rsi
callq 0x23360
jmp 0x1f12d
movq 0x62e74(%rip), %rdi     # 0x81fa8
leaq -0x848(%rbp), %rsi
callq 0x6410
jmp 0x1f142
leaq -0x848(%rbp), %rdi
callq 0x62d0
jmp 0x1f2b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f185
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x6b8(%rbp), %rdi
callq 0xfd80
leaq -0x660(%rbp), %rdi
callq 0xfd80
jmp 0x1f3d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f2f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x708(%rbp), %rdi
callq 0x62d0
jmp 0x1f2f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f2ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f219
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x7e8(%rbp), %rdi
callq 0xfc90
leaq -0x7b8(%rbp), %rdi
callq 0xfd80
jmp 0x1f2ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f2e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
jmp 0x1f273
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x828(%rbp), %rdi
callq 0x62d0
leaq -0x808(%rbp), %rdi
callq 0x62d0
jmp 0x1f2e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2c8(%rbp)
movl %eax, -0x2cc(%rbp)
leaq -0x848(%rbp), %rdi
callq 0x62d0
jmp 0x1f2e0
movq 0x62d00(%rip), %rdi     # 0x81fa8
leaq 0x40f45(%rip), %rsi     # 0x601f4
callq 0x6480
jmp 0x1f2b6
jmp 0x1f2b8
jmp 0x1f2ba
leaq -0x760(%rbp), %rdi
callq 0xfd80
leaq -0x6e8(%rbp), %rdi
callq 0xfc90
leaq -0x608(%rbp), %rdi
callq 0xfc90
jmp 0x1f309
leaq -0x760(%rbp), %rdi
callq 0xfd80
leaq -0x6e8(%rbp), %rdi
callq 0xfc90
leaq -0x608(%rbp), %rdi
callq 0xfc90
jmp 0x1f3d7
testb $0x1, -0x11(%rbp)
je 0x1f326
movq 0x62c92(%rip), %rdi     # 0x81fa8
movq 0x62c63(%rip), %rsi     # 0x81f80
callq 0x64d0
jmp 0x1f324
jmp 0x1f326
leaq -0x2c0(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0xfe00
jmp 0x1f33b
movq -0x860(%rbp), %rdi
leaq -0x328(%rbp), %rsi
callq 0xff80
jmp 0x1f350
jmp 0x1ece0
leaq -0x228(%rbp), %rdi
callq 0x60a0
jmp 0x1f363
movb $0x1, -0x429(%rbp)
testb $0x1, -0x429(%rbp)
jne 0x1f37f
movq -0x860(%rbp), %rdi
callq 0x16720
leaq -0x3e0(%rbp), %rdi
callq 0x101b0
leaq -0x328(%rbp), %rdi
callq 0xfd80
leaq -0x2c0(%rbp), %rdi
callq 0xfd80
leaq -0x268(%rbp), %rdi
callq 0x62d0
leaq -0x248(%rbp), %rdi
callq 0x62d0
leaq -0x228(%rbp), %rdi
callq 0x6100
movq -0x858(%rbp), %rax
addq $0x8c0, %rsp            # imm = 0x8C0
popq %rbp
retq
movq -0x860(%rbp), %rdi
callq 0x16720
leaq -0x3e0(%rbp), %rdi
callq 0x101b0
leaq -0x328(%rbp), %rdi
callq 0xfd80
leaq -0x2c0(%rbp), %rdi
callq 0xfd80
leaq -0x268(%rbp), %rdi
callq 0x62d0
leaq -0x248(%rbp), %rdi
callq 0x62d0
leaq -0x228(%rbp), %rdi
callq 0x6100
movq -0x2c8(%rbp), %rdi
callq 0x6820
nopw (%rax,%rax)