// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x70, %rsp
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
andl $0x0, 0x10(%rax)
andq $0x0, 0x18(%rax)
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
andl $0x0, 0x10(%rax)
andq $0x0, 0x18(%rax)
andq $0x0, -0x18(%rbp)
movq 0x2d53(%rip), %rdi      # 0x3fd8
leaq -0x50(%rbp), %rsi
callq 0x10b0
leaq -0x30(%rbp), %rsi
movq %rax, %rdi
callq 0x10e0
leaq -0x18(%rbp), %rsi
movq %rax, %rdi
callq 0x1060
movl -0x30(%rbp), %eax
cvtsi2sd %rax, %xmm0
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movq 0x2d19(%rip), %rdi      # 0x3fd8
leaq -0x80(%rbp), %rsi
callq 0x10b0
leaq -0x60(%rbp), %rsi
movq %rax, %rdi
callq 0x10e0
leaq -0x18(%rbp), %rsi
movq %rax, %rdi
callq 0x1060
leaq -0x80(%rbp), %rsi
movl 0x20(%rsi), %eax
cvtsi2sd %rax, %xmm0
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, 0x28(%rsi)
leaq -0x50(%rbp), %rdi
callq 0x1410
testb %al, %al
je 0x1397
movl -0x60(%rbp), %r14d
leaq -0x50(%rbp), %rsi
addl 0x20(%rsi), %r14d
movsd 0x28(%rsi), %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movq 0x2c9f(%rip), %rdi      # 0x3fc8
callq 0x1090
leaq 0xccf(%rip), %rsi       # 0x2004
movq %rax, %rdi
callq 0x10a0
movl %r14d, %ebx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1070
leaq 0xcb2(%rip), %rsi       # 0x2004
movq %rax, %rdi
callq 0x10a0
movq %rax, %rdi
movsd -0x20(%rbp), %xmm0
callq 0x10d0
leaq 0xc96(%rip), %rsi       # 0x2004
movq %rax, %rdi
callq 0x10a0
testl %r14d, %r14d
je 0x13b7
cvtsi2sd %rbx, %xmm1
movsd -0x20(%rbp), %xmm0
divsd %xmm1, %xmm0
movq 0x2c38(%rip), %rdi      # 0x3fc8
callq 0x10d0
jmp 0x13ca
movq 0x2c52(%rip), %rdi      # 0x3ff0
leaq 0xc6c(%rip), %rsi       # 0x2011
callq 0x10a0
movq %rax, %rdi
callq 0x1050
pushq $-0x1
popq %rbx
jmp 0x13d4
movq 0x2c0a(%rip), %rdi      # 0x3fc8
leaq 0xc41(%rip), %rsi       # 0x2006
callq 0x10a0
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x1050
leaq -0x80(%rbp), %rdi
callq 0x1040
leaq -0x50(%rbp), %rdi
callq 0x1040
movl %ebx, %eax
addq $0x70, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x13f3
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x1040
leaq -0x50(%rbp), %rdi
callq 0x1040
movq %rbx, %rdi
callq 0x10f0