// File: 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
subq $0x180, %rsp            # imm = 0x180
movl $0x0, -0x4(%rbp)
movq 0x2cff(%rip), %rdi      # 0x3fc8
leaq 0xd34(%rip), %rsi       # 0x2004
callq 0x10b0
movq %rax, %rdi
movq 0x2cd1(%rip), %rsi      # 0x3fb0
callq 0x10e0
movl $0x10, %edi
callq 0x10c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
movl $0x5, %esi
callq 0x1a10
jmp 0x1304
movq -0x70(%rbp), %rax
movq %rax, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1a80
movl %eax, %ecx
movl -0x74(%rbp), %eax
cmpl %ecx, %eax
jae 0x136e
movl -0x20(%rbp), %eax
shll %eax
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x1aa0
movl -0x78(%rbp), %ecx
movl %ecx, (%rax)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1313
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x10, %esi
callq 0x10d0
jmp 0x19f1
movq -0x10(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x1b20
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x1aa0
movq %rax, -0x80(%rbp)
jmp 0x138c
movq -0x80(%rbp), %rax
movl $0x2a, (%rax)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x1aa0
movq %rax, -0x88(%rbp)
jmp 0x13ad
movq -0x88(%rbp), %rax
movl $0xffffffca, (%rax)     # imm = 0xFFFFFFCA
movq 0x2c07(%rip), %rdi      # 0x3fc8
leaq 0xc56(%rip), %rsi       # 0x201e
callq 0x10b0
movq %rax, -0x90(%rbp)
jmp 0x13d6
leaq -0x30(%rbp), %rdi
callq 0x1a80
movl %eax, -0x94(%rbp)
jmp 0x13e7
movl -0x94(%rbp), %esi
movq -0x90(%rbp), %rdi
callq 0x1100
movq %rax, -0xa0(%rbp)
jmp 0x1402
movq -0xa0(%rbp), %rdi
movq 0x2ba0(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x1417
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0xa8(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1a80
movl %eax, -0xa4(%rbp)
jmp 0x1438
movl -0xa8(%rbp), %eax
movl -0xa4(%rbp), %ecx
cmpl %ecx, %eax
jae 0x14ae
movl -0x34(%rbp), %esi
leaq -0x30(%rbp), %rdi
callq 0x1aa0
movq %rax, -0xb0(%rbp)
jmp 0x145d
movq -0xb0(%rbp), %rax
movl (%rax), %esi
movq 0x2b5b(%rip), %rdi      # 0x3fc8
callq 0x1140
movq %rax, -0xb8(%rbp)
jmp 0x147b
movq -0xb8(%rbp), %rdi
movq 0x2b27(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x1490
jmp 0x1492
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x141e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x19e8
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x14dc
movq -0xc0(%rbp), %rdi
callq 0x1b60
movq -0xc0(%rbp), %rdi
movl $0x10, %esi
callq 0x10d0
movq 0x2ae5(%rip), %rdi      # 0x3fc8
leaq 0xb3d(%rip), %rsi       # 0x2027
callq 0x10b0
movq %rax, -0xc8(%rbp)
jmp 0x14f8
movq -0xc8(%rbp), %rdi
movq 0x2aaa(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x150d
movl $0x10, %edi
callq 0x10c0
movq %rax, -0xd0(%rbp)
jmp 0x1520
movq -0xd0(%rbp), %rdi
movl $0x5, %esi
callq 0x1a10
jmp 0x1533
movq -0xd0(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x2a83(%rip), %rdi      # 0x3fc8
leaq 0xad2(%rip), %rsi       # 0x201e
callq 0x10b0
movq %rax, -0xd8(%rbp)
jmp 0x155a
movq -0x40(%rbp), %rdi
callq 0x1a80
movl %eax, -0xdc(%rbp)
jmp 0x156b
movl -0xdc(%rbp), %esi
movq -0xd8(%rbp), %rdi
callq 0x1100
movq %rax, -0xe8(%rbp)
jmp 0x1586
movq -0xe8(%rbp), %rdi
movq 0x2a1c(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x159b
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0xf0(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1a80
movl %eax, -0xec(%rbp)
jmp 0x15bc
movl -0xf0(%rbp), %eax
movl -0xec(%rbp), %ecx
cmpl %ecx, %eax
jae 0x1643
movq -0x40(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x1aa0
movq %rax, -0xf8(%rbp)
jmp 0x15e1
movq -0xf8(%rbp), %rax
movl (%rax), %esi
movq 0x29d7(%rip), %rdi      # 0x3fc8
callq 0x1140
movq %rax, -0x100(%rbp)
jmp 0x15ff
movq -0x100(%rbp), %rdi
movq 0x29a3(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x1614
jmp 0x1616
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x15a2
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x10, %esi
callq 0x10d0
jmp 0x19e8
movq -0x40(%rbp), %rdi
movl $0x5, %esi
callq 0x1aa0
movq %rax, -0x108(%rbp)
jmp 0x165a
movq -0x108(%rbp), %rax
movl (%rax), %esi
movq 0x295e(%rip), %rdi      # 0x3fc8
callq 0x1140
movq %rax, -0x110(%rbp)
jmp 0x1678
movq -0x110(%rbp), %rdi
movq 0x292a(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x168d
jmp 0x16f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x19e8
movq -0x18(%rbp), %rdi
callq 0x1050
movq %rax, -0x50(%rbp)
movq 0x2909(%rip), %rdi      # 0x3fc8
leaq 0x97e(%rip), %rsi       # 0x2044
callq 0x10b0
movq %rax, -0x118(%rbp)
jmp 0x16d4
movq -0x118(%rbp), %rdi
movq 0x28ce(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x16e9
callq 0x1120
jmp 0x16f0
jmp 0x16f2
movq -0x40(%rbp), %rax
movq %rax, -0x120(%rbp)
cmpq $0x0, %rax
je 0x1720
movq -0x120(%rbp), %rdi
callq 0x1b60
movq -0x120(%rbp), %rdi
movl $0x10, %esi
callq 0x10d0
movq 0x28a1(%rip), %rdi      # 0x3fc8
leaq 0x937(%rip), %rsi       # 0x2065
callq 0x10b0
movq %rax, -0x128(%rbp)
jmp 0x173c
movq -0x128(%rbp), %rdi
movq 0x2866(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x1751
movl $0x10, %edi
callq 0x10c0
movq %rax, -0x130(%rbp)
jmp 0x1764
movq -0x130(%rbp), %rdi
callq 0x1bb0
jmp 0x1772
movq -0x130(%rbp), %rax
movq %rax, -0x58(%rbp)
movq 0x2844(%rip), %rdi      # 0x3fc8
leaq 0x893(%rip), %rsi       # 0x201e
callq 0x10b0
movq %rax, -0x138(%rbp)
jmp 0x1799
movq -0x58(%rbp), %rdi
callq 0x1bd0
movl %eax, -0x13c(%rbp)
jmp 0x17aa
movl -0x13c(%rbp), %esi
movq -0x138(%rbp), %rdi
callq 0x1100
movq %rax, -0x148(%rbp)
jmp 0x17c5
movq -0x148(%rbp), %rdi
movq 0x27dd(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x17da
movq -0x58(%rbp), %rdi
movl $0x4, %esi
callq 0x1bf0
movq %rax, -0x150(%rbp)
jmp 0x17f1
movq -0x150(%rbp), %rsi
movq 0x27c9(%rip), %rdi      # 0x3fc8
callq 0x10a0
movq %rax, -0x158(%rbp)
jmp 0x180d
movq -0x158(%rbp), %rdi
movq 0x2795(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x1822
jmp 0x18c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x1120
jmp 0x183a
jmp 0x19e8
movq -0x130(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x10, %esi
callq 0x10d0
jmp 0x19e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x19e8
movq -0x18(%rbp), %rdi
callq 0x1050
movq %rax, -0x60(%rbp)
movq 0x2737(%rip), %rdi      # 0x3fc8
leaq 0x7df(%rip), %rsi       # 0x2077
callq 0x10b0
movq %rax, -0x160(%rbp)
jmp 0x18a6
movq -0x160(%rbp), %rdi
movq 0x26fc(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x18bb
callq 0x1120
jmp 0x18c2
jmp 0x18c4
movq -0x58(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x1bf0
movq %rax, -0x168(%rbp)
jmp 0x18db
movq -0x168(%rbp), %rsi
movq 0x26df(%rip), %rdi      # 0x3fc8
callq 0x10a0
movq %rax, -0x170(%rbp)
jmp 0x18f7
movq -0x170(%rbp), %rdi
movq 0x26ab(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x190c
jmp 0x1989
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x1120
jmp 0x1921
jmp 0x19e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x19e8
movq -0x18(%rbp), %rdi
callq 0x1050
movq %rax, -0x68(%rbp)
movq 0x2672(%rip), %rdi      # 0x3fc8
leaq 0x73b(%rip), %rsi       # 0x2098
callq 0x10b0
movq %rax, -0x178(%rbp)
jmp 0x196b
movq -0x178(%rbp), %rdi
movq 0x2637(%rip), %rsi      # 0x3fb0
callq 0x10e0
jmp 0x1980
callq 0x1120
jmp 0x1987
jmp 0x1989
movq -0x58(%rbp), %rax
movq %rax, -0x180(%rbp)
cmpq $0x0, %rax
je 0x19b7
movq -0x180(%rbp), %rdi
callq 0x1c70
movq -0x180(%rbp), %rdi
movl $0x10, %esi
callq 0x10d0
movl $0x0, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1b60
movl -0x4(%rbp), %eax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x1120
jmp 0x19e6
jmp 0x19e8
leaq -0x30(%rbp), %rdi
callq 0x1b60
movq -0x18(%rbp), %rdi
callq 0x1150
movq %rax, %rdi
callq 0x1ba0
nopw %cs:(%rax,%rax)
nopl (%rax)