// File: iZhangHui[P]CppPrimer/CH19_SpecializedToolsAndTechniques/examples/dyn_cast.cc
// Function: exercises()
void exercises() {
	A *pa = new C;
    if (B *pb = dynamic_cast< B* >(pa))
         cout << "cast from C to B* ok" << endl;
    else
         cout << "cast from C to B* not ok" << endl;
	B *pb = new B;
    if (C *pc = dynamic_cast< C* >(pb))
         cout << "cast from B to C* ok" << endl;
    else
         cout << "cast from B to C* not ok" << endl;

	A *pc = new C;
    if (B *pb = dynamic_cast< B* >(pc))
         cout << "cast C to B* ok" << endl;
    else
         cout << "cast C to B* not ok" << endl;

	A *pd = new D;
    if (B *pb = dynamic_cast< B* >(pd))
         cout << "cast D to B* ok" << endl;
    else
         cout << "cast D to B* not ok" << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movl $0x8, %edi
callq 0x2070
movq %rax, %rdi
movq %rdi, -0x50(%rbp)
callq 0x2780
movq -0x50(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0x48(%rbp)
je 0x2290
movq -0x50(%rbp), %rax
movq (%rax), %rcx
addq -0x20(%rcx), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x22ca
movq -0x58(%rbp), %rdi
leaq 0x289f(%rip), %rsi      # 0x4b50
leaq 0x28a8(%rip), %rdx      # 0x4b60
movq $-0x1, %rcx
callq 0x20a0
movq %rax, -0x60(%rbp)
jmp 0x22d2
xorl %eax, %eax
movq %rax, -0x60(%rbp)
jmp 0x22d2
movq -0x60(%rbp), %rax
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x2305
movq 0x2cf0(%rip), %rdi      # 0x4fd8
leaq 0xd1b(%rip), %rsi       # 0x300a
callq 0x2060
movq %rax, %rdi
movq 0x2cba(%rip), %rsi      # 0x4fb8
callq 0x2090
jmp 0x2327
movq 0x2ccc(%rip), %rdi      # 0x4fd8
leaq 0xd0c(%rip), %rsi       # 0x301f
callq 0x2060
movq %rax, %rdi
movq 0x2c96(%rip), %rsi      # 0x4fb8
callq 0x2090
movl $0x8, %edi
callq 0x2070
movq %rax, %rdi
movq %rdi, -0x70(%rbp)
callq 0x27e0
movq -0x70(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x2374
movq -0x68(%rbp), %rdi
leaq 0x2802(%rip), %rsi      # 0x4b60
leaq 0x2823(%rip), %rdx      # 0x4b88
xorl %eax, %eax
movl %eax, %ecx
callq 0x20a0
movq %rax, -0x78(%rbp)
jmp 0x237c
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x237c
movq -0x78(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x23af
movq 0x2c46(%rip), %rdi      # 0x4fd8
leaq 0xc9f(%rip), %rsi       # 0x3038
callq 0x2060
movq %rax, %rdi
movq 0x2c10(%rip), %rsi      # 0x4fb8
callq 0x2090
jmp 0x23d1
movq 0x2c22(%rip), %rdi      # 0x4fd8
leaq 0xc90(%rip), %rsi       # 0x304d
callq 0x2060
movq %rax, %rdi
movq 0x2bec(%rip), %rsi      # 0x4fb8
callq 0x2090
movl $0x8, %edi
callq 0x2070
movq %rax, %rdi
movq %rdi, -0x88(%rbp)
callq 0x2780
movq -0x88(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0x80(%rbp)
je 0x240f
movq -0x88(%rbp), %rax
movq (%rax), %rcx
addq -0x20(%rcx), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, %rax
je 0x2452
movq -0x90(%rbp), %rdi
leaq 0x271a(%rip), %rsi      # 0x4b50
leaq 0x2723(%rip), %rdx      # 0x4b60
movq $-0x1, %rcx
callq 0x20a0
movq %rax, -0x98(%rbp)
jmp 0x245d
xorl %eax, %eax
movq %rax, -0x98(%rbp)
jmp 0x245d
movq -0x98(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2493
movq 0x2b62(%rip), %rdi      # 0x4fd8
leaq 0xbe9(%rip), %rsi       # 0x3066
callq 0x2060
movq %rax, %rdi
movq 0x2b2c(%rip), %rsi      # 0x4fb8
callq 0x2090
jmp 0x24b5
movq 0x2b3e(%rip), %rdi      # 0x4fd8
leaq 0xbd5(%rip), %rsi       # 0x3076
callq 0x2060
movq %rax, %rdi
movq 0x2b08(%rip), %rsi      # 0x4fb8
callq 0x2090
movl $0x8, %edi
callq 0x2070
movq %rax, %rdi
movq %rdi, -0xa8(%rbp)
callq 0x2820
movq -0xa8(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movq %rax, -0xa0(%rbp)
je 0x24f9
movq -0xa8(%rbp), %rax
movq (%rax), %rcx
addq -0x20(%rcx), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
je 0x253f
movq -0xb0(%rbp), %rdi
leaq 0x262d(%rip), %rsi      # 0x4b50
leaq 0x2636(%rip), %rdx      # 0x4b60
movq $-0x1, %rcx
callq 0x20a0
movq %rax, -0xb8(%rbp)
jmp 0x254a
xorl %eax, %eax
movq %rax, -0xb8(%rbp)
jmp 0x254a
movq -0xb8(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x2580
movq 0x2a75(%rip), %rdi      # 0x4fd8
leaq 0xb20(%rip), %rsi       # 0x308a
callq 0x2060
movq %rax, %rdi
movq 0x2a3f(%rip), %rsi      # 0x4fb8
callq 0x2090
jmp 0x25a2
movq 0x2a51(%rip), %rdi      # 0x4fd8
leaq 0xb0c(%rip), %rsi       # 0x309a
callq 0x2060
movq %rax, %rdi
movq 0x2a1b(%rip), %rsi      # 0x4fb8
callq 0x2090
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax,%rax)