// File: /workspace/github_cpp_makefile_star2_O3/iZhangHui[P]CppPrimer/CH12_DynamicMemory/examples/release.cc
// Function: main
int main()
{
	unique_ptr<string> p1(new string("Stegosaurus"));

	// transfers ownership from p1
	// (which points to the string Stegosaurus) to p2
	unique_ptr<string> p2(p1.release()); // release makes p1 null
	cout << *p2 << endl; // prints Stegosaurus

	unique_ptr<string> p3(new string("Trex"));

	// reset deletes the memory to which p2 had pointed
	// and transfers ownership from p3 to p2
	p2.reset(p3.release());
	cout << *p2 << endl; // prints Trex

	// p1 is null, p2 is steg, and p3 is trex
	if (p1)
		cout << "p1 not null?" << endl;
	if (p3)
		cout << "p2 not null?" << endl;
	cout << *p2 << endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movl $0x20, %edi
callq 0x1090
movq %rax, %r14
addq $0x10, %rax
movq %rax, (%r14)
leaq 0xdb2(%rip), %rsi       # 0x2004
leaq 0xdb6(%rip), %rdx       # 0x200f
movq %r14, %rdi
callq 0x14be
movq $0x0, -0x28(%rbp)
movq %r14, -0x18(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x2d5d(%rip), %rdi      # 0x3fd8
callq 0x10b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1080
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1040
movl $0x20, %edi
callq 0x1090
movq %rax, %r14
addq $0x10, %rax
movq %rax, (%r14)
leaq 0xd4b(%rip), %rsi       # 0x2010
leaq 0xd48(%rip), %rdx       # 0x2014
movq %r14, %rdi
callq 0x14be
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rsi
movq %r14, -0x18(%rbp)
testq %rsi, %rsi
je 0x12f8
leaq -0x18(%rbp), %rbx
movq %rbx, %rdi
callq 0x155c
movq (%rbx), %r14
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x2cd2(%rip), %rdi      # 0x3fd8
callq 0x10b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1080
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1040
cmpq $0x0, -0x28(%rbp)
je 0x1382
movq 0x2c95(%rip), %rbx      # 0x3fd8
leaq 0xccb(%rip), %rsi       # 0x2015
movl $0xc, %edx
movq %rbx, %rdi
callq 0x10b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1080
movsbl %al, %esi
movq 0x2c63(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1040
cmpq $0x0, -0x20(%rbp)
je 0x13cf
movq 0x2c48(%rip), %rbx      # 0x3fd8
leaq 0xc8b(%rip), %rsi       # 0x2022
movl $0xc, %edx
movq %rbx, %rdi
callq 0x10b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1080
movsbl %al, %esi
movq 0x2c16(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1040
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x2bf7(%rip), %rdi      # 0x3fd8
callq 0x10b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1080
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1040
movq -0x20(%rbp), %rsi
testq %rsi, %rsi
je 0x1422
leaq -0x20(%rbp), %rdi
callq 0x155c
movq -0x18(%rbp), %rsi
testq %rsi, %rsi
je 0x1434
leaq -0x18(%rbp), %rdi
callq 0x155c
movq -0x28(%rbp), %rsi
testq %rsi, %rsi
je 0x1446
leaq -0x28(%rbp), %rdi
callq 0x155c
xorl %eax, %eax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
callq 0x10a0
jmp 0x1491
jmp 0x1477
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
callq 0x10a0
jmp 0x14b5
movq %rax, %rbx
jmp 0x1491
movq %rax, %rbx
movq -0x20(%rbp), %rsi
testq %rsi, %rsi
je 0x1491
leaq -0x20(%rbp), %rdi
callq 0x155c
movq -0x18(%rbp), %rsi
testq %rsi, %rsi
je 0x14a3
leaq -0x18(%rbp), %rdi
callq 0x155c
movq -0x28(%rbp), %rsi
testq %rsi, %rsi
je 0x14b5
leaq -0x28(%rbp), %rdi
callq 0x155c
movq %rbx, %rdi
callq 0x10d0
nop