// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x98, %rsp
leaq -0x38(%rbp), %rbx
pushq $0xa
popq %rsi
leaq -0x58(%rbp), %rdx
movq %rbx, %rdi
callq 0x2548
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq %rax, %rdx
cmpq %rcx, %rdx
je 0x231a
movl $0x1, (%rdx)
addq $0x4, %rdx
jmp 0x2309
xorl %esi, %esi
cmpq %rcx, %rax
je 0x2329
addl (%rax), %esi
addq $0x4, %rax
jmp 0x231c
movq 0x2ca0(%rip), %rdi      # 0x4fd0
callq 0x2170
movq %rax, %rdi
callq 0x2080
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq %rdx
andq $-0x4, %rdx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x2366
movl $0xa, (%rax,%rsi)
addq $0x4, %rsi
jmp 0x2354
xorl %esi, %esi
cmpq %rcx, %rax
je 0x2375
addl (%rax), %esi
addq $0x4, %rax
jmp 0x2368
movq 0x2c54(%rip), %rdi      # 0x4fd0
callq 0x2170
movq %rax, %rdi
callq 0x2080
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
subq %rdi, %rsi
sarq $0x2, %rsi
shrq %rsi
leaq -0x58(%rbp), %rdx
andl $0x0, (%rdx)
callq 0x27ad
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
xorl %esi, %esi
cmpq %rcx, %rax
je 0x23be
addl (%rax), %esi
addq $0x4, %rax
jmp 0x23b1
movq 0x2c0b(%rip), %rdi      # 0x4fd0
callq 0x2170
movq %rax, %rdi
callq 0x2080
leaq -0x58(%rbp), %rdx
movl $0x2a, (%rdx)
leaq -0x38(%rbp), %rdi
pushq $0xa
popq %rsi
callq 0x27d8
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
xorl %esi, %esi
cmpq %rcx, %rax
je 0x23ff
addl (%rax), %esi
addq $0x4, %rax
jmp 0x23f2
movq 0x2bca(%rip), %rdi      # 0x4fd0
callq 0x2170
movq %rax, %rdi
callq 0x2080
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rbx
andq $0x0, 0x10(%rbx)
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movaps %xmm0, (%rbx)
movb $0x0, (%rax)
movq 0x2ba7(%rip), %r14      # 0x4fe0
leaq -0x58(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x2100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2463
movq %rbx, %rdi
movq %r15, %rsi
callq 0x259a
jmp 0x243d
movq -0x70(%rbp), %rbx
movq -0x68(%rbp), %r14
leaq 0xbc2(%rip), %rsi       # 0x3034
leaq -0x90(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x2050
leaq -0xb0(%rbp), %rdi
leaq -0x90(%rbp), %rcx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x25d5
leaq -0x90(%rbp), %rdi
callq 0x2070
movq 0x2b22(%rip), %rdi      # 0x4fd0
leaq -0xb0(%rbp), %rsi
callq 0x20c0
movq %rax, %rdi
callq 0x2080
leaq -0xb0(%rbp), %rdi
callq 0x2070
leaq -0x58(%rbp), %rdi
callq 0x2070
leaq -0x70(%rbp), %rdi
callq 0x2640
leaq -0x38(%rbp), %rdi
callq 0x26b4
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0x2515
jmp 0x2521
jmp 0x251c
jmp 0x251c
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x2070
jmp 0x2524
movq %rax, %rbx
jmp 0x2536
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x2070
leaq -0x70(%rbp), %rdi
callq 0x2640
leaq -0x38(%rbp), %rdi
callq 0x26b4
movq %rbx, %rdi
callq 0x2180
nop