// File: justinpajak[P]Sum_SGX/aggsum.cpp
// Function: main
int main(int argc, char *argv[]) {
	
	int n = 1000000;
	auto start = std::chrono::high_resolution_clock::now();
	vector<float> nums(n);
	
	/* Read in data from d_enc.txt, decrypt and put in nums vector */
	readAndDecrypt(nums);

	/* Compute sum */
	std::cout << std::fixed << "Sum: " << agg_sum(nums) << std::endl;

	/* Compute time */
	auto stop = std::chrono::high_resolution_clock::now();
	auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
	std::cout << "n = " << n << ". Time: " << duration.count() / float(1000000) << " secs." << std::endl;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0xf4240, -0x14(%rbp)   # imm = 0xF4240
callq 0x2040
movq %rax, -0x20(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x2800
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x2820
jmp 0x23ad
leaq -0x39(%rbp), %rdi
callq 0x2890
leaq -0x38(%rbp), %rdi
callq 0x25d0
jmp 0x23c1
movq 0x4c08(%rip), %rdi      # 0x6fd0
leaq 0x4e1(%rip), %rsi       # 0x28b0
callq 0x2080
movq %rax, -0x98(%rbp)
jmp 0x23dd
movq -0x98(%rbp), %rdi
leaq 0x1c1d(%rip), %rsi      # 0x4008
callq 0x2140
movq %rax, -0xa0(%rbp)
jmp 0x23f9
leaq -0x68(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x28e0
jmp 0x2408
leaq -0x68(%rbp), %rdi
callq 0x26f0
movsd %xmm0, -0xa8(%rbp)
jmp 0x241b
movsd -0xa8(%rbp), %xmm0
movq -0xa0(%rbp), %rdi
callq 0x2200
movq %rax, -0xb0(%rbp)
jmp 0x2438
movq -0xb0(%rbp), %rdi
movq 0x4b7a(%rip), %rsi      # 0x6fc0
callq 0x2170
jmp 0x244d
leaq -0x68(%rbp), %rdi
callq 0x29d0
callq 0x2040
movq %rax, -0x70(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2a60
movq %rax, -0xb8(%rbp)
jmp 0x2475
movq -0xb8(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x2a30
movq %rax, -0xc0(%rbp)
jmp 0x2492
movq -0xc0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq 0x4b2c(%rip), %rdi      # 0x6fd0
leaq 0x1b63(%rip), %rsi      # 0x400e
callq 0x2140
movq %rax, -0xc8(%rbp)
jmp 0x24b9
movq -0xc8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x21e0
movq %rax, -0xd0(%rbp)
jmp 0x24d1
movq -0xd0(%rbp), %rdi
leaq 0x1b34(%rip), %rsi      # 0x4013
callq 0x2140
movq %rax, -0xd8(%rbp)
jmp 0x24ed
leaq -0x78(%rbp), %rdi
callq 0x2ab0
movq %rax, -0xe0(%rbp)
jmp 0x24ff
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rax
cvtsi2ss %rax, %xmm0
movss 0x1aea(%rip), %xmm1     # 0x4004
divss %xmm1, %xmm0
callq 0x2110
movq %rax, -0xe8(%rbp)
jmp 0x252c
movq -0xe8(%rbp), %rdi
leaq 0x1ae2(%rip), %rsi      # 0x401c
callq 0x2140
movq %rax, -0xf0(%rbp)
jmp 0x2548
movq -0xf0(%rbp), %rdi
movq 0x4a6a(%rip), %rsi      # 0x6fc0
callq 0x2170
jmp 0x255d
movl $0x0, -0x4(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x29d0
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x2890
jmp 0x25bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x25b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x29d0
leaq -0x38(%rbp), %rdi
callq 0x29d0
movq -0x48(%rbp), %rdi
callq 0x21f0
nopw %cs:(%rax,%rax)