// File: /workspace/github_cpp_makefile_star2_O3/MingYueRuYa[P]cprimeprimecode/memory_manager.cpp
// Function: demo07::test_overload_placement_new()
void test_overload_placement_new()
{
	cout << "\n\n\ntest_overload_placement_new()..........\n";

	Foo start; 							//Foo:Foo
	cout << "Foo start" << endl;

	Foo *p1 = new Foo;					//op-new(size_t)
	cout << "new Foo" << endl;

	Foo *p2 = new (&start)Foo;			//op-new(size_t, void *)
	cout << "new (&start)Foo" << endl;

	Foo *p3 = new (100)Foo;				//op-new(size_t, long)
	cout << "new (100)Foo" << endl;

  	Foo *p4 = new (100, 'a')Foo;		//op-new(size_t, long, char)
	cout << "new (100, 'a')Foo" << endl;

	Foo *p5 = new (100) Foo(1);			//op-new(size_t, long) op-del(void *,long)
	cout << "new (100) Foo(1)" << endl;

	Foo *p6 = new (100, 'a') Foo(2);
	cout << "new (100, 'a') Foo(2)" << endl;

	Foo *p7 = new (&start) Foo(1);
	cout << "new (&start) Foo(1)" << endl;

	Foo *p8 = new Foo(1);
	cout << "new Foo(1)" << endl;
	//result:
		// test_overload_placement_new()..........
		// Foo:Foo()
		// Foo start
		// operator new(size_t size), size=4
		// Foo:Foo()
		// new Foo
		// operator new(size_t size, void *start), size= 4 start=0x7e95e58c
		// Foo:Foo()
		// new (&start)Foo
		// operator new(size_t size, long extra) size=4 extra:100
		// Foo:Foo()
		// new (100)Foo
		// operator new(size_t size, long extra, char init) size=4 extra= 100 init=a
		// Foo:Foo()
		// new (100, 'a')Foo
		// operator new(size_t size, long extra) size=4 extra:100
		// Foo:Foo(int)
		// new (100) Foo(1)
		// operator new(size_t size, long extra, char init) size=4 extra= 100 init=a
		// Foo:Foo(int)
		// new (100, 'a') Foo(2)
		// operator new(size_t size, void *start), size= 4 start=0x7e95e58c
		// Foo:Foo(int)
		// new (&start) Foo(1)
		// operator new(size_t size), size=4
		// Foo:Foo(int)
		// new Foo(1)
		// [notice:在4.9上当ctor爆出异常时G4.9没有调用对应的operator delete(void *, long)]
		// [但在G2.9确实是可以的]
		// terminate called after throwing an instance of 'demo07::Bad'
		// Aborted
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq 0x4c6c(%rip), %rbx      # 0x7fd0
leaq 0x1ea0(%rip), %rsi      # 0x520b
movl $0x2b, %edx
movq %rbx, %rdi
callq 0x21a0
leaq -0x14(%rbp), %rdi
callq 0x3e00
leaq 0x1eaf(%rip), %rsi      # 0x5237
movl $0x9, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl $0x4, %edi
callq 0x3e4e
movq %rax, %r14
movq %rax, %rdi
callq 0x3e00
leaq 0x1e69(%rip), %rsi      # 0x5241
movl $0x7, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leaq -0x14(%rbp), %rsi
movl $0x4, %edi
callq 0x3f10
movq %rax, %r14
movq %rax, %rdi
callq 0x3e00
leaq 0x1e1d(%rip), %rsi      # 0x5249
movl $0xf, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl $0x4, %edi
movl $0x64, %esi
callq 0x3ffc
movq %rax, %r14
movq %rax, %rdi
callq 0x3e00
leaq 0x1dd8(%rip), %rsi      # 0x5259
movl $0xc, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl $0x4, %edi
movl $0x64, %esi
movl $0x61, %edx
callq 0x40f0
movq %rax, %r14
movq %rax, %rdi
callq 0x3e00
leaq 0x1d8b(%rip), %rsi      # 0x5266
movl $0x11, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl $0x4, %edi
movl $0x64, %esi
callq 0x3ffc
movq %rax, %r14
movq %rax, %rdi
movl $0x1, %esi
callq 0x421a
leaq 0x1d43(%rip), %rsi      # 0x5278
movl $0x10, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl $0x4, %edi
movl $0x64, %esi
movl $0x61, %edx
callq 0x40f0
movq %rax, %r14
movq %rax, %rdi
movl $0x2, %esi
callq 0x421a
leaq 0x1cf5(%rip), %rsi      # 0x5289
movl $0x15, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
leaq -0x14(%rbp), %rsi
movl $0x4, %edi
callq 0x3f10
movq %rax, %r14
movq %rax, %rdi
movl $0x1, %esi
callq 0x421a
leaq 0x1cb2(%rip), %rsi      # 0x529f
movl $0x13, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl $0x4, %edi
callq 0x3e4e
movq %rax, %r14
movq %rax, %rdi
movl $0x1, %esi
callq 0x421a
leaq 0x1c71(%rip), %rsi      # 0x52b3
movl $0xa, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x36c1
jmp 0x36b0
jmp 0x3687
jmp 0x369e
movq %rax, %rbx
movl $0x64, %esi
movq %r14, %rdi
movl $0x61, %edx
callq 0x41be
jmp 0x36d1
movq %rax, %rbx
movl $0x64, %esi
movq %r14, %rdi
callq 0x4094
jmp 0x36d1
movq %rax, %rbx
leaq -0x14(%rbp), %rsi
movq %r14, %rdi
callq 0x3fa0
jmp 0x36d1
movq %rax, %rbx
movl $0x4, %esi
movq %r14, %rdi
callq 0x3eb4
movq %rbx, %rdi
callq 0x2250