// File: /workspace/github_cpp_makefile_star2_O1/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 0x93eb(%rip), %r14      # 0xcfc8
leaq 0x580d(%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 0x93c1(%rip), %rdi      # 0xcfe0
leaq -0x38(%rbp), %rbx
movq %rbx, %rsi
callq 0x2110
movl (%rbx), %esi
movq %r15, %rdi
callq 0x56b8
testq %rax, %rax
je 0x3c5e
movq %rax, %rbx
movq %r15, %rdi
callq 0x530a
movq 0x937c(%rip), %rdi      # 0xcfc8
testl %eax, %eax
jle 0x3c98
leaq 0x57d1(%rip), %rsi      # 0x9428
movl $0x4c, %edx
jmp 0x3ca4
movq 0x9363(%rip), %rbx      # 0xcfc8
leaq 0x57a0(%rip), %rsi      # 0x940c
movl $0xf, %edx
movq %rbx, %rdi
callq 0x2210
movl -0x38(%rbp), %esi
movq %rbx, %rdi
callq 0x2300
leaq 0x5791(%rip), %rsi      # 0x941c
movl $0xb, %edx
movq %rax, %rdi
jmp 0x3fc2
leaq 0x57d6(%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 0x9309(%rip), %rdi      # 0xcfe0
leaq -0x31(%rbp), %r12
movq %r12, %rsi
callq 0x2270
movsbl (%r12), %edi
callq 0x2330
movb %al, (%r12)
cmpb $0x46, %al
je 0x3e11
movsbl %al, %eax
cmpl $0x54, %eax
je 0x3d8f
cmpl $0x50, %eax
jne 0x3faf
movq 0x92b3(%rip), %r12      # 0xcfc8
leaq 0x5792(%rip), %rsi      # 0x94ae
movl $0x1e, %edx
movq %r12, %rdi
callq 0x2210
movq %r15, %rdi
callq 0x52f8
movq %r12, %rdi
movl %eax, %esi
callq 0x2300
leaq 0x578b(%rip), %rsi      # 0x94cd
movl $0x2, %edx
movq %rax, %rdi
callq 0x2210
movq 0x928a(%rip), %rdi      # 0xcfe0
leaq -0x30(%rbp), %r12
movq %r12, %rsi
callq 0x2110
movl (%r12), %r12d
testl %r12d, %r12d
jle 0x3d7c
movq %r15, %rdi
callq 0x52f8
cmpl %eax, %r12d
jle 0x3e21
movq 0x9245(%rip), %rdi      # 0xcfc8
leaq 0x5746(%rip), %rsi      # 0x94d0
jmp 0x3fbd
movq 0x9232(%rip), %r12      # 0xcfc8
leaq 0x574c(%rip), %rsi      # 0x94e9
movl $0x1b, %edx
movq %r12, %rdi
callq 0x2210
movq %r15, %rdi
callq 0x5300
movq %r12, %rdi
movl %eax, %esi
callq 0x2300
leaq 0x570a(%rip), %rsi      # 0x94cd
movl $0x2, %edx
movq %rax, %rdi
callq 0x2210
movq 0x9209(%rip), %rdi      # 0xcfe0
leaq -0x30(%rbp), %r12
movq %r12, %rsi
callq 0x2110
movl (%r12), %r12d
testl %r12d, %r12d
jle 0x3df9
movq %r15, %rdi
callq 0x5300
cmpl %eax, %r12d
jle 0x3e21
movq 0x91c8(%rip), %rdi      # 0xcfc8
leaq 0x56fe(%rip), %rsi      # 0x9505
movl $0x15, %edx
jmp 0x3fc2
movq %r15, %rdi
callq 0x530a
testl %eax, %eax
jle 0x3faf
leaq 0x570c(%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 0x917d(%rip), %rdi      # 0xcfe0
leaq -0x2c(%rbp), %r15
movq %r15, %rsi
callq 0x2110
cmpl $0x65, (%r15)
jb 0x3ecf
leaq 0x56ce(%rip), %r15      # 0x954a
movq 0x915d(%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 0x3e87
leaq 0x9312(%rip), %r14      # 0xd1e8
leaq 0x5699(%rip), %rsi      # 0x9576
movl $0x10, %edx
movq %r14, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x629c
movq %r14, %rdi
movl %eax, %esi
callq 0x2300
movzbl -0x31(%rbp), %eax
movq 0x90c1(%rip), %r14      # 0xcfc8
cmpl $0x54, %eax
je 0x3fd6
cmpl $0x50, %eax
jne 0x40c7
leaq 0x5667(%rip), %rsi      # 0x9587
movl $0x1f, %edx
movq %r14, %rdi
callq 0x2210
movl -0x30(%rbp), %esi
movq %r14, %rdi
callq 0x2300
movq %rax, %r15
leaq 0x569f(%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 0x6330
leaq 0x924a(%rip), %rbx      # 0xd1e8
leaq 0x55f8(%rip), %rsi      # 0x959d
movl $0x9, %edx
jmp 0x4067
movq 0x9012(%rip), %rdi      # 0xcfc8
leaq 0x555e(%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 0x55ca(%rip), %rsi      # 0x95a7
movl $0x1c, %edx
movq %r14, %rdi
callq 0x2210
movl -0x30(%rbp), %esi
movq %r14, %rdi
callq 0x2300
movq %rax, %r15
leaq 0x55e2(%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 0x6350
leaq 0x918d(%rip), %rbx      # 0xd1e8
leaq 0x555b(%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 0x3fc7
leaq 0x54f6(%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 0x90d1(%rip), %r14      # 0xd1e8
leaq 0x54c8(%rip), %rsi      # 0x95e6
movl $0x12, %edx
movq %r14, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x6360
movq %r14, %rdi
movl %eax, %esi
callq 0x2300
movq %rax, %r14
leaq 0x549a(%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 0x636a
jmp 0x3fc7