// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movl %esi, %r13d
movq %rdi, %rbx
leaq 0x38(%rdi), %r12
xorl %r14d, %r14d
movq %r12, %rcx
movq %r14, %r15
movq (%rcx), %r14
testq %r14, %r14
je 0x424a
movq %r14, %rdi
callq 0x4d38
cmpl %r13d, %eax
je 0x42f1
movq %r14, %rdi
callq 0x4d38
movq %r14, %rcx
cmpl %r13d, %eax
jle 0x421e
movq %r12, -0x30(%rbp)
pushq $0x78
popq %rdi
callq 0x2180
movq %rax, %r12
movl (%rbx), %esi
movl 0x10(%rbx), %edx
movl 0x20(%rbx), %ecx
movq %rax, %rdi
callq 0x4bf0
movq %r12, %rdi
movl %r13d, %esi
callq 0x4d12
leaq -0x80(%rbp), %r13
movq %r13, %rdi
movq -0x40(%rbp), %rsi
callq 0x2240
movq %r12, %rdi
movq %r13, %rsi
callq 0x4d1c
leaq -0x80(%rbp), %rdi
callq 0x2358
leaq -0x60(%rbp), %r13
movq %r13, %rdi
movq -0x38(%rbp), %rsi
callq 0x2240
movq %r12, %rdi
movq %r13, %rsi
callq 0x4d2a
leaq -0x60(%rbp), %rdi
callq 0x2358
testq %r15, %r15
movq -0x30(%rbp), %rax
cmovneq %r15, %rax
movq %r12, (%rax)
movq %r14, (%r12)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x43bc
incl 0x48(%rbx)
movq %r12, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdi
callq 0x20c0
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
movl %r13d, %esi
callq 0x4ace
leaq 0x373b(%rip), %rsi      # 0x7a4d
leaq -0xc0(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
callq 0x4aa0
movb $0x1, %r15b
leaq 0x372a(%rip), %rdx      # 0x7a59
leaq -0xc0(%rbp), %rsi
movq %rbx, %rdi
callq 0x4a77
xorl %r15d, %r15d
leaq 0x6a40(%rip), %rsi      # 0xad88
movq 0x6c61(%rip), %rdx      # 0xafb0
movq %rbx, %rdi
callq 0x22b0
movq %rax, %r14
leaq -0x60(%rbp), %rdi
jmp 0x4367
movq %rax, %r14
leaq -0x80(%rbp), %rdi
callq 0x2358
jmp 0x43b3
movq %rax, %r14
pushq $0x78
popq %rsi
movq %r12, %rdi
callq 0x2190
jmp 0x43b3
movq %rax, %r14
leaq -0xc0(%rbp), %rdi
callq 0x2358
jmp 0x4395
movq %rax, %r14
movb $0x1, %r15b
leaq -0xa0(%rbp), %rdi
callq 0x2358
testb %r15b, %r15b
jne 0x43ab
jmp 0x43b3
movq %rax, %r14
movq %rbx, %rdi
callq 0x2110
movq %r14, %rdi
callq 0x22d0
nop