// File: tbonelaforge[P]gradebook/Student.cpp
// Function: Student::calculateFinalAverage(int, int, int)
void Student::calculateFinalAverage(int programsWeight, int testsWeight, int finalExamWeight) {
    float programAverage, testAverage;
	float d = 100;
    float programTotal = 0.0, testTotal = 0.0;
    
    for (int i = 0; i < numPrograms; i++) {
        if (programGrades[i] > -1) programTotal += (float) programGrades[i];
    }
    programAverage = programTotal / (float) numPrograms;
    for (int i = 0; i < numTests; i++) {
        if (testGrades[i] > -1) testTotal += (float) testGrades[i];
    }
    testAverage = testTotal / (float) numTests;
    
    //adjusted to prevent "nan" final grade
    float finalTotal;
    if (programsWeight > 0 && numPrograms > 0) finalTotal += programAverage / d * programsWeight;
    if (testsWeight > 0 && numTests > 0) finalTotal += testAverage / d * testsWeight;
    if (numFinals > 0) {
        if (finalExamGrade > -1) finalTotal += finalExamGrade / d * finalExamWeight;
    }
    if (!(finalTotal > -0.1)) finalTotal = 0.0;
    setFinalAverage(finalTotal);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movss 0x328b(%rip), %xmm0     # 0xab50
movss %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x24(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x50(%rcx), %eax
jge 0x7927
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x2c(%rbp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
jle 0x791a
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x2c(%rbp), %rcx
cvtsi2ssl (%rax,%rcx,4), %xmm0
addss -0x24(%rbp), %xmm0
movss %xmm0, -0x24(%rbp)
jmp 0x791c
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x78e1
movq -0x40(%rbp), %rax
movss -0x24(%rbp), %xmm0
cvtsi2ssl 0x50(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x18(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x40(%rbp), %rcx
movl -0x30(%rbp), %eax
cmpl 0x54(%rcx), %eax
jge 0x798b
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x30(%rbp), %rcx
cmpl $-0x1, (%rax,%rcx,4)
jle 0x797e
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x30(%rbp), %rcx
cvtsi2ssl (%rax,%rcx,4), %xmm0
addss -0x28(%rbp), %xmm0
movss %xmm0, -0x28(%rbp)
jmp 0x7980
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x7945
movq -0x40(%rbp), %rax
movss -0x28(%rbp), %xmm0
cvtsi2ssl 0x54(%rax), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x1c(%rbp)
cmpl $0x0, -0xc(%rbp)
jle 0x79d3
movq -0x40(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jle 0x79d3
movss -0x18(%rbp), %xmm0
divss -0x20(%rbp), %xmm0
cvtsi2ssl -0xc(%rbp), %xmm2
movss -0x34(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
cmpl $0x0, -0x10(%rbp)
jle 0x7a04
movq -0x40(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jle 0x7a04
movss -0x1c(%rbp), %xmm0
divss -0x20(%rbp), %xmm0
cvtsi2ssl -0x10(%rbp), %xmm2
movss -0x34(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x40(%rbp), %rax
cmpl $0x0, 0x58(%rax)
jle 0x7a3f
movq -0x40(%rbp), %rax
cmpl $-0x1, 0x70(%rax)
jle 0x7a3d
movq -0x40(%rbp), %rax
cvtsi2ssl 0x70(%rax), %xmm0
divss -0x20(%rbp), %xmm0
cvtsi2ssl -0x14(%rbp), %xmm2
movss -0x34(%rbp), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, -0x34(%rbp)
jmp 0x7a3f
movss -0x34(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x3108(%rip), %xmm1     # 0xab58
ucomisd %xmm1, %xmm0
ja 0x7a5e
xorps %xmm0, %xmm0
movss %xmm0, -0x34(%rbp)
movq -0x40(%rbp), %rdi
movss -0x34(%rbp), %xmm0
callq 0x7720
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)