// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x1190b(%rip), %rsi     # 0x296b8
leaq 0x8(%rsp), %r15
pushq $0x10
popq %rdx
movq %r15, %rdi
callq 0x18db8
movq %r13, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x18da0
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x18e1e
testb %bpl, %bpl
je 0x17ec0
leaq 0x11964(%rip), %rsi     # 0x2974a
leaq 0x8(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq 0x96e6
leaq 0x1194e(%rip), %rsi     # 0x2974a
leaq 0x58(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x96e6
leaq 0x11938(%rip), %rsi     # 0x2974a
leaq 0x78(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x96e6
movq (%r13), %rax
movsbl (%rax), %esi
leaq 0x78(%rsp), %rdi
callq 0x52f0
movq %r14, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
movq (%r13), %rsi
movq %r13, %rdi
callq 0x5410
movq (%r13), %rbp
movq 0x8(%r13), %r12
xorl %r15d, %r15d
movq $0x0, (%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpq %r15, %r12
je 0x17ecd
movsbl (%rbp,%r15), %r13d
leal -0x30(%r13), %eax
cmpl $0x9, %eax
ja 0x17e82
imull $0xa, %r14d, %ecx
addl %ecx, %eax
movl %eax, %r14d
jmp 0x17e9b
movl %r13d, %edi
callq 0x5540
leaq 0x8(%rsp), %rdi
testl %eax, %eax
je 0x17ea0
movl %r13d, %esi
callq 0x52f0
incq %r15
jmp 0x17e63
cmpb $0x7e, %r13b
je 0x17eb8
movzbl %r13b, %eax
leaq 0x58(%rsp), %rdi
cmpl $0x2e, %eax
jne 0x17e93
incl %ebx
jmp 0x17e9b
movb $0x1, %al
movq %rax, (%rsp)
jmp 0x17e9b
movq %rbx, %rdi
callq 0x12712
jmp 0x18068
movq 0x58(%rsp), %rax
movq 0x60(%rsp), %rcx
pushq $0x3
popq %rbp
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x17efa
movzbl (%rax,%rdx), %esi
cmpl $0x2c, %esi
je 0x17ef3
cmpl $0x27, %esi
jne 0x17ef5
incl %ebp
jmp 0x17ef5
decl %ebp
incq %rdx
jmp 0x17edc
testl %r14d, %r14d
je 0x17f1a
pushq $0x20
popq %rax
xorl %edx, %edx
idivl %r14d
movl %eax, %r14d
pushq $0x2
popq %rcx
subl $0x1, %ebx
jb 0x17f22
cltd
idivl %ecx
addl %eax, %r14d
jmp 0x17f0d
movq 0x28(%rsp), %rax
movl (%rax), %r14d
leaq 0x11ef0(%rip), %rsi     # 0x29e19
leaq 0x38(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x18db8
movq 0x30(%rsp), %rbx
leaq 0x11662(%rip), %rcx     # 0x295a4
leaq 0x98(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
xorl %r8d, %r8d
callq 0x18e38
leaq 0x8(%rsp), %rdi
leaq 0x98(%rsp), %r15
movq %r15, %rsi
callq 0x5400
movq %r15, %rdi
callq 0x51b0
leaq 0x38(%rsp), %rdi
callq 0x18e1e
leaq 0x11748(%rip), %rsi     # 0x296d2
leaq 0x38(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x18db8
leaq 0x115ec(%rip), %rcx     # 0x2958a
leaq 0x98(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
xorl %r8d, %r8d
callq 0x18e38
leaq 0x8(%rsp), %rdi
leaq 0x98(%rsp), %r15
movq %r15, %rsi
callq 0x5400
movq %r15, %rdi
callq 0x51b0
leaq 0x38(%rsp), %rdi
callq 0x18e1e
leaq 0xd8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x5480
leaq 0xb8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x5480
movzbl (%rsp), %r9d
andl $0x1, %r9d
leaq 0xd8(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
movq %rbx, %rdi
movl %ebp, %ecx
movl %r14d, %r8d
callq 0x12538
leaq 0xb8(%rsp), %rdi
callq 0x51b0
leaq 0xd8(%rsp), %rdi
callq 0x51b0
testl %r14d, %r14d
setne 0x54(%rbx)
leaq 0x78(%rsp), %rdi
callq 0x51b0
leaq 0x58(%rsp), %rdi
callq 0x51b0
leaq 0x8(%rsp), %rdi
callq 0x51b0
movq %rbx, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x51b0
jmp 0x18092
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x51b0
jmp 0x180db
jmp 0x180a5
jmp 0x180d8
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x18e1e
jmp 0x180db
jmp 0x180d8
jmp 0x180d8
movq %rax, %rbx
jmp 0x180e5
movq %rax, %rbx
jmp 0x180ef
movq %rax, %rbx
jmp 0x180f9
jmp 0x180d8
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x18e1e
jmp 0x180f9
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x51b0
leaq 0x58(%rsp), %rdi
callq 0x51b0
leaq 0x8(%rsp), %rdi
callq 0x51b0
movq %rbx, %rdi
callq 0x55d0
nop