// File: joao18araujo[P]pierluigi/src/song_reader.cpp
// Function: SongReader::song_clef_to_string[abi:cxx11](Song&)
string SongReader::song_clef_to_string(Song & song) {
  int total_midi = 0, total_notes = 0;
  for(auto note : song.notes) {
    if(not note.rest()) {
      total_midi += note.midi_number;
      total_notes++;
    }
  }

  Note treble("b", "", 4);
  Note bass("d", "", 3);

  double mid = total_notes ? (1.0 * total_midi) / total_notes : 0;
  string clef;
  if(treble.midi_number - mid <= mid - bass.midi_number)
    clef = "treble";
  else
    clef = "bass";

  return "\\clef " + clef;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %rdi, -0x220(%rbp)
movq %rdi, %rax
movq %rax, -0x218(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x126e0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0x12550
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1cc60
testb $0x1, %al
jne 0x2f02a
jmp 0x2f0ba
leaq -0x28(%rbp), %rdi
callq 0x1b840
movq %rax, %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x22ce0
movq -0x230(%rbp), %rdi
callq 0x23be0
movb %al, -0x221(%rbp)
jmp 0x2f05d
movb -0x221(%rbp), %al
testb $0x1, %al
jne 0x2f0a0
jmp 0x2f069
movl -0x3c(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x2f0a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xfd80
jmp 0x2f43c
leaq -0x88(%rbp), %rdi
callq 0xfd80
leaq -0x28(%rbp), %rdi
callq 0x1cca0
jmp 0x2f014
leaq -0x111(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x6830
movq -0x238(%rbp), %rdx
leaq 0x31cfd(%rip), %rsi     # 0x60dd8
leaq -0x110(%rbp), %rdi
callq 0xfb20
jmp 0x2f0e9
leaq -0x139(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x6830
movq -0x240(%rbp), %rdx
leaq 0x316c8(%rip), %rsi     # 0x607d2
leaq -0x138(%rbp), %rdi
callq 0xfb20
jmp 0x2f118
leaq -0xf0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0x138(%rbp), %rdx
movl $0x4, %ecx
xorl %r9d, %r9d
movl %r9d, %r8d
callq 0x22ac0
jmp 0x2f13f
leaq -0x138(%rbp), %rdi
callq 0x62d0
leaq -0x139(%rbp), %rdi
callq 0x64f0
leaq -0x110(%rbp), %rdi
callq 0x62d0
leaq -0x111(%rbp), %rdi
callq 0x64f0
leaq -0x1b9(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0x6830
movq -0x248(%rbp), %rdx
leaq 0x31c52(%rip), %rsi     # 0x60de2
leaq -0x1b8(%rbp), %rdi
callq 0xfb20
jmp 0x2f19e
leaq -0x1e1(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x6830
movq -0x250(%rbp), %rdx
leaq 0x31613(%rip), %rsi     # 0x607d2
leaq -0x1e0(%rbp), %rdi
callq 0xfb20
jmp 0x2f1cd
leaq -0x198(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
leaq -0x1e0(%rbp), %rdx
movl $0x3, %ecx
xorl %r9d, %r9d
movl %r9d, %r8d
callq 0x22ac0
jmp 0x2f1f4
leaq -0x1e0(%rbp), %rdi
callq 0x62d0
leaq -0x1e1(%rbp), %rdi
callq 0x64f0
leaq -0x1b8(%rbp), %rdi
callq 0x62d0
leaq -0x1b9(%rbp), %rdi
callq 0x64f0
cmpl $0x0, -0x18(%rbp)
je 0x2f24e
cvtsi2sdl -0x14(%rbp), %xmm1
movsd 0x31381(%rip), %xmm0    # 0x605b8
mulsd %xmm1, %xmm0
cvtsi2sdl -0x18(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x258(%rbp)
jmp 0x2f25b
xorps %xmm0, %xmm0
movsd %xmm0, -0x258(%rbp)
jmp 0x2f25b
movsd -0x258(%rbp), %xmm0
movsd %xmm0, -0x1f0(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x6650
cvtsi2sdl -0xa4(%rbp), %xmm1
subsd -0x1f0(%rbp), %xmm1
movsd -0x1f0(%rbp), %xmm0
cvtsi2sdl -0x14c(%rbp), %xmm2
subsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jb 0x2f3c9
leaq 0x314fa(%rip), %rsi     # 0x607a6
leaq -0x210(%rbp), %rdi
callq 0x6640
jmp 0x2f2ba
jmp 0x2f3e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2f31d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2f305
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x62d0
leaq -0x139(%rbp), %rdi
callq 0x64f0
leaq -0x110(%rbp), %rdi
callq 0x62d0
leaq -0x111(%rbp), %rdi
callq 0x64f0
jmp 0x2f43c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2f38c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x2f374
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x62d0
leaq -0x1e1(%rbp), %rdi
callq 0x64f0
leaq -0x1b8(%rbp), %rdi
callq 0x62d0
leaq -0x1b9(%rbp), %rdi
callq 0x64f0
jmp 0x2f430
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x62d0
leaq -0x198(%rbp), %rdi
callq 0xfd80
jmp 0x2f430
leaq 0x313dd(%rip), %rsi     # 0x607ad
leaq -0x210(%rbp), %rdi
callq 0x6640
jmp 0x2f3de
jmp 0x2f3e0
movq -0x220(%rbp), %rdi
leaq 0x313c4(%rip), %rsi     # 0x607b2
leaq -0x210(%rbp), %rdx
callq 0x20e30
jmp 0x2f3fc
leaq -0x210(%rbp), %rdi
callq 0x62d0
leaq -0x198(%rbp), %rdi
callq 0xfd80
leaq -0xf0(%rbp), %rdi
callq 0xfd80
movq -0x218(%rbp), %rax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
leaq -0xf0(%rbp), %rdi
callq 0xfd80
movq -0x90(%rbp), %rdi
callq 0x6820
nopl (%rax,%rax)