// File: /workspace/github_cpp_makefile_star2_O3/tbonelaforge[P]gradebook/Main.cpp
// Function: handleChangeGrade(Gradebook&)
void handleChangeGrade(Gradebook &gradebook) {
    int studentId, gradeNumber, newGrade;
    char gradeType;
    Student * student;
    cout << "Enter the student number: " << endl;
    cin >> studentId;
    student = gradebook.findStudentById(studentId);
    if (student == NULL) {
        cout << "Student number " << studentId << " not found\n";
        return;
    }
    if (gradebook.getNumFinals() > 0) {
        cout << "Enter the type of grade: ('P' for program, 'T' for test, 'F' for final exam)" << endl;
    } else {
        cout << "Enter the type of grade: ('P' for program, 'T' for test)" << endl;
    }
    cin >> gradeType;
    gradeType = toupper(gradeType);
    switch (gradeType) {
    case 'P':
        cout << "Enter the program number (1 - " << gradebook.getNumPrograms() << ")\n";
        cin >> gradeNumber;
        if (gradeNumber < 1 || gradeNumber > gradebook.getNumPrograms()) {
            cout << "Invalid program number.\n";
            return;
        }
        break;
    case 'T':
        cout << "Enter the test number (1 - " << gradebook.getNumTests() << ")\n";
        cin >> gradeNumber;
        if (gradeNumber < 1 || gradeNumber > gradebook.getNumTests()) {
            cout << "Invalid test number.\n";
            return;
        }
        break;
    case 'F':
        if (gradebook.getNumFinals() > 0) {
            break;
        }
    default:
        cout << "Unrecognized Grade Type\n";
        return;
    }
    cout << "Enter the new grade: " << endl;
    cin >> newGrade;
	while (newGrade < 0 || newGrade>100) {
		cout << "Error, please enter a value between 0-100: " << endl;
		cin >> newGrade;
	}

    transLog << "Changed student " << student->getId();

    if (gradeType == 'P') {
        cout << "Changing the grade for program " << gradeNumber << " to " << newGrade << endl;
        student->setProgramGrade(gradeNumber - 1, newGrade);
        
        transLog << " program " << gradeNumber << " to " << newGrade << endl;
    } else if (gradeType == 'T') {
        cout << "Changing the grade for test " << gradeNumber << " to " << newGrade << endl;
        student->setTestGrade(gradeNumber - 1, newGrade);
        
        transLog << " test " << gradeNumber << " to " << newGrade << endl;
    } else {
        cout << "Changing the final exam grade to " << newGrade << endl;
        transLog << " Final grade from " << student->getFinalExamGrade() << " to " << newGrade << endl;
        student->setFinalExamGrade(newGrade);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r15
movq 0x93d1(%rip), %r14      # 0xcfc8
leaq 0x57f3(%rip), %rsi      # 0x93f1
movl $0x1a, %edx
movq %r14, %rdi
callq 0x2210
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq 0x93a7(%rip), %rdi      # 0xcfe0
leaq -0x38(%rbp), %rbx
movq %rbx, %rsi
callq 0x2110
movl (%rbx), %esi
movq %r15, %rdi
callq 0x56fa
testq %rax, %rax
je 0x3c78
movq %rax, %rbx
movq %r15, %rdi
callq 0x5326
movq 0x9362(%rip), %rdi      # 0xcfc8
testl %eax, %eax
jle 0x3cb2
leaq 0x57b7(%rip), %rsi      # 0x9428
movl $0x4c, %edx
jmp 0x3cbe
movq 0x9349(%rip), %rbx      # 0xcfc8
leaq 0x5786(%rip), %rsi      # 0x940c
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2210
movl -0x38(%rbp), %esi
movq %rbx, %rdi
callq 0x2300
leaq 0x5777(%rip), %rsi      # 0x941c
movl $0xb, %edx
movq %rax, %rdi
jmp 0x3fdc
leaq 0x57bc(%rip), %rsi      # 0x9475
movl $0x38, %edx
callq 0x2210
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq 0x92ef(%rip), %rdi      # 0xcfe0
leaq -0x31(%rbp), %r12
movq %r12, %rsi
callq 0x2270
movsbl (%r12), %edi
callq 0x2330
movb %al, (%r12)
cmpb $0x46, %al
je 0x3e2b
movsbl %al, %eax
cmpl $0x54, %eax
je 0x3da9
cmpl $0x50, %eax
jne 0x3fc9
movq 0x9299(%rip), %r12      # 0xcfc8
leaq 0x5778(%rip), %rsi      # 0x94ae
movl $0x1e, %edx
movq %r12, %rdi
callq 0x2210
movq %r15, %rdi
callq 0x5314
movq %r12, %rdi
movl %eax, %esi
callq 0x2300
leaq 0x5771(%rip), %rsi      # 0x94cd
movl $0x2, %edx
movq %rax, %rdi
callq 0x2210
movq 0x9270(%rip), %rdi      # 0xcfe0
leaq -0x30(%rbp), %r12
movq %r12, %rsi
callq 0x2110
movl (%r12), %r12d
testl %r12d, %r12d
jle 0x3d96
movq %r15, %rdi
callq 0x5314
cmpl %eax, %r12d
jle 0x3e3b
movq 0x922b(%rip), %rdi      # 0xcfc8
leaq 0x572c(%rip), %rsi      # 0x94d0
jmp 0x3fd7
movq 0x9218(%rip), %r12      # 0xcfc8
leaq 0x5732(%rip), %rsi      # 0x94e9
movl $0x1b, %edx
movq %r12, %rdi
callq 0x2210
movq %r15, %rdi
callq 0x531c
movq %r12, %rdi
movl %eax, %esi
callq 0x2300
leaq 0x56f0(%rip), %rsi      # 0x94cd
movl $0x2, %edx
movq %rax, %rdi
callq 0x2210
movq 0x91ef(%rip), %rdi      # 0xcfe0
leaq -0x30(%rbp), %r12
movq %r12, %rsi
callq 0x2110
movl (%r12), %r12d
testl %r12d, %r12d
jle 0x3e13
movq %r15, %rdi
callq 0x531c
cmpl %eax, %r12d
jle 0x3e3b
movq 0x91ae(%rip), %rdi      # 0xcfc8
leaq 0x56e4(%rip), %rsi      # 0x9505
movl $0x15, %edx
jmp 0x3fdc
movq %r15, %rdi
callq 0x5326
testl %eax, %eax
jle 0x3fc9
leaq 0x56f2(%rip), %rsi      # 0x9534
movl $0x15, %edx
movq %r14, %rdi
callq 0x2210
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq 0x9163(%rip), %rdi      # 0xcfe0
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x2110
cmpl $0x65, (%r15)
jb 0x3ee9
leaq 0x56b4(%rip), %r15      # 0x954a
movq 0x9143(%rip), %r12      # 0xcfe0
leaq -0x2c(%rbp), %r13
movl $0x2b, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2210
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movq %r12, %rdi
movq %r13, %rsi
callq 0x2110
cmpl $0x64, -0x2c(%rbp)
ja 0x3ea1
leaq 0x92f8(%rip), %r14      # 0xd1e8
leaq 0x567f(%rip), %rsi      # 0x9576
movl $0x10, %edx
movq %r14, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x62b6
movq %r14, %rdi
movl %eax, %esi
callq 0x2300
movzbl -0x31(%rbp), %eax
movq 0x90a7(%rip), %r14      # 0xcfc8
cmpl $0x54, %eax
je 0x3ff0
cmpl $0x50, %eax
jne 0x40e1
leaq 0x564d(%rip), %rsi      # 0x9587
movl $0x1f, %edx
movq %r14, %rdi
callq 0x2210
movl -0x30(%rbp), %esi
movq %r14, %rdi
callq 0x2300
movq %rax, %r15
leaq 0x5685(%rip), %r14      # 0x95e1
movl $0x4, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2210
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2300
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movl -0x30(%rbp), %esi
decl %esi
movl -0x2c(%rbp), %edx
movq %rbx, %rdi
callq 0x634a
leaq 0x9230(%rip), %rbx      # 0xd1e8
leaq 0x55de(%rip), %rsi      # 0x959d
movl $0x9, %edx
jmp 0x4081
movq 0x8ff8(%rip), %rdi      # 0xcfc8
leaq 0x5544(%rip), %rsi      # 0x951b
movl $0x18, %edx
callq 0x2210
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x55b0(%rip), %rsi      # 0x95a7
movl $0x1c, %edx
movq %r14, %rdi
callq 0x2210
movl -0x30(%rbp), %esi
movq %r14, %rdi
callq 0x2300
movq %rax, %r15
leaq 0x55c8(%rip), %r14      # 0x95e1
movl $0x4, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2210
movl -0x2c(%rbp), %esi
movq %r15, %rdi
callq 0x2300
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movl -0x30(%rbp), %esi
decl %esi
movl -0x2c(%rbp), %edx
movq %rbx, %rdi
callq 0x636a
leaq 0x9173(%rip), %rbx      # 0xd1e8
leaq 0x5541(%rip), %rsi      # 0x95bd
movl $0x6, %edx
movq %rbx, %rdi
callq 0x2210
movl -0x30(%rbp), %esi
movq %rbx, %rdi
callq 0x2300
movq %rax, %rbx
movl $0x4, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2210
movl -0x2c(%rbp), %esi
movq %rbx, %rdi
callq 0x2300
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
jmp 0x3fe1
leaq 0x54dc(%rip), %rsi      # 0x95c4
movl $0x21, %edx
movq %r14, %rdi
callq 0x2210
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2300
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
leaq 0x90b7(%rip), %r14      # 0xd1e8
leaq 0x54ae(%rip), %rsi      # 0x95e6
movl $0x12, %edx
movq %r14, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x637a
movq %r14, %rdi
movl %eax, %esi
callq 0x2300
movq %rax, %r14
leaq 0x5480(%rip), %rsi      # 0x95e1
movl $0x4, %edx
movq %rax, %rdi
callq 0x2210
movl -0x2c(%rbp), %esi
movq %r14, %rdi
callq 0x2300
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2130
movl -0x2c(%rbp), %esi
movq %rbx, %rdi
callq 0x6384
jmp 0x3fe1