// File: /workspace/github_cpp_makefile_star2_O3/lorenatoscano[P]musify/src/linkedList.cpp
// Function: LinkedList::insertPosition(unsigned long, Song)
void LinkedList::insertPosition(size_t pos, Song value) {
  node* pre = nullptr;
  node* cur = nullptr;

  if (pos == 1) {
    if (size == 0) {
      insertEnd(value);
    } else {
      insertStart(value);
    } 
  } else if (pos <= size) {
    // Evita a adição de músicas repetidas
    if (search(value) != nullptr) {
      cout << "A música já existe no sistema." << endl;
    } else {

      node* temp = new node;
      
      cur = head;
    
      for (size_t i = 1; i < pos; ++i) {
        pre = cur;
        cur = cur->next;
      }

      temp->data = value;
      pre->next = temp;
      temp->next = cur;

      ++size;
    }
  } else {
    insertEnd(value);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, %r14
movq %rdi, %rbx
movq 0x10(%rdi), %rax
cmpq $0x1, %rsi
jne 0x2e8b
testq %rax, %rax
je 0x2f8b
leaq -0xe0(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xf0(%rbp), %rdi
callq 0x377e
leaq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x377e
leaq -0xf0(%rbp), %rsi
movq %rbx, %rdi
callq 0x28e0
leaq -0xf0(%rbp), %rdi
jmp 0x2fe4
movq %rsi, %r15
cmpq %rsi, %rax
jae 0x2edf
leaq -0x60(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %rdi
callq 0x377e
leaq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x377e
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
callq 0x24dc
leaq -0x70(%rbp), %rdi
jmp 0x2fe4
leaq -0xa0(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x377e
leaq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x377e
leaq -0xb0(%rbp), %rsi
movq %rbx, %rdi
callq 0x2a0a
movq %rax, %r12
leaq -0xb0(%rbp), %rdi
callq 0x9986
testq %r12, %r12
je 0x2ffb
movq 0xb082(%rip), %rbx      # 0xdfd0
leaq 0x70af(%rip), %rsi      # 0xa004
movl $0x20, %edx
movq %rbx, %rdi
callq 0x2120
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2080
jmp 0x2fe9
leaq -0x120(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x130(%rbp), %rdi
callq 0x377e
leaq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x377e
leaq -0x130(%rbp), %rsi
movq %rbx, %rdi
callq 0x24dc
leaq -0x130(%rbp), %rdi
callq 0x9986
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x48, %edi
callq 0x2100
movq %rax, %r12
movq %rax, %rdi
callq 0x9960
movq %r12, %rcx
leaq 0x20(%r14), %rax
movq %rax, -0x30(%rbp)
movq (%rbx), %r13
testq %r15, %r15
je 0x303a
decq %r15
movq %r13, %rax
movq 0x40(%rax), %r13
movq %rax, %r12
movq %r13, %rax
decq %r15
jne 0x3029
jmp 0x303d
xorl %r12d, %r12d
movq %rcx, %r15
movq %rcx, %rdi
movq %r14, %rsi
callq 0x2040
movq %r15, %rdi
addq $0x20, %rdi
movq -0x30(%rbp), %rsi
callq 0x2040
movq %r15, 0x40(%r12)
movq %r13, 0x40(%r15)
incq 0x10(%rbx)
jmp 0x2fe9
movq %rax, %rbx
movq %r12, %rdi
jmp 0x30dc
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
jmp 0x30c6
movq %rax, %rbx
movq -0x130(%rbp), %rdi
jmp 0x30d7
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x30c6
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0x30c6
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
jne 0x30dc
jmp 0x30e1
movq %rax, %rbx
movq -0x70(%rbp), %rdi
jmp 0x30d7
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x9986
jmp 0x30e1
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
cmpq %r15, %rdi
je 0x30e1
callq 0x20e0
movq %rbx, %rdi
callq 0x2170
nop