// File: joao18araujo[P]pierluigi/src/ly_parser.cpp
// Function: LyParser::convert_file_to_simple_format(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void LyParser::convert_file_to_simple_format(string file_path, string output_path) {
  std::fstream file(file_path);

  string line, s;

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

  string s_scale = "", s_time = "", s_notes = "";
  Note note, prev;
  int note_count = 0;
  while(file >> s){
    if(s == "\\key" && s_scale == ""){
      string key, mode;
      file >> key >> mode;
      Scale scale = SongReader::string_to_scale(s + " " + key + " " + mode);
      s_scale = SongReader::scale_to_string(scale);
    }else if(s == "\\time" or s == "\\numericTimeSignature\\time"){
      string time_and_note;
      file >> time_and_note;
      CompassTime compass_time = SongReader::string_to_compass_time("\\time " + time_and_note);
      s_time = SongReader::compass_time_to_string(compass_time);
    }else if(s == "\\relative"){
      if(s_scale == ""){
        std::cerr << "Error: Lilypond with relative pitches\n";
        file.close();
        exit(-5);
      }
    }else{
      note = SongReader::string_to_note(prev, s);
      if(note.valid){
        prev = note;
        note_count++;
        if(note_count > 1){
          if(note_count % 10 == 1) s_notes += "\n";
          else s_notes += " ";
        }
        s_notes += SongReader::note_to_string(note);
      }
    }

    if(s == "}" and s_notes != "") break;
  }

  if(s_scale == ""){
    std::cerr << "Error: Lilypond without scale\n";
    file.close();
    exit(-3);
  }

  if(s_time == ""){
    std::cerr << "Error: Lilypond without time\n";
    file.close();
    exit(-4);
  }

  std::ofstream output(output_path);
  output << s_scale << std::endl;
  output << s_time << std::endl;
  output << s_notes << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa30, %rsp            # imm = 0xA30
