// File: /workspace/github_cpp_makefile_star2_O3/iZhangHui[P]CppPrimer/CH02_VariablesAndBasicTypes/examples/Sales_data.cc
// Function: main
int main()
{
	Sales_data data1, data2;

	// code to read into data1 and data2
	double price = 0;  // price per book, used to calculate total revenue

	// read the first transactions: ISBN, number of books sold, price per book
	std::cin >> data1.bookNo >> data1.units_sold >> price;
	// calculate total revenue from price and units_sold
	data1.revenue = data1.units_sold * price;

	// read the second transaction
	std::cin >> data2.bookNo >> data2.units_sold >> price;
	data2.revenue = data2.units_sold * price;

	// code to check whether data1 and data2 have the same ISBN
	//        and if so print the sum of data1 and data2
	if (data1.bookNo == data2.bookNo) {
		unsigned totalCnt = data1.units_sold + data2.units_sold;
		double totalRevenue = data1.revenue + data2.revenue;

		// print: ISBN, total sold, total revenue, average price per book
		std::cout << data1.bookNo << " " << totalCnt 
		          << " " << totalRevenue << " ";
		if (totalCnt != 0)
			std::cout << totalRevenue/totalCnt << std::endl;
		else
			std::cout  << "(no sales)" << std::endl;

		return 0;  // indicate success
	} else {  // transactions weren't for the same ISBN
		std::cerr << "Data must refer to the same ISBN" 
		          << std::endl;
		return -1; // indicate failure
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
xorl %eax, %eax
movq %rax, -0x8(%r15)
movb %al, (%r15)
movl %eax, 0x10(%r15)
movq %rax, 0x18(%r15)
leaq -0x88(%rbp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
movl %eax, 0x10(%r12)
movq %rax, 0x18(%r12)
movq %rax, -0x38(%rbp)
movq 0x2d38(%rip), %rdi      # 0x3fd8
leaq -0x68(%rbp), %rsi
callq 0x10c0
leaq -0x48(%rbp), %rsi
movq %rax, %rdi
callq 0x10f0
leaq -0x38(%rbp), %rsi
movq %rax, %rdi
callq 0x1040
movl -0x48(%rbp), %eax
cvtsi2sd %rax, %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movq 0x2cfe(%rip), %rdi      # 0x3fd8
leaq -0x98(%rbp), %rsi
callq 0x10c0
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x10f0
leaq -0x38(%rbp), %rsi
movq %rax, %rdi
callq 0x1040
movl -0x78(%rbp), %r13d
xorps %xmm0, %xmm0
cvtsi2sd %r13, %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x60(%rbp), %rbx
cmpq -0x90(%rbp), %rbx
jne 0x134a
movq -0x68(%rbp), %r14
testq %rbx, %rbx
je 0x139a
movq -0x98(%rbp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
movsd %xmm0, -0x30(%rbp)
callq 0x10a0
movsd -0x30(%rbp), %xmm0
testl %eax, %eax
je 0x139a
movq 0x2c9f(%rip), %rbx      # 0x3ff0
leaq 0xcb9(%rip), %rsi       # 0x2011
movl $0x20, %edx
movq %rbx, %rdi
callq 0x10b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1080
movsbl %al, %esi
movq 0x2c6d(%rip), %rdi      # 0x3ff0
callq 0x1030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x1060
jmp 0x1493
addl -0x48(%rbp), %r13d
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x2c19(%rip), %rdi      # 0x3fc8
movq %r14, %rsi
movq %rbx, %rdx
callq 0x10b0
movq %rax, %r14
leaq 0xc40(%rip), %rsi       # 0x2004
movl $0x1, %edx
movq %rax, %rdi
callq 0x10b0
movl %r13d, %ebx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1050
movq %rax, %r14
leaq 0xc1b(%rip), %rsi       # 0x2004
movl $0x1, %edx
movq %rax, %rdi
callq 0x10b0
movq %r14, %rdi
movsd -0x30(%rbp), %xmm0
callq 0x10e0
leaq 0xbfa(%rip), %rsi       # 0x2004
movl $0x1, %edx
movq %rax, %rdi
callq 0x10b0
testl %r13d, %r13d
je 0x144f
cvtsi2sd %rbx, %xmm1
movsd -0x30(%rbp), %xmm0
divsd %xmm1, %xmm0
movq 0x2b97(%rip), %rdi      # 0x3fc8
callq 0x10e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1080
jmp 0x147e
movq 0x2b72(%rip), %rbx      # 0x3fc8
leaq 0xba9(%rip), %rsi       # 0x2006
movl $0xa, %edx
movq %rbx, %rdi
callq 0x10b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1080
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x1060
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0x14ae
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x1090
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x14c3
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x1090
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14d6
movq %rax, %rbx
movq -0x98(%rbp), %rdi
cmpq %r12, %rdi
je 0x14f4
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x1090
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x1509
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x1090
movq %rbx, %rdi
callq 0x1100