// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x38, %rsp
callq 0x1050
movq %rax, %rbx
movl $0x3d0900, %edi         # imm = 0x3D0900
callq 0x1140
leaq -0x48(%rbp), %r14
movq %rax, (%r14)
leaq 0x3d0900(%rax), %r15
movq %r15, 0x10(%r14)
movl $0x3d0900, %edx         # imm = 0x3D0900
movq %rax, %rdi
xorl %esi, %esi
callq 0x10b0
movq %r15, 0x8(%r14)
movq %r14, %rdi
callq 0x159a
movq 0x2c01(%rip), %rdi      # 0x3fd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movl $0xfffffefb, %ecx       # imm = 0xFFFFFEFB
andl 0x18(%rdi,%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x18(%rdi,%rax)
leaq 0xc1b(%rip), %rsi       # 0x2008
movl $0x5, %edx
callq 0x1170
leaq -0x30(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1740
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
xorps %xmm1, %xmm1
cvtss2sd (%rax,%rdx,4), %xmm1
addsd %xmm1, %xmm0
incq %rdx
cmpq %rdx, %rcx
jne 0x141d
movq 0x2b98(%rip), %rdi      # 0x3fd0
callq 0x11c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x1130
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10f0
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x147c
movq -0x20(%rbp), %rsi
subq %rdi, %rsi
callq 0x1150
callq 0x1050
subq %rbx, %rax
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
imulq %rcx
movq %rdx, %rbx
movq 0x2b35(%rip), %rdi      # 0x3fd0
leaq 0xb6c(%rip), %rsi       # 0x200e
movl $0x4, %edx
callq 0x1170
movq 0x2b1d(%rip), %rdi      # 0x3fd0
movl $0xf4240, %esi          # imm = 0xF4240
callq 0x11e0
movq %rax, %r14
leaq 0xb4c(%rip), %rsi       # 0x2013
movl $0x8, %edx
movq %rax, %rdi
callq 0x1170
movq %rbx, %rax
shrq $0x3f, %rax
sarq $0x7, %rbx
addq %rax, %rbx
xorps %xmm0, %xmm0
cvtsi2ss %rbx, %xmm0
divss 0xb12(%rip), %xmm0      # 0x2004
cvtss2sd %xmm0, %xmm0
movq %r14, %rdi
callq 0x11c0
movq %rax, %rbx
leaq 0xb14(%rip), %rsi       # 0x201c
movl $0x6, %edx
movq %rax, %rdi
callq 0x1170
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10f0
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1551
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x1150
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
jmp 0x157a
movq %rax, %rbx
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x157d
movq -0x20(%rbp), %rsi
subq %rdi, %rsi
callq 0x1150
jmp 0x157d
movq %rax, %rbx
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1592
movq -0x38(%rbp), %rsi
subq %rdi, %rsi
callq 0x1150
movq %rbx, %rdi
callq 0x11f0