// File: /workspace/github_cpp_makefile_star2_O1/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 0x2a3f
movq 0x8(%rsi), %rsi
leaq 0x100(%rsp), %r14
leaq 0x120(%rsp), %rdx
movq %r14, %rdi
callq 0x2bb0
leaq 0x120(%rsp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x21f0
movq 0x120(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x140(%rsp,%rax)
jne 0x2a54
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1ba6(%rip), %rdx      # 0x413f
leaq 0x38(%rsp), %rdi
movq %rdx, %rsi
callq 0x2dc2
xorl %r14d, %r14d
leaq 0x38(%rsp), %r13
leaq 0x328(%rsp), %rbp
leaq 0x1a5b(%rip), %rbx      # 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 0x2870
movq %rbp, %rdi
movq %r13, %rsi
movl $0x8, %edx
callq 0x2210
leaq 0x88(%rsp), %rdi
movq %rbp, %rsi
callq 0x2bee
leaq 0xd0(%rsp), %r15
movq %r14, 0x8(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movb %r14b, 0x20(%rsp)
movb %r14b, 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 0x2e82
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 0x2e82
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 0x2c3c
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
je 0x26ff
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x271b
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0xe8(%rsp), %rsi
movq 0xf0(%rsp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x2a10
cmpl $0x8, %r12d
ja 0x2a2a
movl %r12d, %eax
movslq (%rbx,%rax,4), %rax
addq %rbx, %rax
jmpq *%rax
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x39f2(%rip)      # 0x6150
jmp 0x27fe
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x39f5(%rip)      # 0x6168
jmp 0x27fe
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x39d0(%rip)      # 0x6158
jmp 0x27fe
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x39c6(%rip)      # 0x6160
jmp 0x27fe
movq 0x20(%rsi), %rdi
callq 0x2190
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x39d7(%rip)     # 0x6188
jmp 0x27fe
movq 0x20(%rsi), %rdi
callq 0x2190
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x39b8(%rip)     # 0x6180
jmp 0x27fe
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x3996(%rip)      # 0x6170
jmp 0x27fe
movq 0x20(%rsi), %rdi
callq 0x2170
movq %rax, 0x398c(%rip)      # 0x6178
jmp 0x27fe
addq $0x20, %rsi
leaq 0x3997(%rip), %rdi      # 0x6190
callq 0x20c0
leaq 0xe8(%rsp), %rdi
callq 0x2d5c
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2827
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x284c
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
movq %rbp, %rdi
movq 0x377a(%rip), %rsi      # 0x5fd0
callq 0x21b0
leaq 0x3a0(%rsp), %rdi
callq 0x2070
incl %r12d
jmp 0x25c0
leaq 0x3919(%rip), %rdi      # 0x6190
leaq 0x1877(%rip), %rsi      # 0x40f5
callq 0x2060
testl %eax, %eax
je 0x2929
leaq 0x38fe(%rip), %rdi      # 0x6190
leaq 0x1861(%rip), %rsi      # 0x40fa
callq 0x2060
testl %eax, %eax
je 0x2930
leaq 0x38e3(%rip), %rdi      # 0x6190
leaq 0x184e(%rip), %rsi      # 0x4102
callq 0x2060
testl %eax, %eax
jne 0x2a69
movss 0x173b(%rip), %xmm0     # 0x4004
movaps %xmm0, %xmm1
subss 0x38ac(%rip), %xmm1     # 0x6180
cvtsi2ssq 0x387b(%rip), %xmm2 # 0x6158
cvtsi2ssq 0x386a(%rip), %xmm3 # 0x6150
divss %xmm3, %xmm2
xorps %xmm3, %xmm3
cvtsi2ssq 0x386a(%rip), %xmm3 # 0x6160
cvtsi2ssq 0x3871(%rip), %xmm4 # 0x6170
addss %xmm3, %xmm4
xorps %xmm3, %xmm3
cvtsi2ssq 0x3859(%rip), %xmm3 # 0x6168
addss %xmm4, %xmm3
mulss %xmm2, %xmm3
addss %xmm1, %xmm3
divss %xmm3, %xmm0
movss %xmm0, 0x385d(%rip)     # 0x6184
jmp 0x2935
callq 0x23cc
jmp 0x2935
callq 0x2446
movq 0x369c(%rip), %rdi      # 0x5fd8
leaq 0x17df(%rip), %rsi      # 0x4122
movl $0x19, %edx
callq 0x2160
xorps %xmm0, %xmm0
cvtss2sd 0x382c(%rip), %xmm0     # 0x6184
addsd 0x16a8(%rip), %xmm0     # 0x4008
mulsd 0x16a8(%rip), %xmm0     # 0x4010
movq 0x3669(%rip), %rdi      # 0x5fd8
callq 0x21e0
movq %rax, %rbx
leaq 0x17be(%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 0x29ce
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 0x29fc
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 0x35c1(%rip), %rdi      # 0x5fd8
leaq 0x1682(%rip), %rsi      # 0x40a0
callq 0x2130
xorl %edi, %edi
callq 0x2180
movq 0x35a7(%rip), %rdi      # 0x5fd8
leaq 0x1689(%rip), %rsi      # 0x40c1
callq 0x2130
jmp 0x2a23
movq 0x3592(%rip), %rdi      # 0x5fd8
leaq 0x15ef(%rip), %rsi      # 0x403c
callq 0x2130
jmp 0x2a23
movq 0x357d(%rip), %rdi      # 0x5fd8
leaq 0x161b(%rip), %rsi      # 0x407d
callq 0x2130
jmp 0x2a23
movq 0x3568(%rip), %rdi      # 0x5fd8
leaq 0x1691(%rip), %rsi      # 0x4108
callq 0x2130
jmp 0x2a23
jmp 0x2a80
movq %rax, %rbx
jmp 0x2b79
movq %rax, %rbx
jmp 0x2b86
jmp 0x2a97
jmp 0x2b5a
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x2d5c
jmp 0x2af4
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2ad8
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x2ad8
movq %rax, %rbx
jmp 0x2b35
movq %rax, %rbx
jmp 0x2af4
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x2af4
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2b10
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x2b35
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x3494(%rip), %rsi      # 0x5fd0
leaq 0x328(%rsp), %rdi
callq 0x21b0
leaq 0x3a0(%rsp), %rdi
callq 0x2070
jmp 0x2b5d
jmp 0x2b5a
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2b79
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 0x2ba7
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
callq 0x2220
nop