// File: /workspace/github_cpp_makefile_star2_O1/iZhangHui[P]CppPrimer/CH10_GenericAlgorithms/examples/avg_price.cc
// Function: main
int main() 
{
	// iterators that can read and write Sales_items
	istream_iterator<Sales_item> item_iter(cin), eof;
	ostream_iterator<Sales_item> out_iter(cout, "\n");

	// store the first transaction in sum and read the next record
	Sales_item sum = *item_iter++; 

	while (item_iter != eof) {
		// if the current transaction (which is in item_iter) 
		// has the same ISBN
	    if (item_iter->isbn() == sum.isbn())
	        sum += *item_iter++; // add it to sum 
		                         // and read the next transaction
	    else {
	        out_iter = sum;      // write the current sum
	        sum = *item_iter++;  // read the next transaction
	    }
	}
	out_iter = sum;  // remember to print the last set of records

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq 0x2ada(%rip), %rsi      # 0x3fe0
leaq -0x108(%rbp), %rbx
movq %rbx, %rdi
callq 0x187e
leaq -0x138(%rbp), %r14
xorpd %xmm0, %xmm0
movapd %xmm0, -0x18(%r14)
movapd %xmm0, -0x8(%r14)
movapd %xmm0, 0x8(%r14)
xorl %eax, %eax
movq %rax, 0x18(%r14)
movq %r14, -0x10(%r14)
movq %rax, -0x8(%r14)
movb %al, (%r14)
movl $0x0, 0x10(%r14)
movb %al, 0x20(%r14)
movq 0x2a7a(%rip), %rax      # 0x3fd0
movq %rax, -0xa8(%rbp)
leaq 0xaa2(%rip), %rax       # 0x2006
movq %rax, -0xa0(%rbp)
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x18de
leaq -0x88(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
addq %rsi, %rdx
leaq -0x98(%rbp), %rdi
callq 0x199e
leaq -0x50(%rbp), %rax
movupd 0x10(%rax), %xmm0
movupd %xmm0, -0x78(%rbp)
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15be
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10a0
leaq -0x58(%rbp), %r13
leaq -0xb8(%rbp), %r15
leaq -0x68(%rbp), %r14
leaq -0x98(%rbp), %rbx
movb -0xd0(%rbp), %al
cmpb -0x118(%rbp), %al
jne 0x15fe
testb %al, %al
je 0x172a
movq -0x108(%rbp), %rax
cmpq -0x150(%rbp), %rax
je 0x172a
movq %r13, -0x68(%rbp)
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x199e
movq %r15, -0xc8(%rbp)
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %rdi
callq 0x199e
movq -0x60(%rbp), %rdx
cmpq -0xc0(%rbp), %rdx
jne 0x1669
testq %rdx, %rdx
je 0x166e
movq -0xc8(%rbp), %rsi
movq -0x68(%rbp), %rdi
callq 0x10b0
testl %eax, %eax
sete %r12b
jmp 0x1671
xorl %r12d, %r12d
jmp 0x1671
movb $0x1, %r12b
movq -0xc8(%rbp), %rdi
cmpq %r15, %rdi
je 0x168c
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x10a0
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x16a1
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10a0
testb %r12b, %r12b
je 0x16ce
movq %r14, %rdi
leaq -0x108(%rbp), %rsi
xorl %edx, %edx
callq 0x18de
movl -0x40(%rbp), %eax
addl %eax, -0x78(%rbp)
movsd -0x38(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
jmp 0x1708
leaq -0xa8(%rbp), %rdi
movq %rbx, %rsi
callq 0x1958
movq %r14, %rdi
leaq -0x108(%rbp), %rsi
xorl %edx, %edx
callq 0x18de
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
callq 0x1040
movupd 0x18(%r13), %xmm0
leaq -0x78(%rbp), %rax
movupd %xmm0, (%rax)
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x15d4
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10a0
jmp 0x15d4
leaq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x1958
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
leaq -0x138(%rbp), %rbx
je 0x1766
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x10a0
movq -0x148(%rbp), %rdi
cmpq %rbx, %rdi
je 0x1781
movq -0x138(%rbp), %rsi
incq %rsi
callq 0x10a0
leaq -0xf0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x17a0
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x10a0
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x17f5
movq %rax, %rbx
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x183b
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x10a0
jmp 0x183b
movq %rax, %rbx
jmp 0x183b
jmp 0x17f5
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x1812
movq -0x50(%rbp), %rsi
jmp 0x180a
jmp 0x17f5
jmp 0x17f5
movq %rax, %rbx
jmp 0x1812
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x1812
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x10a0
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x1834
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x10a0
leaq -0x138(%rbp), %r14
movq -0x148(%rbp), %rdi
cmpq %r14, %rdi
je 0x1856
movq -0x138(%rbp), %rsi
incq %rsi
callq 0x10a0
leaq -0xf0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1875
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x10a0
movq %rbx, %rdi
callq 0x1120
nop