// File: /workspace/github_cpp_makefile_star2_O1/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
xorps %xmm0, %xmm0
movaps %xmm0, -0x40(%rbp)
xorl %ebx, %ebx
movq %rbx, -0x30(%rbp)
movl $0x28, %edi
callq 0x2100
movq %rax, -0x40(%rbp)
movq %rax, -0x38(%rbp)
leaq 0x28(%rax), %rcx
movq %rcx, -0x30(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movq %rbx, 0x20(%rax)
movq %rcx, -0x38(%rbp)
movl $0x1, (%rax,%rbx)
addq $0x4, %rbx
cmpq $0x28, %rbx
jne 0x2369
xorl %esi, %esi
xorl %ecx, %ecx
addl (%rax,%rcx), %esi
addq $0x4, %rcx
cmpq $0x28, %rcx
jne 0x237e
movq 0x2c3e(%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 0x23f2
shrq %rdx
shlq $0x2, %rdx
xorl %esi, %esi
movl $0xa, (%rax,%rsi)
addq $0x4, %rsi
cmpq %rsi, %rdx
jne 0x23e2
xorl %esi, %esi
cmpq %rcx, %rax
je 0x2401
addl (%rax), %esi
addq $0x4, %rax
jmp 0x23f4
movq 0x2bc8(%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 0x245c
sarq %rdx
andq $-0x4, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2090
xorl %esi, %esi
cmpq %r14, %rbx
je 0x246b
addl (%rbx), %esi
addq $0x4, %rbx
jmp 0x245e
movq 0x2b5e(%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 0x24d4
movl -0xe0(%rbp), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, -0x38(%rbp)
jmp 0x24df
movq %r14, %rdi
movq %rbx, %rdx
callq 0x285c
decl %r15d
cmpl $0x1, %r15d
ja 0x24b8
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
xorl %esi, %esi
cmpq %rcx, %rax
je 0x24ff
addl (%rax), %esi
addq $0x4, %rax
jmp 0x24f2
movq 0x2aca(%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 0x2a7f(%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 0x258e
movq %rbx, %rdi
movq %r15, %rsi
callq 0x277a
jmp 0x2568
movq -0xc0(%rbp), %rbx
movq -0xb8(%rbp), %r12
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0xa9c(%rip), %rdx       # 0x3047
leaq -0x60(%rbp), %rdi
movq %rdx, %rsi
callq 0x2c66
cmpq %r12, %rbx
je 0x260b
leaq -0xd0(%rbp), %r13
leaq -0xe0(%rbp), %r14
leaq -0x60(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2cff
movq %r15, %rdi
movq %r14, %rsi
callq 0x2130
movq -0xe0(%rbp), %rdi
cmpq %r13, %rdi
je 0x2602
movq -0xd0(%rbp), %rsi
incq %rsi
callq 0x2110
addq $0x20, %rbx
cmpq %r12, %rbx
jne 0x25ce
leaq -0x70(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x60(%rbp), %rax
leaq -0x50(%rbp), %rcx
cmpq %rcx, %rax
je 0x262e
movq %rax, -0x80(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x2635
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq -0x58(%rbp), %rdx
movq %rdx, -0x78(%rbp)
movq %rcx, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movb $0x0, -0x50(%rbp)
movq -0x80(%rbp), %rsi
movq 0x2978(%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 0x269c
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2110
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x26be
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2110
leaq -0xc0(%rbp), %rdi
callq 0x27c6
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x26df
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 0x272c
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x272f
movq -0x70(%rbp), %rsi
jmp 0x2722
jmp 0x2709
movq %rax, %rbx
jmp 0x275d
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x272f
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2110
jmp 0x272f
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x2751
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2110
leaq -0xc0(%rbp), %rdi
callq 0x27c6
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x2772
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
callq 0x2110
movq %rbx, %rdi
callq 0x21a0