// File: /workspace/github_cpp_makefile_star2_O2/iZhangHui[P]CppPrimer/CH12_DynamicMemory/examples/oknew.cc
// Function: main
int main()
{
	// if allocation fails, new returns a null pointer
	int *p1 = new int; // if allocation fails, new throws std::bad_alloc
	int *p2 = new (nothrow) int; // if allocation fails, new returns a null pointer

	int i0;                  // named, uninitialized int variable

	int *p0 = new int;       // pi points to a dynamically allocated,
	                         // unnamed, uninitialized int
	delete p0;  // frees the memory to which pi points

	// named initialized variables
	int i(1024);             // value of i is 1024
	string s(10, '9');       // value of s is "9999999999"
	vector<int> v = {0,1,2,3,4,5,6,7,8,9};

	// unnamed, initialized dynamically allocated objects
	int *pi = new int(1024); // object to which pi points has value 1024
	string *ps = new string(10, '9');   // *ps is "9999999999"
	// vector with ten elements with values from 0 to 9
	vector<int> *pv = new vector<int>{0,1,2,3,4,5,6,7,8,9};

	cout << "*pi: " << *pi
	     << "\ti: " << i << endl
	     << "*ps: " << *ps
	     << "\ts: " << s << endl;

	for (auto b = pv->begin(); b != pv->end(); ++b)
		cout << *b << " ";
	cout << endl;

	// when we're done using the memory must delete the pointers
	delete pi;  // frees the memory to which pi points
	delete ps;  // frees the string to which ps points
	            // the string destructor frees the space used by its data
	delete pv;  // frees the memory for the vector
	            // which also destroys the elements in that vector

	// call get_size to determine how many ints to allocate
	int *pia = new int[get_size()]; // pia points to the first of these ints
	delete [] pia; // brackets used to delete pointer to element in an array
	typedef int arrT[42];  // arrT names the type array of 42 ints
	int *p = new arrT;     // allocates an array of 42 ints; p points to the first one
	delete [] p;           // brackets are necessary because we allocated an array

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0x50(%rbp), %rdi
pushq $0xa
popq %rbx
pushq $0x39
popq %rdx
movq %rbx, %rsi
callq 0x10f0
movups 0xd56(%rip), %xmm0      # 0x2014
leaq -0x90(%rbp), %rsi
movaps %xmm0, 0x10(%rsi)
movups 0xd34(%rip), %xmm0      # 0x2004
movaps %xmm0, (%rsi)
movabsq $0x900000008, %r15      # imm = 0x900000008
movq %r15, 0x20(%rsi)
leaq -0x68(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movq %rbx, %rdx
callq 0x1496
pushq $0x20
popq %rdi
callq 0x10d0
movq %rax, %rbx
addq $0x10, %rax
movq %rax, (%rbx)
pushq $0xa
popq %rsi
pushq $0x39
popq %rdx
movq %rbx, %rdi
callq 0x10f0
pushq $0x18
popq %rdi
callq 0x10d0
movq %rax, %r14
leaq -0x90(%rbp), %rsi
movups 0xcea(%rip), %xmm0      # 0x2014
movaps %xmm0, 0x10(%rsi)
movups 0xccf(%rip), %xmm0      # 0x2004
movaps %xmm0, (%rsi)
movq %r15, 0x20(%rsi)
pushq $0xa
popq %rdx
leaq -0x29(%rbp), %rcx
movq %rax, %rdi
callq 0x1496
movq 0x2c86(%rip), %rdi      # 0x3fd8
leaq 0xcd3(%rip), %rsi       # 0x202c
callq 0x10c0
movq %rax, %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x1120
leaq 0xcc0(%rip), %rsi       # 0x2032
movq %rax, %rdi
callq 0x10c0
movq %rax, %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x1120
movq %rax, %rdi
callq 0x1070
leaq 0xca1(%rip), %rsi       # 0x2037
movq %rax, %rdi
callq 0x10c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x10b0
leaq 0xc8d(%rip), %rsi       # 0x203d
movq %rax, %rdi
callq 0x10c0
leaq -0x50(%rbp), %rsi
movq %rax, %rdi
callq 0x10b0
movq %rax, %rdi
callq 0x1070
movq (%r14), %r13
movq 0x2c02(%rip), %r15      # 0x3fd8
leaq 0xc58(%rip), %r12       # 0x2035
cmpq 0x8(%r14), %r13
je 0x1400
movl (%r13), %esi
movq %r15, %rdi
callq 0x1120
movq %rax, %rdi
movq %r12, %rsi
callq 0x10c0
addq $0x4, %r13
jmp 0x13dd
movq 0x2bd1(%rip), %rdi      # 0x3fd8
callq 0x1070
movq %rbx, %rdi
callq 0x1060
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x10e0
movq %r14, %rdi
callq 0x1536
pushq $0x18
popq %rsi
movq %r14, %rdi
callq 0x10e0
leaq -0x68(%rbp), %rdi
callq 0x1536
leaq -0x50(%rbp), %rdi
callq 0x1060
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
pushq $0x18
popq %rsi
movq %r14, %rdi
jmp 0x1469
movq %rax, %r15
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x10e0
jmp 0x147c
jmp 0x1479
movq %rax, %r15
jmp 0x1485
jmp 0x1479
movq %rax, %r15
leaq -0x68(%rbp), %rdi
callq 0x1536
leaq -0x50(%rbp), %rdi
callq 0x1060
movq %r15, %rdi
callq 0x1130