movq %rdi, -0x9b0(%rbp)
movq %rsi, -0x9b8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x8, %edi
movl $0x10, %esi
callq 0x20d40
movq -0x9b0(%rbp), %rsi
movl %eax, %edx
leaq -0x220(%rbp), %rdi
movq %rdi, -0x9a8(%rbp)
callq 0x6770
leaq -0x240(%rbp), %rdi
callq 0x6650
leaq -0x260(%rbp), %rdi
callq 0x6650
movq -0x9a8(%rbp), %rdi
callq 0x67f0
movb %al, -0x999(%rbp)
jmp 0x1f4b8
movb -0x999(%rbp), %al
testb $0x1, %al
jne 0x1f4fa
jmp 0x1f4c4
movq 0x62b1d(%rip), %rdi     # 0x81fe8
leaq 0x40ce7(%rip), %rsi     # 0x601b9
callq 0x6480
jmp 0x1f4d9
movl $0xfffffffe, %edi       # imm = 0xFFFFFFFE
callq 0x6570
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1ffe9
leaq -0x291(%rbp), %rdi
movq %rdi, -0x9c0(%rbp)
callq 0x6830
movq -0x9c0(%rbp), %rdx
leaq 0x412b7(%rip), %rsi     # 0x607d2
leaq -0x290(%rbp), %rdi
callq 0xfb20
jmp 0x1f529
leaq -0x291(%rbp), %rdi
callq 0x64f0
leaq -0x2b9(%rbp), %rdi
movq %rdi, -0x9c8(%rbp)
callq 0x6830
movq -0x9c8(%rbp), %rdx
leaq 0x4127c(%rip), %rsi     # 0x607d2
leaq -0x2b8(%rbp), %rdi
callq 0xfb20
jmp 0x1f564
leaq -0x2b9(%rbp), %rdi
callq 0x64f0
leaq -0x2e1(%rbp), %rdi
movq %rdi, -0x9d0(%rbp)
callq 0x6830
movq -0x9d0(%rbp), %rdx
leaq 0x41241(%rip), %rsi     # 0x607d2
leaq -0x2e0(%rbp), %rdi
callq 0xfb20
jmp 0x1f59f
leaq -0x2e1(%rbp), %rdi
callq 0x64f0
leaq -0x340(%rbp), %rdi
callq 0x22dc0
jmp 0x1f5b9
leaq -0x398(%rbp), %rdi
callq 0x22dc0
jmp 0x1f5c7
movl $0x0, -0x39c(%rbp)
leaq -0x220(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x65e0
movq %rax, -0x9d8(%rbp)
jmp 0x1f5ed
movq -0x9d8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x65b0
movb %al, -0x9d9(%rbp)
jmp 0x1f60b
movb -0x9d9(%rbp), %al
testb $0x1, %al
jne 0x1f61a
jmp 0x1fdc5
leaq 0x40bdb(%rip), %rsi     # 0x601fc
leaq -0x260(%rbp), %rdi
callq 0xfff0
movb %al, -0x9da(%rbp)
jmp 0x1f635
movb -0x9da(%rbp), %al
testb $0x1, %al
jne 0x1f644
jmp 0x1f991
leaq 0x41187(%rip), %rsi     # 0x607d2
leaq -0x290(%rbp), %rdi
callq 0xfff0
movb %al, -0x9db(%rbp)
jmp 0x1f65f
movb -0x9db(%rbp), %al
testb $0x1, %al
jne 0x1f66e
jmp 0x1f991
leaq -0x3c0(%rbp), %rdi
movq %rdi, -0x9f0(%rbp)
callq 0x6650
leaq -0x3e0(%rbp), %rdi
callq 0x6650
movq -0x9f0(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x65e0
movq %rax, -0x9e8(%rbp)
jmp 0x1f6a9
movq -0x9e8(%rbp), %rdi
leaq -0x3e0(%rbp), %rsi
callq 0x65e0
jmp 0x1f6be
leaq 0x40b27(%rip), %rdx     # 0x601ec
leaq -0x510(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x20db0
jmp 0x1f6da
leaq -0x4f0(%rbp), %rdi
leaq -0x510(%rbp), %rsi
leaq -0x3c0(%rbp), %rdx
callq 0x20d60
jmp 0x1f6f6
leaq 0x40aef(%rip), %rdx     # 0x601ec
leaq -0x4d0(%rbp), %rdi
leaq -0x4f0(%rbp), %rsi
callq 0x1cb40
jmp 0x1f712
leaq -0x4b0(%rbp), %rdi
leaq -0x4d0(%rbp), %rsi
leaq -0x3e0(%rbp), %rdx
callq 0x20d60
jmp 0x1f72e
leaq -0x490(%rbp), %rdi
leaq -0x4b0(%rbp), %rsi
callq 0x2e970
jmp 0x1f743
leaq -0x4b0(%rbp), %rdi
callq 0x62d0
leaq -0x4d0(%rbp), %rdi
callq 0x62d0
leaq -0x4f0(%rbp), %rdi
callq 0x62d0
leaq -0x510(%rbp), %rdi
callq 0x62d0
leaq -0x5e0(%rbp), %rdi
leaq -0x490(%rbp), %rsi
callq 0x10110
jmp 0x1f788
leaq -0x530(%rbp), %rdi
leaq -0x5e0(%rbp), %rsi
callq 0x2ed00
jmp 0x1f79d
leaq -0x290(%rbp), %rdi
leaq -0x530(%rbp), %rsi
callq 0x6580
leaq -0x530(%rbp), %rdi
callq 0x62d0
leaq -0x5e0(%rbp), %rdi
callq 0x101b0
leaq -0x490(%rbp), %rdi
callq 0x101b0
leaq -0x3e0(%rbp), %rdi
callq 0x62d0
leaq -0x3c0(%rbp), %rdi
callq 0x62d0
jmp 0x1fd70
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x291(%rbp), %rdi
callq 0x64f0
jmp 0x1ffe9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x2b9(%rbp), %rdi
callq 0x64f0
jmp 0x1ffdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x2e1(%rbp), %rdi
callq 0x64f0
jmp 0x1ffd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1ffc5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1ffb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1ffad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1f974
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1f928
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1f91c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1f910
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x4b0(%rbp), %rdi
callq 0x62d0
leaq -0x4d0(%rbp), %rdi
callq 0x62d0
leaq -0x4f0(%rbp), %rdi
callq 0x62d0
leaq -0x510(%rbp), %rdi
callq 0x62d0
jmp 0x1f974
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1f968
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x5e0(%rbp), %rdi
callq 0x101b0
leaq -0x490(%rbp), %rdi
callq 0x101b0
leaq -0x3e0(%rbp), %rdi
callq 0x62d0
leaq -0x3c0(%rbp), %rdi
callq 0x62d0
jmp 0x1ffad
leaq 0x4087e(%rip), %rsi     # 0x60216
leaq -0x260(%rbp), %rdi
callq 0xfff0
movb %al, -0x9f1(%rbp)
jmp 0x1f9ac
movb -0x9f1(%rbp), %al
testb $0x1, %al
jne 0x1f9e2
jmp 0x1f9b8
leaq 0x40842(%rip), %rsi     # 0x60201
leaq -0x260(%rbp), %rdi
callq 0xfff0
movb %al, -0x9f2(%rbp)
jmp 0x1f9d3
movb -0x9f2(%rbp), %al
testb $0x1, %al
jne 0x1f9e2
jmp 0x1faeb
leaq -0x600(%rbp), %rdi
movq %rdi, -0xa00(%rbp)
callq 0x6650
movq -0xa00(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x65e0
jmp 0x1fa0a
leaq 0x4080b(%rip), %rsi     # 0x6021c
leaq -0x628(%rbp), %rdi
leaq -0x600(%rbp), %rdx
callq 0x20e30
jmp 0x1fa26
leaq -0x628(%rbp), %rdi
callq 0x2edd0
movq %rax, -0xa08(%rbp)
jmp 0x1fa3b
movq -0xa08(%rbp), %rax
movq %rax, -0x608(%rbp)
leaq -0x628(%rbp), %rdi
callq 0x62d0
movq -0x608(%rbp), %rax
movq %rax, -0x650(%rbp)
movq -0x650(%rbp), %rsi
leaq -0x648(%rbp), %rdi
callq 0x2ee90
jmp 0x1fa78
leaq -0x2b8(%rbp), %rdi
leaq -0x648(%rbp), %rsi
callq 0x6580
leaq -0x648(%rbp), %rdi
callq 0x62d0
leaq -0x600(%rbp), %rdi
callq 0x62d0
jmp 0x1fd6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1fada
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x628(%rbp), %rdi
callq 0x62d0
leaq -0x600(%rbp), %rdi
callq 0x62d0
jmp 0x1ffad
leaq 0x40731(%rip), %rsi     # 0x60223
leaq -0x260(%rbp), %rdi
callq 0xfff0
movb %al, -0xa09(%rbp)
jmp 0x1fb06
movb -0xa09(%rbp), %al
testb $0x1, %al
jne 0x1fb12
jmp 0x1fb6b
leaq 0x40cb9(%rip), %rsi     # 0x607d2
leaq -0x290(%rbp), %rdi
callq 0xfff0
movb %al, -0xa0a(%rbp)
jmp 0x1fb2d
movb -0xa0a(%rbp), %al
testb $0x1, %al
jne 0x1fb39
jmp 0x1fb66
movq 0x624a8(%rip), %rdi     # 0x81fe8
leaq 0x406e6(%rip), %rsi     # 0x6022d
callq 0x6480
jmp 0x1fb4e
leaq -0x220(%rbp), %rdi
callq 0x60a0
jmp 0x1fb5c
movl $0xfffffffb, %edi       # imm = 0xFFFFFFFB
callq 0x6570
jmp 0x1fd6c
leaq -0x700(%rbp), %rdi
leaq -0x398(%rbp), %rsi
callq 0x22ce0
jmp 0x1fb80
leaq -0x720(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x61f0
jmp 0x1fb95
leaq -0x6a8(%rbp), %rdi
leaq -0x700(%rbp), %rsi
leaq -0x720(%rbp), %rdx
callq 0x2de50
jmp 0x1fbb1
leaq -0x340(%rbp), %rdi
leaq -0x6a8(%rbp), %rsi
callq 0xfe00
jmp 0x1fbc6
leaq -0x6a8(%rbp), %rdi
callq 0xfd80
leaq -0x720(%rbp), %rdi
callq 0x62d0
leaq -0x700(%rbp), %rdi
callq 0xfd80
testb $0x1, -0x2ec(%rbp)
je 0x1fd6a
leaq -0x398(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0xfe00
jmp 0x1fc0c
movl -0x39c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x39c(%rbp)
cmpl $0x1, -0x39c(%rbp)
jle 0x1fcce
movl -0x39c(%rbp), %eax
movl $0xa, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x1fcb5
leaq 0x40c60(%rip), %rsi     # 0x608a2
leaq -0x2e0(%rbp), %rdi
callq 0x6450
jmp 0x1fc50
jmp 0x1fccc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1fca4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1fc98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x6a8(%rbp), %rdi
callq 0xfd80
leaq -0x720(%rbp), %rdi
callq 0x62d0
leaq -0x700(%rbp), %rdi
callq 0xfd80
jmp 0x1ffad
leaq 0x40530(%rip), %rsi     # 0x601ec
leaq -0x2e0(%rbp), %rdi
callq 0x6450
jmp 0x1fcca
jmp 0x1fccc
jmp 0x1fcce
leaq -0x798(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0x22ce0
jmp 0x1fce3
leaq -0x740(%rbp), %rdi
leaq -0x798(%rbp), %rsi
callq 0x2e5a0
jmp 0x1fcf8
leaq -0x2e0(%rbp), %rdi
leaq -0x740(%rbp), %rsi
callq 0x65f0
jmp 0x1fd0d
leaq -0x740(%rbp), %rdi
callq 0x62d0
leaq -0x798(%rbp), %rdi
callq 0xfd80
jmp 0x1fd6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
jmp 0x1fd59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x740(%rbp), %rdi
callq 0x62d0
leaq -0x798(%rbp), %rdi
callq 0xfd80
jmp 0x1ffad
jmp 0x1fd6c
jmp 0x1fd6e
jmp 0x1fd70
leaq 0x404dd(%rip), %rsi     # 0x60254
leaq -0x260(%rbp), %rdi
callq 0xfff0
movb %al, -0xa0b(%rbp)
jmp 0x1fd8b
movb -0xa0b(%rbp), %al
testb $0x1, %al
jne 0x1fd97
jmp 0x1fdc0
leaq 0x40a34(%rip), %rsi     # 0x607d2
leaq -0x2e0(%rbp), %rdi
callq 0xfe70
movb %al, -0xa0c(%rbp)
jmp 0x1fdb2
movb -0xa0c(%rbp), %al
testb $0x1, %al
jne 0x1fdbe
jmp 0x1fdc0
jmp 0x1fdc5
jmp 0x1f5d1
leaq 0x40a06(%rip), %rsi     # 0x607d2
leaq -0x290(%rbp), %rdi
callq 0xfff0
movb %al, -0xa0d(%rbp)
jmp 0x1fde0
movb -0xa0d(%rbp), %al
testb $0x1, %al
jne 0x1fdec
jmp 0x1fe19
movq 0x621f5(%rip), %rdi     # 0x81fe8
leaq 0x4045c(%rip), %rsi     # 0x60256
callq 0x6480
jmp 0x1fe01
leaq -0x220(%rbp), %rdi
callq 0x60a0
jmp 0x1fe0f
movl $0xfffffffd, %edi       # imm = 0xFFFFFFFD
callq 0x6570
leaq 0x409b2(%rip), %rsi     # 0x607d2
leaq -0x2b8(%rbp), %rdi
callq 0xfff0
movb %al, -0xa0e(%rbp)
jmp 0x1fe34
movb -0xa0e(%rbp), %al
testb $0x1, %al
jne 0x1fe40
jmp 0x1fe6d
movq 0x621a1(%rip), %rdi     # 0x81fe8
leaq 0x40427(%rip), %rsi     # 0x60275
callq 0x6480
jmp 0x1fe55
leaq -0x220(%rbp), %rdi
callq 0x60a0
jmp 0x1fe63
movl $0xfffffffc, %edi       # imm = 0xFFFFFFFC
callq 0x6570
movq -0x9b8(%rbp), %rsi
leaq -0x998(%rbp), %rdi
movl $0x10, %edx
callq 0x68a0
jmp 0x1fe87
leaq -0x998(%rbp), %rdi
leaq -0x290(%rbp), %rsi
callq 0x6410
movq %rax, -0xa18(%rbp)
jmp 0x1fea3
movq -0xa18(%rbp), %rdi
movq 0x620cf(%rip), %rsi     # 0x81f80
callq 0x64d0
jmp 0x1feb8
leaq -0x998(%rbp), %rdi
leaq -0x2b8(%rbp), %rsi
callq 0x6410
movq %rax, -0xa20(%rbp)
jmp 0x1fed4
movq -0xa20(%rbp), %rdi
movq 0x6209e(%rip), %rsi     # 0x81f80
callq 0x64d0
jmp 0x1fee9
leaq -0x998(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x6410
movq %rax, -0xa28(%rbp)
jmp 0x1ff05
movq -0xa28(%rbp), %rdi
movq 0x6206d(%rip), %rsi     # 0x81f80
callq 0x64d0
jmp 0x1ff1a
leaq -0x998(%rbp), %rdi
callq 0x66c0
leaq -0x398(%rbp), %rdi
callq 0xfd80
leaq -0x340(%rbp), %rdi
callq 0xfd80
leaq -0x2e0(%rbp), %rdi
callq 0x62d0
leaq -0x2b8(%rbp), %rdi
callq 0x62d0
leaq -0x290(%rbp), %rdi
callq 0x62d0
leaq -0x260(%rbp), %rdi
callq 0x62d0
leaq -0x240(%rbp), %rdi
callq 0x62d0
leaq -0x220(%rbp), %rdi
callq 0x6100
addq $0xa30, %rsp            # imm = 0xA30
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x268(%rbp)
movl %eax, -0x26c(%rbp)
leaq -0x998(%rbp), %rdi
callq 0x66c0
leaq -0x398(%rbp), %rdi
callq 0xfd80
leaq -0x340(%rbp), %rdi
callq 0xfd80
leaq -0x2e0(%rbp), %rdi
callq 0x62d0
leaq -0x2b8(%rbp), %rdi
callq 0x62d0
leaq -0x290(%rbp), %rdi
callq 0x62d0
leaq -0x260(%rbp), %rdi
callq 0x62d0
leaq -0x240(%rbp), %rdi
callq 0x62d0
leaq -0x220(%rbp), %rdi
callq 0x6100
movq -0x268(%rbp), %rdi
callq 0x6820
nopl (%rax)