// File: 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
subq $0x230, %rsp            # imm = 0x230
movl $0x0, -0x4(%rbp)
leaq -0x21(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x28c0
movq -0x178(%rbp), %rdx
leaq -0x20(%rbp), %rdi
movl $0xa, %esi
callq 0x28e0
jmp 0x2359
leaq -0x21(%rbp), %rdi
callq 0x2950
leaq -0x20(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x29b0
movq -0x180(%rbp), %rdi
movq %rax, -0x40(%rbp)
callq 0x29e0
movq %rax, -0x48(%rbp)
movl $0x1, -0x4c(%rbp)
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
callq 0x2970
jmp 0x23a0
leaq -0x20(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x2a70
movq -0x190(%rbp), %rdi
movq %rax, -0x58(%rbp)
callq 0x2aa0
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
xorl %edx, %edx
callq 0x2a10
movl %eax, -0x184(%rbp)
jmp 0x23db
movl -0x184(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %esi
movq 0x5be2(%rip), %rdi      # 0x7fd0
callq 0x21a0
movq %rax, -0x198(%rbp)
jmp 0x23fc
movq -0x198(%rbp), %rdi
movq 0x5bb6(%rip), %rsi      # 0x7fc0
callq 0x20f0
jmp 0x2411
leaq -0x20(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x29b0
movq -0x1a0(%rbp), %rdi
movq %rax, -0x68(%rbp)
callq 0x29b0
movq -0x1a0(%rbp), %rdi
movq %rax, -0x78(%rbp)
callq 0x2b10
movq %rax, %rsi
shrq %rsi
leaq -0x78(%rbp), %rdi
callq 0x2ad0
movq %rax, -0x70(%rbp)
movl $0xa, -0x7c(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
leaq -0x7c(%rbp), %rdx
callq 0x2970
jmp 0x246e
leaq -0x20(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x29b0
movq -0x1b0(%rbp), %rdi
movq %rax, -0x88(%rbp)
callq 0x29e0
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
movq -0x90(%rbp), %rsi
xorl %edx, %edx
callq 0x2b30
movl %eax, -0x1a4(%rbp)
jmp 0x24b5
movl -0x1a4(%rbp), %esi
movq 0x5b0e(%rip), %rdi      # 0x7fd0
callq 0x21a0
movq %rax, -0x1b8(%rbp)
jmp 0x24d0
movq -0x1b8(%rbp), %rdi
movq 0x5ae2(%rip), %rsi      # 0x7fc0
callq 0x20f0
jmp 0x24e5
leaq -0x20(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x29b0
movq -0x1c8(%rbp), %rdi
movq %rax, -0x98(%rbp)
callq 0x2b10
movq %rax, %rsi
shrq %rsi
movl $0x0, -0x9c(%rbp)
movq -0x98(%rbp), %rdi
leaq -0x9c(%rbp), %rdx
callq 0x2b90
movq %rax, -0x1c0(%rbp)
jmp 0x2534
movq -0x1c0(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x20(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x29b0
movq -0x1d8(%rbp), %rdi
movq %rax, -0xb0(%rbp)
callq 0x29e0
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
xorl %edx, %edx
callq 0x2b30
movl %eax, -0x1cc(%rbp)
jmp 0x2589
movl -0x1cc(%rbp), %esi
movq 0x5a3a(%rip), %rdi      # 0x7fd0
callq 0x21a0
movq %rax, -0x1e0(%rbp)
jmp 0x25a4
movq -0x1e0(%rbp), %rdi
movq 0x5a0e(%rip), %rsi      # 0x7fc0
callq 0x20f0
jmp 0x25b9
leaq -0x20(%rbp), %rdi
callq 0x2c50
movq %rax, -0x1e8(%rbp)
jmp 0x25cb
movq -0x1e8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl $0x2a, -0xc4(%rbp)
movq -0xc0(%rbp), %rdi
movl $0xa, %esi
leaq -0xc4(%rbp), %rdx
callq 0x2bf0
movq %rax, -0x1f0(%rbp)
jmp 0x2604
movq -0x1f0(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x20(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0x29b0
movq -0x200(%rbp), %rdi
movq %rax, -0xd8(%rbp)
callq 0x29e0
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
xorl %edx, %edx
callq 0x2b30
movl %eax, -0x1f4(%rbp)
jmp 0x2659
movl -0x1f4(%rbp), %esi
movq 0x596a(%rip), %rdi      # 0x7fd0
callq 0x21a0
movq %rax, -0x208(%rbp)
jmp 0x2674
movq -0x208(%rbp), %rdi
movq 0x593e(%rip), %rsi      # 0x7fc0
callq 0x20f0
jmp 0x2689
leaq -0xf8(%rbp), %rdi
callq 0x2c80
leaq -0x118(%rbp), %rdi
callq 0x2150
movq 0x5938(%rip), %rdi      # 0x7fe0
leaq -0x118(%rbp), %rsi
callq 0x2130
movq %rax, -0x210(%rbp)
jmp 0x26bd
movq -0x210(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2120
movb %al, -0x211(%rbp)
jmp 0x26db
movb -0x211(%rbp), %al
testb $0x1, %al
jne 0x26e7
jmp 0x273a
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x2ca0
jmp 0x26fc
jmp 0x26a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x21(%rbp), %rdi
callq 0x2950
jmp 0x28af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x28a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x288e
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x228(%rbp)
callq 0x2da0
movq -0x228(%rbp), %rdi
movq %rax, -0x140(%rbp)
callq 0x2dd0
movq %rax, -0x148(%rbp)
leaq -0x169(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x21c0
movq -0x220(%rbp), %rdx
leaq 0x28ac(%rip), %rsi      # 0x5034
leaq -0x168(%rbp), %rdi
callq 0x2140
jmp 0x2796
movq -0x140(%rbp), %rsi
movq -0x148(%rbp), %rdx
leaq -0x138(%rbp), %rdi
leaq -0x168(%rbp), %rcx
callq 0x2d10
jmp 0x27b9
leaq -0x168(%rbp), %rdi
callq 0x2090
leaq -0x169(%rbp), %rdi
callq 0x2100
movq 0x57f8(%rip), %rdi      # 0x7fd0
leaq -0x138(%rbp), %rsi
callq 0x20c0
movq %rax, -0x230(%rbp)
jmp 0x27ed
movq -0x230(%rbp), %rdi
movq 0x57c5(%rip), %rsi      # 0x7fc0
callq 0x20f0
jmp 0x2802
movl $0x0, -0x4(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x2090
leaq -0x118(%rbp), %rdi
callq 0x2090
leaq -0xf8(%rbp), %rdi
callq 0x2e00
leaq -0x20(%rbp), %rdi
callq 0x2e60
movl -0x4(%rbp), %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x2868
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x2090
leaq -0x169(%rbp), %rdi
callq 0x2100
jmp 0x288e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x2090
leaq -0x118(%rbp), %rdi
callq 0x2090
leaq -0xf8(%rbp), %rdi
callq 0x2e00
leaq -0x20(%rbp), %rdi
callq 0x2e60
movq -0x30(%rbp), %rdi
callq 0x21b0
nopl (%rax,%rax)