// File: /workspace/github_cpp_makefile_star2_O1/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 0x2eb1
testq %rax, %rax
je 0x2fb1
leaq -0xe0(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xf0(%rbp), %rdi
callq 0x37d8
leaq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x37d8
leaq -0xf0(%rbp), %rsi
movq %rbx, %rdi
callq 0x28e6
leaq -0xf0(%rbp), %rdi
jmp 0x300a
movq %rsi, %r15
cmpq %rsi, %rax
jae 0x2f05
leaq -0x60(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %rdi
callq 0x37d8
leaq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x37d8
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
callq 0x24dc
leaq -0x70(%rbp), %rdi
jmp 0x300a
leaq -0xa0(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %rdi
callq 0x37d8
leaq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x37d8
leaq -0xb0(%rbp), %rsi
movq %rbx, %rdi
callq 0x2a10
movq %rax, %r12
leaq -0xb0(%rbp), %rdi
callq 0x99c6
testq %r12, %r12
je 0x3021
movq 0xb05c(%rip), %rbx      # 0xdfd0
leaq 0x7089(%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 0x300f
leaq -0x120(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x130(%rbp), %rdi
callq 0x37d8
leaq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x37d8
leaq -0x130(%rbp), %rsi
movq %rbx, %rdi
callq 0x24dc
leaq -0x130(%rbp), %rdi
callq 0x99c6
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 0x99a0
movq %r12, %rcx
leaq 0x20(%r14), %rax
movq %rax, -0x30(%rbp)
movq (%rbx), %r13
testq %r15, %r15
je 0x3060
decq %r15
movq %r13, %rax
movq 0x40(%rax), %r13
movq %rax, %r12
movq %r13, %rax
decq %r15
jne 0x304f
jmp 0x3063
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 0x300f
movq %rax, %rbx
movq %r12, %rdi
jmp 0x3102
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
jmp 0x30ec
movq %rax, %rbx
movq -0x130(%rbp), %rdi
jmp 0x30fd
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x30ec
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0x30ec
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r12, %rdi
jne 0x3102
jmp 0x3107
movq %rax, %rbx
movq -0x70(%rbp), %rdi
jmp 0x30fd
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x99c6
jmp 0x3107
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3107
callq 0x20e0
movq %rbx, %rdi
callq 0x2170
nop