// File: /workspace/github_cpp_makefile_star2_O2/tbonelaforge[P]gradebook/Main.cpp
// Function: handleSetup(int&, Gradebook&)
void handleSetup(int &state, Gradebook &gradebook) {
    int numPrograms, numTests, numFinals;
    int programsWeight, testsWeight, finalExamWeight;

    cout << "Enter number of programming assignments (Between 0-6): " << endl;
    cin >> numPrograms;
    while (numPrograms<0||numPrograms>6){
      cout << "Error, incorrect value entered." <<endl<<"Enter number of programming assignments (Between 0-6): " << endl;
      cin >> numPrograms;
    }

    cout << "Enter number of tests (Between 0-4): " << endl;
    cin >> numTests;
    while (numTests<0||numTests>4){
      cout << "Error, incorrect value entered." <<endl<<"Enter number of tests (Between 0-4): " << endl;
      cin >> numTests;
    }

    cout << "Enter number of Final Exams: (0 or 1)" << endl;
    cin >> numFinals;
    while (numFinals<0||numFinals>1){
      cout << "Error, incorrect value entered." <<endl<< "Enter number of Final Exams: (0 or 1)" << endl;
      cin >> numFinals;
    }

    if (numFinals > 0) {
        cout << "Enter the relative percentages for programs, tests, and final exam. example: \n30 50 20" << endl;
        cin >> programsWeight >> testsWeight >> finalExamWeight;
		while ((programsWeight + testsWeight + finalExamWeight) != 100) {
			cout << "Error, must equal 100%" << endl;
			cout << "Enter the relative percentages for programs, tests, and final exam. example: \n30 50 20" << endl;
			cin >> programsWeight >> testsWeight >> finalExamWeight;
		}
    } else {
        cout << "Enter the relative percentages for programs, and tests. example: \n40 60" << endl;
        cin >> programsWeight >> testsWeight;
		while ((programsWeight + testsWeight) != 100) {
			cout << "Error, must equal 100%" << endl;
			cout << "Enter the relative percentages for programs, and tests. example: \n40 60" << endl;
			cin >> programsWeight >> testsWeight;
		}
    }
    gradebook.initialize(
                         numPrograms,
                         numTests,
                         numFinals,
                         programsWeight,
                         testsWeight,
                         finalExamWeight
                         );
    saveGrades(gradebook);
    state = 1;
    
    transLog.close();
    transLog.open("Grades.trn");
    transLog << "Initialized Gradebook:" 
        << " Programs: " << numPrograms
        << " Tests: " << numTests
        << " Finals: " << numFinals << "  | "
        << " Pwt: " << programsWeight
        << " Twt: " << testsWeight
        << " Fwt: " << finalExamWeight << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, -0x48(%rbp)
movq %rdi, -0x50(%rbp)
movq 0x89c1(%rip), %r15      # 0xafc8
leaq 0x4a65(%rip), %rbx      # 0x7073
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq 0x89b8(%rip), %r14      # 0xafe0
leaq -0x3c(%rbp), %r12
leaq 0x4a78(%rip), %r13      # 0x70ab
movq %r14, %rdi
movq %r12, %rsi
callq 0x20e0
cmpl $0x6, -0x3c(%rbp)
jbe 0x266c
movq %r15, %rdi
movq %r13, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
jmp 0x2633
leaq 0x4a58(%rip), %rbx      # 0x70cb
movq 0x8966(%rip), %r14      # 0xafe0
leaq -0x38(%rbp), %r12
leaq 0x4a26(%rip), %r13      # 0x70ab
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq %r14, %rdi
movq %r12, %rsi
callq 0x20e0
cmpl $0x4, -0x38(%rbp)
jbe 0x26c1
movq %r15, %rdi
movq %r13, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
jmp 0x2688
movq 0x8900(%rip), %rbx      # 0xafc8
leaq 0x4a22(%rip), %r14      # 0x70f1
movq 0x890a(%rip), %r15      # 0xafe0
leaq -0x34(%rbp), %r12
leaq 0x49ca(%rip), %r13      # 0x70ab
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq %r15, %rdi
movq %r12, %rsi
callq 0x20e0
movl -0x34(%rbp), %eax
cmpl $0x2, %eax
jb 0x271f
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
jmp 0x26e4
cmpl $0x1, %eax
jne 0x27a9
movq 0x8899(%rip), %r15      # 0xafc8
leaq -0x30(%rbp), %rbx
leaq -0x2c(%rbp), %r14
leaq -0x40(%rbp), %r12
leaq 0x4a2c(%rip), %r13      # 0x716e
movq %r15, %rdi
leaq 0x49cb(%rip), %rsi      # 0x7117
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq 0x8880(%rip), %rdi      # 0xafe0
movq %rbx, %rsi
callq 0x20e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x20e0
movq %rax, %rdi
movq %r12, %rsi
callq 0x20e0
movl -0x30(%rbp), %r8d
movl -0x2c(%rbp), %r9d
leal (%r9,%r8), %ecx
movl -0x40(%rbp), %eax
addl %eax, %ecx
cmpl $0x64, %ecx
je 0x2808
movq %r15, %rdi
movq %r13, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
jmp 0x2742
movq 0x8818(%rip), %rbx      # 0xafc8
movq 0x8829(%rip), %r15      # 0xafe0
leaq -0x30(%rbp), %r12
leaq -0x2c(%rbp), %r13
leaq 0x49a8(%rip), %r14      # 0x716e
movq %rbx, %rdi
leaq 0x49b5(%rip), %rsi      # 0x7185
callq 0x2170
movq %rax, %rdi
callq 0x20b0
movq %r15, %rdi
movq %r12, %rsi
callq 0x20e0
movq %rax, %rdi
movq %r13, %rsi
callq 0x20e0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2170
movq %rax, %rdi
callq 0x20b0
jmp 0x27c6
movl -0x3c(%rbp), %esi
movl -0x38(%rbp), %edx
movl -0x34(%rbp), %ecx
movl %eax, (%rsp)
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
callq 0x4130
movq %rbx, %rdi
callq 0x255c
movq -0x50(%rbp), %rax
movl $0x1, (%rax)
leaq 0x899f(%rip), %rbx      # 0xb1d8
movq %rbx, %rdi
callq 0x2250
leaq 0x480c(%rip), %rsi      # 0x7054
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x2050
leaq 0x4973(%rip), %rsi      # 0x71cd
movq %rbx, %rdi
callq 0x2170
leaq 0x497b(%rip), %rsi      # 0x71e4
movq %rax, %rdi
callq 0x2170
movl -0x3c(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x496d(%rip), %rsi      # 0x71f0
movq %rax, %rdi
callq 0x2170
movl -0x38(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x495c(%rip), %rsi      # 0x71f9
movq %rax, %rdi
callq 0x2170
movl -0x34(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x494c(%rip), %rsi      # 0x7203
movq %rax, %rdi
callq 0x2170
leaq 0x4942(%rip), %rsi      # 0x7208
movq %rax, %rdi
callq 0x2170
movl -0x30(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x492f(%rip), %rsi      # 0x720f
movq %rax, %rdi
callq 0x2170
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x491c(%rip), %rsi      # 0x7216
movq %rax, %rdi
callq 0x2170
movl -0x40(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20b0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq