// File: /workspace/github_cpp_makefile_star2_O2/akshithasriraman[P]Accelerometer/accelerometer.cc
// Function: main
int main (int argc, char** argv) {
    if (argc != 2) {
        std::cout << "Format: <./binary> <input file name e.g., validation/aesni.txt>\n";
        exit(0);
    }

    // First read user input to get file containing model parameters.
    std::string parameters_file_name = argv[1];
    std::ifstream parameters_file(parameters_file_name);
    if (!parameters_file.good()) {
        std::cout << "Invalid file: file does not exist\n";
        exit(0);
    }


    // Read file to populate model parameter values.
    std::string line = "";
    int dimension = 0, curr_dimension = 0;

    // Process each file line.
    for(int i = 0; std::getline(parameters_file, line); i++)
    {
        std::istringstream buf(line);
        std::istream_iterator<std::string> begin(buf), end;
        std::vector<std::string> tokens(begin, end);
        // We only need model parameter and its value, error out otherwise.
        if (tokens.size() != 2) {
            std::cout << "input file has the wrong format\n";
            exit(0);
        }

        // Populate model values from the file to global vars.
        switch (i)
        {
        case 0:
            C = atol(tokens[1].c_str());
            break;
        case 1:
            alpha = atof(tokens[1].c_str());
            break;
        case 2:
            n = atol(tokens[1].c_str());
            break;
        case 3:
            o_0 = atol(tokens[1].c_str());
            break;
        case 4:
            Q = atol(tokens[1].c_str());
            break;
        case 5:
            L = atol(tokens[1].c_str());
            break;
        case 6:
            o_1 = atol(tokens[1].c_str());
            break;
        case 7:
            A = atof(tokens[1].c_str());
            break;
        case 8:
            threading = tokens[1];
            break;
        default:
            std::cout << "File can have only 8 lines containing model values\n";
            exit(0);
        } 
    }
    // std::cout << C << " " << alpha << " " << n << " " << o_0 << " " << Q << " " << L << " " << o_1 << " " << A << " " << std::endl;

        // Compute speedup based on the threading model.
        if (threading == "Sync") {
            Sync();
        } else if (threading == "Sync-OS") {
            SyncOS();
        } else if (threading == "Async") {
            Async();
        } else {
            std::cout << "Invalid threading option\n";
            exit(0);
        }


        std::cout << "Estimated speedup in % = " << (speedup - 1.0) * 100.0 << "%\n\n" << std::endl;


        
    return 0;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4a8, %rsp            # imm = 0x4A8
cmpl $0x2, %edi
jne 0x283c
movq 0x8(%rsi), %rsi
leaq 0x70(%rsp), %rbx
leaq 0x120(%rsp), %rdx
movq %rbx, %rdi
callq 0x291e
leaq 0x120(%rsp), %rdi
pushq $0x8
popq %rdx
movq %rbx, %rsi
callq 0x21e0
movq 0x120(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x140(%rsp,%rax)
jne 0x2851
leaq 0xbfc(%rip), %rsi       # 0x313f
leaq 0x50(%rsp), %rdi
leaq 0x328(%rsp), %rdx
callq 0x291e
leaq 0x328(%rsp), %rbx
leaq 0xc0(%rsp), %r14
leaq 0x38(%rsp), %r13
leaq 0xaa7(%rip), %r15       # 0x3018
xorl %ebp, %ebp
leaq 0x120(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x2030
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2732
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
pushq $0x8
popq %rdx
callq 0x2200
leaq 0xf0(%rsp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x295a
andq $0x0, 0x8(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
xorl %eax, %eax
movb %al, 0x20(%rsp)
movb %al, 0x30(%rsp)
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
callq 0x299a
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x299a
movq %r13, %rdi
leaq 0x90(%rsp), %rsi
movq %r14, %rdx
leaq 0x7(%rsp), %rcx
callq 0x29c6
leaq 0xc8(%rsp), %rdi
callq 0x2238
leaq 0x98(%rsp), %rdi
callq 0x2238
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x280d
cmpl $0x8, %ebp
ja 0x2827
movl %ebp, %eax
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movq 0x20(%rsi), %rdi
callq 0x2150
movq %rax, 0x2adc(%rip)      # 0x5140
jmp 0x2704
movq 0x20(%rsi), %rdi
callq 0x2150
movq %rax, 0x2adf(%rip)      # 0x5158
jmp 0x2704
movq 0x20(%rsi), %rdi
callq 0x2150
movq %rax, 0x2aba(%rip)      # 0x5148
jmp 0x2704
movq 0x20(%rsi), %rdi
callq 0x2150
movq %rax, 0x2ab0(%rip)      # 0x5150
jmp 0x2704
movq 0x20(%rsi), %rdi
callq 0x2170
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x2ac1(%rip)     # 0x5178
jmp 0x2704
movq 0x20(%rsi), %rdi
callq 0x2170
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x2aa2(%rip)     # 0x5170
jmp 0x2704
movq 0x20(%rsi), %rdi
callq 0x2150
movq %rax, 0x2a80(%rip)      # 0x5160
jmp 0x2704
movq 0x20(%rsi), %rdi
callq 0x2150
movq %rax, 0x2a76(%rip)      # 0x5168
jmp 0x2704
addq $0x20, %rsi
leaq 0x2a81(%rip), %rdi      # 0x5180
callq 0x20d0
movq %r13, %rdi
callq 0x2a54
leaq 0x10(%rsp), %rdi
callq 0x2238
leaq 0xf8(%rsp), %rdi
callq 0x2238
movq %rbx, %rdi
callq 0x20a0
incl %ebp
jmp 0x2573
leaq 0x2a47(%rip), %rdi      # 0x5180
leaq 0x9b5(%rip), %rsi       # 0x30f5
callq 0x2a75
testb %al, %al
je 0x2750
callq 0x239c
jmp 0x278e
leaq 0x2a29(%rip), %rdi      # 0x5180
leaq 0x99c(%rip), %rsi       # 0x30fa
callq 0x2a75
testb %al, %al
je 0x276e
callq 0x240d
jmp 0x278e
leaq 0x2a0b(%rip), %rdi      # 0x5180
leaq 0x986(%rip), %rsi       # 0x3102
callq 0x2a75
testb %al, %al
je 0x2866
callq 0x247b
movq 0x2843(%rip), %rdi      # 0x4fd8
leaq 0x986(%rip), %rsi       # 0x3122
callq 0x2120
cvtss2sd 0x29cb(%rip), %xmm0     # 0x5174
addsd 0x857(%rip), %xmm0      # 0x3008
mulsd 0x857(%rip), %xmm0      # 0x3010
movq %rax, %rdi
callq 0x21d0
leaq 0x974(%rip), %rsi       # 0x313c
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20b0
leaq 0x50(%rsp), %rdi
callq 0x2238
leaq 0x120(%rsp), %rdi
callq 0x2040
leaq 0x70(%rsp), %rdi
callq 0x2238
xorl %eax, %eax
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x27c4(%rip), %rdi      # 0x4fd8
leaq 0x885(%rip), %rsi       # 0x30a0
callq 0x2120
xorl %edi, %edi
callq 0x2160
movq 0x27aa(%rip), %rdi      # 0x4fd8
leaq 0x88c(%rip), %rsi       # 0x30c1
callq 0x2120
jmp 0x2820
movq 0x2795(%rip), %rdi      # 0x4fd8
leaq 0x7f2(%rip), %rsi       # 0x303c
callq 0x2120
jmp 0x2820
movq 0x2780(%rip), %rdi      # 0x4fd8
leaq 0x81e(%rip), %rsi       # 0x307d
callq 0x2120
jmp 0x2820
movq 0x276b(%rip), %rdi      # 0x4fd8
leaq 0x894(%rip), %rsi       # 0x3108
callq 0x2120
jmp 0x2820
jmp 0x287d
movq %rax, %rbx
jmp 0x28fe
movq %rax, %rbx
jmp 0x290b
jmp 0x288e
jmp 0x28f1
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2a54
jmp 0x28c9
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x2238
jmp 0x28bc
movq %rax, %rbx
jmp 0x28e0
movq %rax, %rbx
jmp 0x28c9
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x2238
leaq 0x10(%rsp), %rdi
callq 0x2238
leaq 0xf8(%rsp), %rdi
callq 0x2238
leaq 0x328(%rsp), %rdi
callq 0x20a0
jmp 0x28f4
jmp 0x28f1
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x2238
leaq 0x120(%rsp), %rdi
callq 0x2040
leaq 0x70(%rsp), %rdi
callq 0x2238
movq %rbx, %rdi
callq 0x2210
nop