// File: /workspace/github_cpp_makefile_star2_O3/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 0x172db(%rip), %rsi     # 0x3b668
leaq 0x38(%rsp), %r15
movq %r15, %rdi
movl $0x10, %edx
callq 0x26350
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 0x316eb
movl %eax, %ebp
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x243dd
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5360
leaq 0x38(%rsp), %rdi
callq 0x263b8
testb %bpl, %bpl
je 0x244f6
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x172fa(%rip), %rdx     # 0x3b6fa
leaq 0x10(%rsp), %rdi
movq %rdx, %rsi
callq 0xb5f8
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x172dd(%rip), %rdx     # 0x3b6fa
leaq 0x38(%rsp), %rdi
movq %rdx, %rsi
callq 0xb5f8
movq %r14, 0x60(%rsp)
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x172b8(%rip), %rdx     # 0x3b6fa
leaq 0x88(%rsp), %rdi
movq %rdx, %rsi
callq 0xb5f8
movq (%r13), %rax
movsbl (%rax), %esi
leaq 0x88(%rsp), %rdi
callq 0x52e0
xorl %ebx, %ebx
movl $0x1, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x5400
movq %r12, 0x58(%rsp)
movq 0x8(%r13), %rbp
testq %rbp, %rbp
je 0x24503
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 0x244b2
leal (%r14,%r14,4), %ecx
leal (%rax,%rcx,2), %r14d
jmp 0x244cb
movl %r13d, %edi
callq 0x5550
leaq 0x10(%rsp), %rdi
testl %eax, %eax
je 0x244d5
movl %r13d, %esi
callq 0x52e0
incq %r15
cmpq %r15, %rbp
jne 0x2449a
jmp 0x2450f
cmpb $0x7e, %r13b
je 0x244ed
movzbl %r13b, %eax
leaq 0x38(%rsp), %rdi
cmpl $0x2e, %eax
jne 0x244c3
incl %ebx
jmp 0x244cb
movb $0x1, %al
movq %rax, 0x30(%rsp)
jmp 0x244cb
movq %r14, %rdi
callq 0x1aada
jmp 0x247cb
movq $0x0, 0x30(%rsp)
xorl %r14d, %r14d
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x24548
movq 0x38(%rsp), %rcx
movl $0x3, %ebp
xorl %edx, %edx
movq 0x58(%rsp), %rdi
movzbl (%rcx,%rdx), %esi
cmpl $0x2c, %esi
je 0x2453c
cmpl $0x27, %esi
jne 0x2453e
incl %ebp
jmp 0x2453e
decl %ebp
incq %rdx
cmpq %rdx, %rax
jne 0x2452a
jmp 0x24552
movl $0x3, %ebp
movq 0x58(%rsp), %rdi
testl %r14d, %r14d
je 0x2457c
movl $0x20, %eax
xorl %edx, %edx
idivl %r14d
testl %ebx, %ebx
je 0x24581
movl %eax, %r14d
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
addl %ecx, %r14d
movl %ecx, %eax
decl %ebx
jne 0x2456a
jmp 0x24584
movl (%rdi), %r14d
jmp 0x24584
movl %eax, %r14d
leaq 0x1783e(%rip), %rsi     # 0x3bdc9
leaq 0xa8(%rsp), %rdi
movl $0x10, %edx
callq 0x26350
leaq 0x78(%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 0x16f8b(%rip), %r8      # 0x3b55b
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %rcx
movl $0x1, %r9d
callq 0x336af
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %r15
movq %r15, %rsi
callq 0x5420
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x2460f
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0xa8(%rsp), %rdi
callq 0x263b8
leaq 0x1705f(%rip), %rsi     # 0x3b682
leaq 0xa8(%rsp), %rdi
movl $0x10, %edx
callq 0x26350
leaq 0x68(%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 0x16ee5(%rip), %r8      # 0x3b549
leaq 0xa8(%rsp), %rcx
movl $0x3, %r9d
callq 0x336af
leaq 0x10(%rsp), %rdi
leaq 0x68(%rsp), %r15
movq %r15, %rsi
callq 0x5420
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x2469e
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0xa8(%rsp), %rdi
callq 0x263b8
leaq 0xf8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0xb50a
leaq 0xd8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0xb50a
movzbl 0x30(%rsp), %r9d
andl $0x1, %r9d
leaq 0xe8(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
movq 0x60(%rsp), %rdi
movl %ebp, %ecx
movl %r14d, %r8d
callq 0x1a870
movq 0xc8(%rsp), %rdi
cmpq %r12, %rdi
je 0x24744
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x24761
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x5360
testl %r14d, %r14d
movq 0x60(%rsp), %r14
setne 0x54(%r14)
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x24793
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
leaq 0x20(%rsp), %rbx
je 0x247b4
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0x247cb
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 0x24805
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x24805
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x24896
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x5360
jmp 0x24896
jmp 0x2482c
jmp 0x24893
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r12, %rdi
je 0x24846
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x5360
leaq 0xa8(%rsp), %rdi
callq 0x263b8
jmp 0x24896
jmp 0x24893
jmp 0x24893
movq %rax, %rbx
jmp 0x248bb
movq %rax, %rbx
jmp 0x248d7
movq %rax, %rbx
jmp 0x248f3
jmp 0x24893
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x24887
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5360
leaq 0x38(%rsp), %rdi
callq 0x263b8
jmp 0x248f3
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x248bb
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x248d7
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x5360
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x248f3
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5360
movq %rbx, %rdi
callq 0x55e0
nop