// File: /workspace/github_cpp_makefile_star2_O3/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 0x2a3c
movq 0x8(%rsi), %rsi
leaq 0x100(%rsp), %rbx
leaq 0x120(%rsp), %rdx
movq %rbx, %rdi
callq 0x2bac
leaq 0x120(%rsp), %rdi
movq %rbx, %rsi
movl $0x8, %edx
callq 0x21f0
movq 0x120(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x140(%rsp,%rax)
jne 0x2a51
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1ba6(%rip), %rdx      # 0x413f
leaq 0x38(%rsp), %rdi
movq %rdx, %rsi
callq 0x2dc2
xorl %ebx, %ebx
leaq 0x38(%rsp), %r13
leaq 0x328(%rsp), %rbp
leaq 0x1a5c(%rip), %r14      # 0x4018
xorl %r12d, %r12d
movq 0x120(%rsp), %rax
movq -0x18(%rax), %rdi
leaq 0x120(%rsp), %r15
addq %r15, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x2240
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x286d
movq %rbp, %rdi
movq %r13, %rsi
movl $0x8, %edx
callq 0x2210
leaq 0x88(%rsp), %rdi
movq %rbp, %rsi
callq 0x2bea
leaq 0xd0(%rsp), %r15
movq %rbx, 0x8(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movb %bl, 0x20(%rsp)
movb %bl, 0x30(%rsp)
movq 0x88(%rsp), %rax
movq 0x90(%rsp), %rsi
movq %rax, 0x58(%rsp)
leaq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x98(%rsp), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0x2e88
movb 0xb0(%rsp), %al
movb %al, 0x80(%rsp)
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rsi
movq %rax, 0xb8(%rsp)
movq %r15, 0xc0(%rsp)
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0x2e88
movb 0x30(%rsp), %al
movb %al, 0xe0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
leaq 0x7(%rsp), %rcx
callq 0x2c38
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
je 0x26fc
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x2718
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0xe8(%rsp), %rsi
movq 0xf0(%rsp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x2a0d
cmpl $0x8, %r12d
ja 0x2a27
movl %r12d, %eax
movslq (%r14,%rax,4), %rax
addq %r14, %rax
jmpq *%rax
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x39f5(%rip)      # 0x6150
jmp 0x27fb
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x39f8(%rip)      # 0x6168
jmp 0x27fb
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x39d3(%rip)      # 0x6158
jmp 0x27fb
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x39c9(%rip)      # 0x6160
jmp 0x27fb
movq 0x20(%rsi), %rdi
callq 0x2190
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x39da(%rip)     # 0x6188
jmp 0x27fb
movq 0x20(%rsi), %rdi
callq 0x2190
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x39bb(%rip)     # 0x6180
jmp 0x27fb
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x3999(%rip)      # 0x6170
jmp 0x27fb
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x398f(%rip)      # 0x6178
jmp 0x27fb
addq $0x20, %rsi
leaq 0x399a(%rip), %rdi      # 0x6190
callq 0x20c0
leaq 0xe8(%rsp), %rdi
callq 0x2d58
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2824
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2849
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
movq %rbp, %rdi
movq 0x377d(%rip), %rsi      # 0x5fd0
callq 0x21b0
leaq 0x3a0(%rsp), %rdi
callq 0x2070
incl %r12d
jmp 0x25bf
leaq 0x391c(%rip), %rdi      # 0x6190
leaq 0x187a(%rip), %rsi      # 0x40f5
callq 0x2060
testl %eax, %eax
je 0x2926
leaq 0x3901(%rip), %rdi      # 0x6190
leaq 0x1864(%rip), %rsi      # 0x40fa
callq 0x2060
testl %eax, %eax
je 0x292d
leaq 0x38e6(%rip), %rdi      # 0x6190
leaq 0x1851(%rip), %rsi      # 0x4102
callq 0x2060
testl %eax, %eax
jne 0x2a66
movss 0x173e(%rip), %xmm0     # 0x4004
movaps %xmm0, %xmm1
subss 0x38af(%rip), %xmm1     # 0x6180
cvtsi2ssq 0x387e(%rip), %xmm2 # 0x6158
cvtsi2ssq 0x386d(%rip), %xmm3 # 0x6150
divss %xmm3, %xmm2
xorps %xmm3, %xmm3
cvtsi2ssq 0x386d(%rip), %xmm3 # 0x6160
cvtsi2ssq 0x3874(%rip), %xmm4 # 0x6170
addss %xmm3, %xmm4
xorps %xmm3, %xmm3
cvtsi2ssq 0x385c(%rip), %xmm3 # 0x6168
addss %xmm4, %xmm3
mulss %xmm2, %xmm3
addss %xmm1, %xmm3
divss %xmm3, %xmm0
movss %xmm0, 0x3860(%rip)     # 0x6184
jmp 0x2932
callq 0x23cc
jmp 0x2932
callq 0x2446
movq 0x369f(%rip), %rdi      # 0x5fd8
leaq 0x17e2(%rip), %rsi      # 0x4122
movl $0x19, %edx
callq 0x2160
xorps %xmm0, %xmm0
cvtss2sd 0x382f(%rip), %xmm0     # 0x6184
addsd 0x16ab(%rip), %xmm0     # 0x4008
mulsd 0x16ab(%rip), %xmm0     # 0x4010
movq 0x366c(%rip), %rdi      # 0x5fd8
callq 0x21e0
movq %rax, %rbx
leaq 0x17c1(%rip), %rsi      # 0x413c
movl $0x3, %edx
movq %rax, %rdi
callq 0x2160
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x29cb
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2150
leaq 0x120(%rsp), %rdi
callq 0x2040
leaq 0x110(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29f9
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x2150
xorl %eax, %eax
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x35c4(%rip), %rdi      # 0x5fd8
leaq 0x1685(%rip), %rsi      # 0x40a0
callq 0x2130
xorl %edi, %edi
callq 0x2180
movq 0x35aa(%rip), %rdi      # 0x5fd8
leaq 0x168c(%rip), %rsi      # 0x40c1
callq 0x2130
jmp 0x2a20
movq 0x3595(%rip), %rdi      # 0x5fd8
leaq 0x15f2(%rip), %rsi      # 0x403c
callq 0x2130
jmp 0x2a20
movq 0x3580(%rip), %rdi      # 0x5fd8
leaq 0x161e(%rip), %rsi      # 0x407d
callq 0x2130
jmp 0x2a20
movq 0x356b(%rip), %rdi      # 0x5fd8
leaq 0x1694(%rip), %rsi      # 0x4108
callq 0x2130
jmp 0x2a20
jmp 0x2a7d
movq %rax, %r14
jmp 0x2b76
movq %rax, %r14
jmp 0x2b83
jmp 0x2a94
jmp 0x2b57
movq %rax, %r14
leaq 0xe8(%rsp), %rdi
callq 0x2d58
jmp 0x2af1
movq %rax, %r14
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2ad5
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x2ad5
movq %rax, %r14
jmp 0x2b32
movq %rax, %r14
jmp 0x2af1
movq %rax, %r14
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x2af1
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2b0d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2b32
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x3497(%rip), %rsi      # 0x5fd0
leaq 0x328(%rsp), %rdi
callq 0x21b0
leaq 0x3a0(%rsp), %rdi
callq 0x2070
jmp 0x2b5a
jmp 0x2b57
movq %rax, %r14
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2b76
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2150
leaq 0x120(%rsp), %rdi
callq 0x2040
leaq 0x110(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2ba4
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x2150
movq %r14, %rdi
callq 0x2220