// File: iZhangHui[P]CppPrimer/CH02_VariablesAndBasicTypes/examples/decl-ex.cc
// Function: main
int main()
{
	int a = 0;
	decltype(a) c = a;   // c is an int
	decltype((a)) d = a; // d is a reference to a
	++c;                 // increments c, a (and d) unchanged
	cout << "a: " << a << " c: " << c << " d: " << d << endl;
	++d;                 // increments a through the reference d
	cout << "a: " << a << " c: " << c << " d: " << d << endl;
	
	int A = 0, B = 0;
	decltype((A)) C = A;   // C is a reference to A
	decltype(A = B) D = A; // D is also a reference to A
	++C;
	cout << "A: " << A << " C: " << C << " D: " << D << endl;
	++D;
	cout << "A: " << A << " C: " << C << " D: " << D << endl;
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0xc(%rbp)
leaq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
movq 0x2de4(%rip), %rdi      # 0x3fd8
leaq 0xe09(%rip), %rsi       # 0x2004
callq 0x1040
movq %rax, %rdi
movl -0x8(%rbp), %esi
callq 0x1070
movq %rax, %rdi
leaq 0xdf3(%rip), %rsi       # 0x2008
callq 0x1040
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x1070
movq %rax, %rdi
leaq 0xdde(%rip), %rsi       # 0x200d
callq 0x1040
movq %rax, %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
callq 0x1070
movq %rax, %rdi
movq 0x2d7c(%rip), %rsi      # 0x3fc8
callq 0x1050
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq 0x2d75(%rip), %rdi      # 0x3fd8
leaq 0xd9a(%rip), %rsi       # 0x2004
callq 0x1040
movq %rax, %rdi
movl -0x8(%rbp), %esi
callq 0x1070
movq %rax, %rdi
leaq 0xd84(%rip), %rsi       # 0x2008
callq 0x1040
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x1070
movq %rax, %rdi
leaq 0xd6f(%rip), %rsi       # 0x200d
callq 0x1040
movq %rax, %rdi
movq -0x18(%rbp), %rax
movl (%rax), %esi
callq 0x1070
movq %rax, %rdi
movq 0x2d0d(%rip), %rsi      # 0x3fc8
callq 0x1050
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
leaq -0x1c(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq -0x1c(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq 0x2ce8(%rip), %rdi      # 0x3fd8
leaq 0xd1b(%rip), %rsi       # 0x2012
callq 0x1040
movq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x1070
movq %rax, %rdi
leaq 0xd05(%rip), %rsi       # 0x2016
callq 0x1040
movq %rax, %rdi
movq -0x28(%rbp), %rax
movl (%rax), %esi
callq 0x1070
movq %rax, %rdi
leaq 0xced(%rip), %rsi       # 0x201b
callq 0x1040
movq %rax, %rdi
movq -0x30(%rbp), %rax
movl (%rax), %esi
callq 0x1070
movq %rax, %rdi
movq 0x2c7d(%rip), %rsi      # 0x3fc8
callq 0x1050
movq -0x30(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq 0x2c76(%rip), %rdi      # 0x3fd8
leaq 0xca9(%rip), %rsi       # 0x2012
callq 0x1040
movq %rax, %rdi
movl -0x1c(%rbp), %esi
callq 0x1070
movq %rax, %rdi
leaq 0xc93(%rip), %rsi       # 0x2016
callq 0x1040
movq %rax, %rdi
movq -0x28(%rbp), %rax
movl (%rax), %esi
callq 0x1070
movq %rax, %rdi
leaq 0xc7b(%rip), %rsi       # 0x201b
callq 0x1040
movq %rax, %rdi
movq -0x30(%rbp), %rax
movl (%rax), %esi
callq 0x1070
movq %rax, %rdi
movq 0x2c0b(%rip), %rsi      # 0x3fc8
callq 0x1050
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq