// File: /workspace/github_cpp_makefile_star2_O1/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 0x14d0
movq %r14, -0x20(%rbp)
movq $0x0, -0x20(%rbp)
movq %r14, -0x18(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x2d59(%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 0xd47(%rip), %rsi       # 0x2010
leaq 0xd44(%rip), %rdx       # 0x2014
movq %r14, %rdi
callq 0x14d0
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rsi
movq %r14, -0x18(%rbp)
testq %rsi, %rsi
je 0x12f6
leaq -0x18(%rbp), %rdi
callq 0x156a
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x2cd0(%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, -0x20(%rbp)
je 0x1384
movq 0x2c93(%rip), %rbx      # 0x3fd8
leaq 0xcc9(%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 0x2c61(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1040
cmpq $0x0, -0x28(%rbp)
je 0x13d1
movq 0x2c46(%rip), %rbx      # 0x3fd8
leaq 0xc89(%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 0x2c14(%rip), %rdi      # 0x3fd8
callq 0x1030
movq %rax, %rdi
callq 0x1040
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x2bf5(%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 -0x28(%rbp), %rsi
testq %rsi, %rsi
je 0x1424
leaq -0x28(%rbp), %rdi
callq 0x156a
movq -0x18(%rbp), %rsi
testq %rsi, %rsi
je 0x1436
leaq -0x18(%rbp), %rdi
callq 0x156a
movq -0x20(%rbp), %rsi
testq %rsi, %rsi
je 0x1448
leaq -0x20(%rbp), %rdi
callq 0x156a
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 0x149b
jmp 0x1479
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
callq 0x10a0
jmp 0x14c7
movq %rax, %rbx
jmp 0x149b
movq %rax, %rbx
movq -0x28(%rbp), %rsi
testq %rsi, %rsi
je 0x1493
leaq -0x28(%rbp), %rdi
callq 0x156a
movq $0x0, -0x28(%rbp)
movq -0x18(%rbp), %rsi
testq %rsi, %rsi
je 0x14ad
leaq -0x18(%rbp), %rdi
callq 0x156a
movq -0x20(%rbp), %rsi
testq %rsi, %rsi
je 0x14bf
leaq -0x20(%rbp), %rdi
callq 0x156a
movq $0x0, -0x20(%rbp)
movq %rbx, %rdi
callq 0x10d0
nop