// File: joao18araujo[P]pierluigi/src/song_reader.cpp
// Function: SongReader::string_to_note(Note, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Note SongReader::string_to_note(Note prev, string s){
  if(!regex_match(s, regex("[a-gr][ies]*[\',]*\\d*\\.*~?")))
    return Note();

  string accidental = "", modifier = "";
	string note = "";
	int duration = 0, dots = 0;
  int octave = BELOW_MIDDLE_C_OCTAVE;
  bool linked = false;

	note += s[0];
	s.erase(s.begin());
	for (auto & c : s){
		if (isdigit(c)){
			duration *= 10;
			duration += (c - '0');
		} else if (isalpha(c))
			accidental += c;
		else if(c == '.')
      dots++;
    else if(c == '~')
        linked = true;
    else
			modifier += c;
	}

  for (auto& c : modifier){
    if (c == '\'')
      octave++;
    else if (c == ',')
      octave--;
  }

  if(duration){
    //TODO setar valor mínimo (fusa atualmente)
    duration = (duration ? QUANT / duration : duration);
    int increment = duration / 2;
    while(dots--){
      duration += increment;
      increment /= 2;
    }
  }
  else
    duration = prev.duration;

  accidental = regex_replace(accidental, regex("is"), "#");
  accidental = regex_replace(accidental, regex("es"), "\u266D");

	Note n(note, accidental, octave, duration, linked);
  n.valid = (duration != 0);
  return n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdx, -0x210(%rbp)
