// File: /workspace/github_cpp_makefile_star2_O2/t0mm4rx[P]piscine_cpp/day07/ex02/main.cpp
// Function: main
int main(void)
{
	std::cout << "Test copy with int array." << std::endl;
	Array<int> *arr = new Array<int>(5);
	for (unsigned int i = 0; i < arr->size(); i++)
		(*arr)[i] = i * 2;
	Array<int> copy = *arr;
	(*arr)[0] = 42;
	(*arr)[1] = -54;
	std::cout << "Length: " << copy.size() << std::endl;
	for (unsigned int i = 0; i < copy.size(); i++)
		std::cout << copy[i] << std::endl;
	delete arr;
	std::cout << "Test initializing int array." << std::endl;
	Array<int> *arr2 = new Array<int>(5);
	std::cout << "Length: " << arr2->size() << std::endl;
	for (unsigned int i = 0; i < arr2->size(); i++)
		std::cout << (*arr2)[i] << std::endl;
	try
	{
		std::cout << (*arr2)[5] << std::endl;
	}
	catch (std::exception &e)
	{
		std::cout << "Exception while reading arr2[5]." << std::endl;
	}
	delete arr2;
	std::cout << "Test empty array." << std::endl;
	Array<std::string> *arr3 = new Array<std::string>();
	std::cout << "Length: " << arr3->size() << std::endl;
	try
	{
		std::cout << (*arr3)[4] << std::endl;
	}
	catch (std::exception &e)
	{
		std::cout << "Exception while reading arr3[4]." << std::endl;
	}
	try
	{
		std::cout << (*arr3)[-1] << std::endl;
	}
	catch (std::exception &e)
	{
		std::cout << "Exception while reading arr3[-1]." << std::endl;
	}
	delete arr3;
	return (0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq 0x2d06(%rip), %rdi      # 0x3fc8
leaq 0xd3b(%rip), %rsi       # 0x2004
callq 0x10d0
movq %rax, %rdi
callq 0x1070
pushq $0x10
popq %rdi
callq 0x10e0
movq %rax, %rbx
pushq $0x5
popq %rsi
movq %rax, %rdi
callq 0x1646
xorl %r15d, %r15d
xorl %r14d, %r14d
cmpl 0x8(%rbx), %r14d
jae 0x130f
movq %rbx, %rdi
movl %r14d, %esi
callq 0x1686
movl %r15d, (%rax)
incl %r14d
addl $0x2, %r15d
jmp 0x12f2
leaq -0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x16ce
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1686
movl $0x2a, (%rax)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1686
movl $0xffffffca, (%rax)     # imm = 0xFFFFFFCA
movq 0x2c85(%rip), %rdi      # 0x3fc8
leaq 0xcd4(%rip), %rsi       # 0x201e
callq 0x10d0
movl -0x28(%rbp), %esi
movq %rax, %rdi
callq 0x10a0
movq %rax, %rdi
callq 0x1070
xorl %r14d, %r14d
leaq -0x30(%rbp), %r15
movq 0x2c58(%rip), %r12      # 0x3fc8
cmpl -0x28(%rbp), %r14d
jae 0x1398
movq %r15, %rdi
movl %r14d, %esi
callq 0x1686
movl (%rax), %esi
movq %r12, %rdi
callq 0x1140
movq %rax, %rdi
callq 0x1070
incl %r14d
jmp 0x1370
movq %rbx, %rdi
callq 0x16e0
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x10f0
movq 0x2c16(%rip), %rdi      # 0x3fc8
leaq 0xc6e(%rip), %rsi       # 0x2027
callq 0x10d0
movq %rax, %rdi
callq 0x1070
pushq $0x10
popq %rdi
callq 0x10e0
movq %rax, %rbx
pushq $0x5
popq %rsi
movq %rax, %rdi
callq 0x1646
movq 0x2be5(%rip), %rdi      # 0x3fc8
leaq 0xc34(%rip), %rsi       # 0x201e
callq 0x10d0
movl 0x8(%rbx), %esi
movq %rax, %rdi
callq 0x10a0
movq %rax, %rdi
callq 0x1070
xorl %r14d, %r14d
movq 0x2bbc(%rip), %r15      # 0x3fc8
cmpl 0x8(%rbx), %r14d
jae 0x1434
movq %rbx, %rdi
movl %r14d, %esi
callq 0x1686
movl (%rax), %esi
movq %r15, %rdi
callq 0x1140
movq %rax, %rdi
callq 0x1070
incl %r14d
jmp 0x140c
pushq $0x5
popq %rsi
movq %rbx, %rdi
callq 0x1686
movl (%rax), %esi
movq 0x2b80(%rip), %rdi      # 0x3fc8
callq 0x1140
movq %rax, %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x16e0
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x10f0
movq 0x2b59(%rip), %rdi      # 0x3fc8
leaq 0xbef(%rip), %rsi       # 0x2065
callq 0x10d0
movq %rax, %rdi
callq 0x1070
pushq $0x10
popq %rdi
callq 0x10e0
movq %rax, %rbx
andq $0x0, (%rax)
andl $0x0, 0x8(%rax)
movq 0x2b2b(%rip), %rdi      # 0x3fc8
leaq 0xb7a(%rip), %rsi       # 0x201e
callq 0x10d0
movq %rax, %rdi
xorl %esi, %esi
callq 0x10a0
movq %rax, %rdi
callq 0x1070
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x1702
movq 0x2afb(%rip), %rdi      # 0x3fc8
movq %rax, %rsi
callq 0x10c0
movq %rax, %rdi
callq 0x1070
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x1702
movq 0x2ad9(%rip), %rdi      # 0x3fc8
movq %rax, %rsi
callq 0x10c0
movq %rax, %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x174e
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x10f0
leaq -0x30(%rbp), %rdi
callq 0x16e0
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x10f0
jmp 0x1634
movq %rax, %r14
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x10f0
jmp 0x163d
movq %rax, %r14
cmpl $0x1, %edx
jne 0x1634
movq %r14, %rdi
callq 0x1050
movq 0x2a5d(%rip), %rdi      # 0x3fc8
leaq 0xb26(%rip), %rsi       # 0x2098
callq 0x10d0
movq %rax, %rdi
callq 0x1070
callq 0x1120
jmp 0x14ff
jmp 0x1631
movq %rax, %r14
callq 0x1120
jmp 0x1634
movq %rax, %r14
cmpl $0x1, %edx
jne 0x1634
movq %r14, %rdi
callq 0x1050
movq 0x2a12(%rip), %rdi      # 0x3fc8
leaq 0xaba(%rip), %rsi       # 0x2077
callq 0x10d0
movq %rax, %rdi
callq 0x1070
callq 0x1120
jmp 0x14dd
jmp 0x1631
movq %rax, %r14
callq 0x1120
jmp 0x1634
movq %rax, %r14
cmpl $0x1, %edx
jne 0x1634
movq %r14, %rdi
callq 0x1050
movq 0x29d1(%rip), %rdi      # 0x3fc8
leaq 0xa46(%rip), %rsi       # 0x2044
callq 0x10d0
movq %rax, %rdi
callq 0x1070
callq 0x1120
jmp 0x1455
jmp 0x1631
movq %rax, %r14
callq 0x1120
jmp 0x1634
movq %rax, %rdi
callq 0x16f4
jmp 0x1631
jmp 0x1631
jmp 0x1631
jmp 0x1631
movq %rax, %r14
leaq -0x30(%rbp), %rdi
callq 0x16e0
movq %r14, %rdi
callq 0x1150
nop