// File: /workspace/github_cpp_makefile_star2_O1/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 $0x108, %rsp            # imm = 0x108
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r14
leaq 0x17303(%rip), %rsi     # 0x3b668
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movl $0x10, %edx
callq 0x26334
movq (%r13), %rdi
movq 0x8(%r13), %rsi
addq %rdi, %rsi
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, (%rdx)
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x316c1
movl %eax, %ebp
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x243b5
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5360
leaq 0x38(%rsp), %rdi
callq 0x2639c
testb %bpl, %bpl
je 0x244d5
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x17322(%rip), %rdx     # 0x3b6fa
leaq 0x10(%rsp), %rdi
movq %rdx, %rsi
callq 0xb62c
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x17305(%rip), %rdx     # 0x3b6fa
leaq 0x38(%rsp), %rdi
movq %rdx, %rsi
callq 0xb62c
movq %r14, 0x58(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x172e0(%rip), %rdx     # 0x3b6fa
leaq 0x80(%rsp), %rdi
movq %rdx, %rsi
callq 0xb62c
movq (%r13), %rax
movsbl (%rax), %esi
leaq 0x80(%rsp), %rdi
callq 0x52e0
xorl %ebx, %ebx
movl $0x1, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x5400
movq 0x8(%r13), %rbp
testq %rbp, %rbp
je 0x244ec
movq %r12, 0xa0(%rsp)
movq (%r13), %r12
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %ebx, %ebx
movq $0x0, 0x30(%rsp)
movsbl (%r12,%r15), %r13d
leal -0x30(%r13), %eax
cmpl $0x9, %eax
ja 0x24491
leal (%r14,%r14,4), %ecx
leal (%rax,%rcx,2), %r14d
jmp 0x244aa
movl %r13d, %edi
callq 0x5550
leaq 0x10(%rsp), %rdi
testl %eax, %eax
je 0x244b4
movl %r13d, %esi
callq 0x52e0
incq %r15
cmpq %r15, %rbp
jne 0x24479
jmp 0x244e2
cmpb $0x7e, %r13b
je 0x244cc
movzbl %r13b, %eax
leaq 0x38(%rsp), %rdi
cmpl $0x2e, %eax
jne 0x244a2
incl %ebx
jmp 0x244aa
movb $0x1, %al
movq %rax, 0x30(%rsp)
jmp 0x244aa
movq %r14, %rdi
callq 0x1aa88
jmp 0x247ab
movq 0xa0(%rsp), %r12
jmp 0x244f8
movq $0x0, 0x30(%rsp)
xorl %r14d, %r14d
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x2452c
movq 0x38(%rsp), %rcx
movl $0x3, %ebp
xorl %edx, %edx
movzbl (%rcx,%rdx), %esi
cmpl $0x2c, %esi
je 0x24520
cmpl $0x27, %esi
jne 0x24522
incl %ebp
jmp 0x24522
decl %ebp
incq %rdx
cmpq %rdx, %rax
jne 0x2450e
jmp 0x24531
movl $0x3, %ebp
testl %r14d, %r14d
je 0x2455b
movl $0x20, %eax
xorl %edx, %edx
idivl %r14d
testl %ebx, %ebx
je 0x24561
movl %eax, %r14d
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
addl %ecx, %r14d
movl %ecx, %eax
decl %ebx
jne 0x24549
jmp 0x24564
movl (%r12), %r14d
jmp 0x24564
movl %eax, %r14d
leaq 0x1785e(%rip), %rsi     # 0x3bdc9
leaq 0xa8(%rsp), %rdi
movl $0x10, %edx
callq 0x26334
leaq 0x70(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
movl $0x0, (%rsp)
leaq 0x16fab(%rip), %r8      # 0x3b55b
leaq 0x60(%rsp), %rdi
leaq 0xa8(%rsp), %rcx
movl $0x1, %r9d
callq 0x33675
leaq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %r15
movq %r15, %rsi
callq 0x5420
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x245ef
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0xa8(%rsp), %rdi
callq 0x2639c
leaq 0x1707f(%rip), %rsi     # 0x3b682
leaq 0xa8(%rsp), %rdi
movl $0x10, %edx
callq 0x26334
leaq 0x60(%rsp), %rdi
movq %r12, (%rdi)
movq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
movl $0x0, (%rsp)
leaq 0x16f05(%rip), %r8      # 0x3b549
leaq 0xa8(%rsp), %rcx
movl $0x3, %r9d
callq 0x33675
leaq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %r15
movq %r15, %rsi
callq 0x5420
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x2467e
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0xa8(%rsp), %rdi
callq 0x2639c
leaq 0xf8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0xb544
leaq 0xd8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0xb544
movzbl 0x30(%rsp), %r9d
andl $0x1, %r9d
leaq 0xe8(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
movq 0x58(%rsp), %rdi
movl %ebp, %ecx
movl %r14d, %r8d
callq 0x1a814
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x24724
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x24741
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x5360
testl %r14d, %r14d
movq 0x58(%rsp), %r14
setne 0x54(%r14)
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x24773
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
leaq 0x20(%rsp), %rbx
je 0x24794
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x247ab
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5360
movq %r14, %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x247e5
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x247e5
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x24876
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x24876
jmp 0x2480c
jmp 0x24873
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0x24826
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0xa8(%rsp), %rdi
callq 0x2639c
jmp 0x24876
jmp 0x24873
jmp 0x24873
movq %rax, %rbx
jmp 0x2489b
movq %rax, %rbx
jmp 0x248b7
movq %rax, %rbx
jmp 0x248d3
jmp 0x24873
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x24867
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5360
leaq 0x38(%rsp), %rdi
callq 0x2639c
jmp 0x248d3
movq %rax, %rbx
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x2489b
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x248b7
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x248d3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5360
movq %rbx, %rdi
callq 0x55e0
nop