movq %rsi, -0x228(%rbp)
movq %rdi, -0x220(%rbp)
movq %rdi, %rax
movq %rax, -0x218(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x328b3(%rip), %rsi     # 0x60740
leaq -0x38(%rbp), %rdi
movq %rdi, -0x208(%rbp)
movl $0x10, %edx
callq 0x2fab0
movq -0x210(%rbp), %rdi
movq -0x208(%rbp), %rsi
xorl %edx, %edx
callq 0x2fa60
movb %al, -0x1f9(%rbp)
jmp 0x2debf
movb -0x1f9(%rbp), %al
xorb $-0x1, %al
movb %al, -0x229(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2fb50
movb -0x229(%rbp), %al
testb $0x1, %al
jne 0x2dee2
jmp 0x2df0d
movq -0x220(%rbp), %rdi
callq 0x22dc0
jmp 0x2e587
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2fb50
jmp 0x2e597
leaq -0x69(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x6830
movq -0x238(%rbp), %rdx
leaq 0x328a7(%rip), %rsi     # 0x607d2
leaq -0x68(%rbp), %rdi
callq 0xfb20
jmp 0x2df36
leaq -0x69(%rbp), %rdi
callq 0x64f0
leaq -0x91(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x6830
movq -0x240(%rbp), %rdx
leaq 0x32872(%rip), %rsi     # 0x607d2
leaq -0x90(%rbp), %rdi
callq 0xfb20
jmp 0x2df6e
leaq -0x91(%rbp), %rdi
callq 0x64f0
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x6830
movq -0x248(%rbp), %rdx
leaq 0x32837(%rip), %rsi     # 0x607d2
leaq -0xb8(%rbp), %rdi
callq 0xfb20
jmp 0x2dfa9
leaq -0xb9(%rbp), %rdi
callq 0x64f0
movq -0x210(%rbp), %rdi
movl $0x0, -0xc0(%rbp)
movl $0x0, -0xc4(%rbp)
movl $0x3, -0xc8(%rbp)
movb $0x0, -0xc9(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0x68e0
movq %rax, -0x250(%rbp)
jmp 0x2dff3
movq -0x250(%rbp), %rax
movsbl (%rax), %esi
leaq -0xb8(%rbp), %rdi
callq 0x62f0
jmp 0x2e00b
movq -0x210(%rbp), %rdi
callq 0x63f0
movq %rax, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x24050
movq -0x210(%rbp), %rdi
movq -0xd8(%rbp), %rsi
callq 0x6590
movq %rax, -0x258(%rbp)
jmp 0x2e04d
movq -0x210(%rbp), %rax
movq -0x258(%rbp), %rcx
movq %rcx, -0xe8(%rbp)
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rdi
callq 0x63f0
movq %rax, -0xf8(%rbp)
movq -0xf0(%rbp), %rdi
callq 0x6290
movq %rax, -0x100(%rbp)
leaq -0xf8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x1c7c0
testb $0x1, %al
jne 0x2e0ab
jmp 0x2e1fc
leaq -0xf8(%rbp), %rdi
callq 0x1c800
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
movsbl (%rax), %edi
callq 0x6420
cmpl $0x0, %eax
je 0x2e166
imull $0xa, -0xc0(%rbp), %eax
movl %eax, -0xc0(%rbp)
movq -0x108(%rbp), %rax
movsbl (%rax), %eax
subl $0x30, %eax
addl -0xc0(%rbp), %eax
movl %eax, -0xc0(%rbp)
jmp 0x2e1e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x69(%rbp), %rdi
callq 0x64f0
jmp 0x2e597
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x64f0
jmp 0x2e57c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb9(%rbp), %rdi
callq 0x64f0
jmp 0x2e570
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2e564
movq -0x108(%rbp), %rax
movsbl (%rax), %edi
callq 0x6730
cmpl $0x0, %eax
je 0x2e191
movq -0x108(%rbp), %rax
movsbl (%rax), %esi
leaq -0x68(%rbp), %rdi
callq 0x62f0
jmp 0x2e18f
jmp 0x2e1e7
movq -0x108(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x2e1b1
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x2e1e5
movq -0x108(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7e, %eax
jne 0x2e1c9
movb $0x1, -0xc9(%rbp)
jmp 0x2e1e3
movq -0x108(%rbp), %rax
movsbl (%rax), %esi
leaq -0x90(%rbp), %rdi
callq 0x62f0
jmp 0x2e1e1
jmp 0x2e1e3
jmp 0x2e1e5
jmp 0x2e1e7
jmp 0x2e1e9
jmp 0x2e1eb
leaq -0xf8(%rbp), %rdi
callq 0x1c820
jmp 0x2e08f
leaq -0x90(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rdi
callq 0x63f0
movq %rax, -0x118(%rbp)
movq -0x110(%rbp), %rdi
callq 0x6290
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x1c7c0
testb $0x1, %al
jne 0x2e249
jmp 0x2e2ac
leaq -0x118(%rbp), %rdi
callq 0x1c800
movq %rax, -0x128(%rbp)
movq -0x128(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x27, %eax
jne 0x2e27c
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x2e29c
movq -0x128(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x2e29a
movl -0xc8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x2e29c
jmp 0x2e29e
leaq -0x118(%rbp), %rdi
callq 0x1c820
jmp 0x2e230
cmpl $0x0, -0xc0(%rbp)
je 0x2e342
cmpl $0x0, -0xc0(%rbp)
je 0x2e2d6
movl $0x20, %eax
cltd
idivl -0xc0(%rbp)
movl %eax, -0x25c(%rbp)
jmp 0x2e2e2
movl -0xc0(%rbp), %eax
movl %eax, -0x25c(%rbp)
movl -0x25c(%rbp), %eax
movl %eax, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x12c(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0xc4(%rbp)
cmpl $0x0, %eax
je 0x2e340
movl -0x12c(%rbp), %eax
addl -0xc0(%rbp), %eax
movl %eax, -0xc0(%rbp)
movl -0x12c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x12c(%rbp)
jmp 0x2e302
jmp 0x2e351
movq -0x228(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc0(%rbp)
leaq 0x32b49(%rip), %rsi     # 0x60ea1
leaq -0x170(%rbp), %rdi
movl $0x10, %edx
callq 0x2fab0
jmp 0x2e36b
leaq 0x32212(%rip), %rcx     # 0x60584
leaq -0x150(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x170(%rbp), %rdx
xorl %r8d, %r8d
callq 0x2fb80
jmp 0x2e38e
leaq -0x68(%rbp), %rdi
leaq -0x150(%rbp), %rsi
movq %rsi, -0x268(%rbp)
callq 0x6580
movq -0x268(%rbp), %rdi
callq 0x62d0
leaq -0x170(%rbp), %rdi
callq 0x2fb50
leaq 0x32396(%rip), %rsi     # 0x6075a
leaq -0x1b0(%rbp), %rdi
movl $0x10, %edx
callq 0x2fab0
jmp 0x2e3d7
leaq 0x3218c(%rip), %rcx     # 0x6056a
leaq -0x190(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x1b0(%rbp), %rdx
xorl %r8d, %r8d
callq 0x2fb80
jmp 0x2e3fa
leaq -0x68(%rbp), %rdi
leaq -0x190(%rbp), %rsi
movq %rsi, -0x270(%rbp)
callq 0x6580
movq -0x270(%rbp), %rdi
callq 0x62d0
leaq -0x1b0(%rbp), %rdi
callq 0x2fb50
movb $0x0, -0x1b1(%rbp)
leaq -0x1d8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x61f0
jmp 0x2e445
leaq -0x1f8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x61f0
jmp 0x2e457
movq -0x220(%rbp), %rdi
movl -0xc8(%rbp), %ecx
movl -0xc0(%rbp), %r8d
movzbl -0xc9(%rbp), %r9d
andl $0x1, %r9d
leaq -0x1d8(%rbp), %rsi
leaq -0x1f8(%rbp), %rdx
callq 0x22ac0
jmp 0x2e48c
leaq -0x1f8(%rbp), %rdi
callq 0x62d0
leaq -0x1d8(%rbp), %rdi
callq 0x62d0
movq -0x220(%rbp), %rax
cmpl $0x0, -0xc0(%rbp)
setne %cl
andb $0x1, %cl
movb %cl, 0x54(%rax)
movb $0x1, -0x1b1(%rbp)
testb $0x1, -0x1b1(%rbp)
jne 0x2e541
jmp 0x2e535
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x2fb50
jmp 0x2e564
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x2fb50
jmp 0x2e564
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2e527
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1f8(%rbp), %rdi
callq 0x62d0
leaq -0x1d8(%rbp), %rdi
callq 0x62d0
jmp 0x2e564
movq -0x220(%rbp), %rdi
callq 0xfd80
leaq -0xb8(%rbp), %rdi
callq 0x62d0
leaq -0x90(%rbp), %rdi
callq 0x62d0
leaq -0x68(%rbp), %rdi
callq 0x62d0
jmp 0x2e587
leaq -0xb8(%rbp), %rdi
callq 0x62d0
leaq -0x90(%rbp), %rdi
callq 0x62d0
leaq -0x68(%rbp), %rdi
callq 0x62d0
jmp 0x2e597
movq -0x218(%rbp), %rax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x6820