// File: tbonelaforge[P]gradebook/Gradebook.cpp
// Function: Gradebook::addStudent(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Student * Gradebook::addStudent(int newId, string firstName, string lastName) {
    Student * current = head;
    Student * previous = NULL;
    while (current != NULL) {
        if (current->getId() == newId) {
            throw "Student Id " + to_string(newId) + " already exists.";
        }
        if (current->getId() > newId) {
            break;
        }
        previous = current;
        current = current->next;
    }
    Student * newStudent = new Student(numPrograms, numTests, numFinals);
    newStudent->setId(newId);
    newStudent->setFirstName(firstName);
    newStudent->setLastName(lastName);
    if (previous != NULL) {
        previous->next = newStudent;
    } else {
        head = newStudent;
    }
    newStudent->next = current;
    addToIndex(newStudent);
    numStudents += 1;
    return newStudent;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdx, -0xe0(%rbp)
movq %rcx, -0xd8(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq 0x38(%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x62a0
movq -0x28(%rbp), %rdi
callq 0x7540
cmpl -0xc(%rbp), %eax
jne 0x6278
movb $0x1, -0x7d(%rbp)
movl $0x20, %edi
callq 0x3120
movq %rax, -0xe8(%rbp)
movl -0xc(%rbp), %esi
leaq -0x70(%rbp), %rdi
callq 0x6f70
jmp 0x61d3
leaq 0x4873(%rip), %rsi      # 0xaa4d
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x6f20
jmp 0x61e9
movq -0xe8(%rbp), %rdi
leaq 0x4862(%rip), %rdx      # 0xaa59
leaq -0x50(%rbp), %rsi
callq 0x6ed0
jmp 0x6202
movq -0xe8(%rbp), %rdi
movb $0x0, -0x7d(%rbp)
leaq 0x7b6c(%rip), %rsi      # 0xdd80
movq 0x7d95(%rip), %rdx      # 0xdfb0
callq 0x33d0
jmp 0x6445
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x625f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x6256
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3498
leaq -0x70(%rbp), %rdi
callq 0x3498
testb $0x1, -0x7d(%rbp)
jne 0x6267
jmp 0x6273
movq -0xe8(%rbp), %rdi
callq 0x31a0
jmp 0x643c
movq -0x28(%rbp), %rdi
callq 0x7540
cmpl -0xc(%rbp), %eax
jle 0x6288
jmp 0x62a0
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x6193
movl $0x78, %edi
callq 0x3230
movq %rax, %rdi
movq -0xd0(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0xf0(%rbp)
movl (%rax), %esi
movl 0x10(%rax), %edx
movl 0x20(%rax), %ecx
callq 0x72e0
jmp 0x62cd
movq -0xf0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x74c0
movq -0xe0(%rbp), %rsi
movq -0x88(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0xa8(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x30f0
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rsi
callq 0x74e0
jmp 0x6327
leaq -0xa8(%rbp), %rdi
callq 0x3498
movq -0xd8(%rbp), %rsi
movq -0x88(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x30f0
movq -0x110(%rbp), %rdi
movq -0x108(%rbp), %rsi
callq 0x7510
jmp 0x6370
leaq -0xc8(%rbp), %rdi
callq 0x3498
cmpq $0x0, -0x30(%rbp)
je 0x63e9
movq -0x88(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x63fb
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
movl $0x78, %esi
callq 0x3240
jmp 0x643c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3498
jmp 0x643c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3498
jmp 0x643c
movq -0xd0(%rbp), %rax
movq -0x88(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq -0xd0(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq -0x88(%rbp), %rax
movq %rcx, (%rax)
movq -0x88(%rbp), %rsi
callq 0x6450
movq -0xd0(%rbp), %rax
movl 0x48(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x48(%rax)
movq -0x88(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x33f0
nopw %cs:(%rax,%rax)