// File: MingYueRuYa[P]cprimeprimecode/memory_manager.cpp
// Function: demo06::test_overload_operator_new_and_array_new()
void test_overload_operator_new_and_array_new()
{
	cout << "\ntest_overload_operator_new_and_array_new().......\n";

	cout << "sizeof(Foo)= " << sizeof(Foo) << endl;
	{
		Foo *p = new Foo(7);
		delete p;


		Foo *pArray = new Foo[5];	//无法给array elements 以initializer
		delete []pArray;
	}

	{
		cout << "testing global expression ::new and ::new[] \n";
		//这回绕过overload new(), delete(), new[](), delete[]();
		//当然ctor，dtor都会被正常调用
		Foo *p = ::new Foo(7);
		::delete p;

		Foo *pArray = ::new Foo[5];
		::delete [] pArray;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq 0x5a86(%rip), %rdi      # 0x8fd8
movq %rdi, -0x48(%rbp)
leaq 0x2c22(%rip), %rsi      # 0x617f
callq 0x2190
movq -0x48(%rbp), %rdi
leaq 0x2c46(%rip), %rsi      # 0x61b3
callq 0x2190
movq %rax, %rdi
movl $0x30, %esi
movq %rsi, -0x40(%rbp)
callq 0x2050
movq %rax, %rdi
movq 0x5a2b(%rip), %rsi      # 0x8fb8
callq 0x21c0
movq -0x40(%rbp), %rdi
callq 0x3320
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x38(%rbp)
movl $0x7, %esi
callq 0x45b0
jmp 0x35b1
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0x35de
movq -0x50(%rbp), %rdi
callq 0x4670
movq -0x50(%rbp), %rdi
movl $0x30, %esi
callq 0x3390
movl $0xf8, %edi
callq 0x3430
movq %rax, -0x70(%rbp)
movq $0x5, (%rax)
addq $0x8, %rax
movq %rax, -0x68(%rbp)
movq %rax, %rcx
addq $0xf0, %rcx
movq %rcx, -0x60(%rbp)
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0x4710
jmp 0x361c
movq -0x60(%rbp), %rcx
movq -0x78(%rbp), %rax
addq $0x30, %rax
cmpq %rcx, %rax
movq %rax, -0x58(%rbp)
jne 0x360d
movq -0x68(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0x36c3
movq -0x80(%rbp), %rcx
movq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0x98(%rbp)
movq -0x8(%rcx), %rax
movq %rax, -0x90(%rbp)
imulq $0x30, %rax, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x88(%rbp)
je 0x36a8
movq -0x88(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0xa0(%rbp)
callq 0x4670
movq -0x80(%rbp), %rcx
movq -0xa0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x88(%rbp)
jne 0x367a
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rax
imulq $0x30, %rax, %rsi
addq $0x8, %rsi
callq 0x34a0
movq 0x590e(%rip), %rdi      # 0x8fd8
leaq 0x2af0(%rip), %rsi      # 0x61c1
callq 0x2190
movl $0x30, %edi
callq 0x21a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa8(%rbp)
movl $0x7, %esi
callq 0x45b0
jmp 0x36f9
movq -0xa8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
je 0x3732
movq -0xb0(%rbp), %rdi
callq 0x4670
movq -0xb0(%rbp), %rdi
movl $0x30, %esi
callq 0x21b0
movl $0xf8, %edi
callq 0x2030
movq %rax, -0xd0(%rbp)
movq $0x5, (%rax)
addq $0x8, %rax
movq %rax, -0xc8(%rbp)
movq %rax, %rcx
addq $0xf0, %rcx
movq %rcx, -0xc0(%rbp)
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x4710
jmp 0x3782
movq -0xc0(%rbp), %rcx
movq -0xd8(%rbp), %rax
addq $0x30, %rax
cmpq %rcx, %rax
movq %rax, -0xb8(%rbp)
jne 0x376d
movq -0xc8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xe0(%rbp)
cmpq $0x0, %rax
je 0x3842
movq -0xe0(%rbp), %rcx
movq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0xf8(%rbp)
movq -0x8(%rcx), %rax
movq %rax, -0xf0(%rbp)
imulq $0x30, %rax, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0xe8(%rbp)
je 0x3827
movq -0xe8(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x100(%rbp)
callq 0x4670
movq -0xe0(%rbp), %rcx
movq -0x100(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0xe8(%rbp)
jne 0x37f6
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rax
imulq $0x30, %rax, %rsi
addq $0x8, %rsi
callq 0x2350
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x38(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
movl $0x30, %esi
callq 0x3390
jmp 0x394e
movq -0x68(%rbp), %rcx
movq %rax, %rsi
movq -0x78(%rbp), %rax
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpq %rax, %rcx
movq %rax, -0x108(%rbp)
je 0x38b6
movq -0x108(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x110(%rbp)
callq 0x4670
movq -0x68(%rbp), %rcx
movq -0x110(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x108(%rbp)
jne 0x3888
movq -0x70(%rbp), %rdi
movl $0xf8, %esi
callq 0x34a0
jmp 0x394e
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
movl $0x30, %esi
callq 0x21b0
jmp 0x394e
movq -0xc8(%rbp), %rcx
movq %rax, %rsi
movq -0xd8(%rbp), %rax
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpq %rax, %rcx
movq %rax, -0x118(%rbp)
je 0x393d
movq -0x118(%rbp), %rdi
addq $-0x30, %rdi
movq %rdi, -0x120(%rbp)
callq 0x4670
movq -0xc8(%rbp), %rcx
movq -0x120(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x118(%rbp)
jne 0x390c
movq -0xd0(%rbp), %rdi
movl $0xf8, %esi
callq 0x2350
movq -0x10(%rbp), %rdi
callq 0x2300
nopw (%rax,%rax)