// File: /workspace/github_cpp_makefile_star2_O3/iZhangHui[P]CppPrimer/CH10_GenericAlgorithms/examples/accum.cc
// Function: main
int main()
{
	vector<int> vec(10);              // default initialized to 0
	fill(vec.begin(), vec.end(), 1);  // reset each element to 1

	// sum the elements in vec starting the summation with the value 0
	int sum = accumulate(vec.cbegin(), vec.cend(), 0);
	cout << sum << endl;
	
	// set a subsequence of the container to 10
	fill(vec.begin(), vec.begin() + vec.size()/2, 10);
	cout << accumulate(vec.begin(), vec.end(), 0) << endl;

	// reset the same subsequence to 0
	fill_n(vec.begin(), vec.size()/2, 0);
	cout << accumulate(vec.begin(), vec.end(), 0) << endl;

	// create 10 elements on the end of vec each with the value 42
	fill_n(back_inserter(vec), 10, 42);
	cout << accumulate(vec.begin(), vec.end(), 0) << endl;
	
	// concatenate elements in a vector of strings and store in sum 
	vector<string> v;
	string s;
	while (cin >> s)
		v.push_back(s);
	string concat = accumulate(v.cbegin(), v.cend(), string(""));
	cout << concat << endl;
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl $0x28, %edi
callq 0x2100
movq %rax, -0x40(%rbp)
leaq 0x28(%rax), %rcx
movq %rcx, -0x30(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq $0x0, 0x20(%rax)
movq %rcx, -0x38(%rbp)
xorl %ecx, %ecx
movl $0x1, (%rax,%rcx)
addq $0x4, %rcx
cmpq $0x28, %rcx
jne 0x235e
xorl %esi, %esi
xorl %ecx, %ecx
addl (%rax,%rcx), %esi
addq $0x4, %rcx
cmpq $0x28, %rcx
jne 0x2373
movq 0x2c49(%rip), %rdi      # 0x4fd0
callq 0x2190
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq $0x2, %rdx
jb 0x23e7
shrq %rdx
shlq $0x2, %rdx
xorl %esi, %esi
movl $0xa, (%rax,%rsi)
addq $0x4, %rsi
cmpq %rsi, %rdx
jne 0x23d7
xorl %esi, %esi
cmpq %rcx, %rax
je 0x23f6
addl (%rax), %esi
addq $0x4, %rax
jmp 0x23e9
movq 0x2bd3(%rip), %rdi      # 0x4fd0
callq 0x2190
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %r14
movq %r14, %rdx
subq %rbx, %rdx
cmpq $0x5, %rdx
jb 0x2451
sarq %rdx
andq $-0x4, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2090
xorl %esi, %esi
cmpq %r14, %rbx
je 0x2460
addl (%rbx), %esi
addq $0x4, %rbx
jmp 0x2453
movq 0x2b69(%rip), %rdi      # 0x4fd0
callq 0x2190
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
leaq -0xe0(%rbp), %rbx
movl $0x2a, (%rbx)
movl $0xb, %r15d
leaq -0x40(%rbp), %r14
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x24c9
movl -0xe0(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x38(%rbp)
jmp 0x24d4
movq %r14, %rdi
movq %rbx, %rdx
callq 0x2854
decl %r15d
cmpl $0x1, %r15d
ja 0x24ad
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
xorl %esi, %esi
cmpq %rcx, %rax
je 0x24f4
addl (%rax), %esi
addq $0x4, %rax
jmp 0x24e7
movq 0x2ad5(%rip), %rdi      # 0x4fd0
callq 0x2190
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
xorps %xmm0, %xmm0
leaq -0xc0(%rbp), %rbx
movaps %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
leaq -0x90(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
movq 0x2a8a(%rip), %r14      # 0x4fe0
leaq -0xa0(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x2140
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2583
movq %rbx, %rdi
movq %r15, %rsi
callq 0x276e
jmp 0x255d
movq -0xc0(%rbp), %rbx
movq -0xb8(%rbp), %r12
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0xaa7(%rip), %rdx       # 0x3047
leaq -0x60(%rbp), %rdi
movq %rdx, %rsi
callq 0x2c3a
cmpq %r12, %rbx
je 0x2600
leaq -0xd0(%rbp), %r13
leaq -0xe0(%rbp), %r14
leaq -0x60(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2cd8
movq %r15, %rdi
movq %r14, %rsi
callq 0x2130
movq -0xe0(%rbp), %rdi
cmpq %r13, %rdi
je 0x25f7
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x2110
addq $0x20, %rbx
cmpq %r12, %rbx
jne 0x25c3
leaq -0x70(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x60(%rbp), %rsi
leaq -0x50(%rbp), %rcx
cmpq %rcx, %rsi
je 0x2623
movq %rsi, -0x80(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x262d
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq %r14, %rsi
movq -0x58(%rbp), %rdx
movq %rdx, -0x78(%rbp)
movq %rcx, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movb $0x0, -0x50(%rbp)
movq 0x2984(%rip), %rdi      # 0x4fd0
callq 0x2120
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20a0
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x2690
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2110
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x26b2
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2110
leaq -0xc0(%rbp), %rdi
callq 0x27ba
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x26d3
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x2110
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2720
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x2723
movq -0x70(%rbp), %rsi
jmp 0x2716
jmp 0x26fd
movq %rax, %rbx
jmp 0x2751
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x2723
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2110
jmp 0x2723
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x2745
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2110
leaq -0xc0(%rbp), %rdi
callq 0x27ba
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x2766
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x2110
movq %rbx, %rdi
callq 0x21a0