// File: /workspace/github_c_makefile_star2_O2/Ihsoh[P]ilang/array.c
// Function: rarr_test
void rarr_test(void) {
	ResizableArray rarr1;

	rarr_init(&rarr1, sizeof(int));
	MYASSERT(
		rarr1.size == 0 && rarr1.len == 0 && rarr1.item_size == sizeof(int) && rarr1.buffer == NULL,
		"TEST rarr_init(...)"
	);

	#define	__CMP_RARR_ARR(rarr, arr, msg)	{	\
		int __temp[] = arr;	\
		if ((rarr)->len != sizeof(__temp) / sizeof(int)) {	\
			MYASSERT(0, (msg "xxxxxx"));	\
		}	\
		for (int __i = 0; __i < sizeof(__temp) / sizeof(int); __i++) {	\
			if (__temp[__i] != RARR_ELEMENT((rarr), __i, int)) {	\
				MYASSERT(0, (msg));	\
			}	\
		}	\
	}
	#define	__C	,

	// [] + [1, 2] => [1, 2]
	int arr1[] = {1, 2};
	rarr_append_with_raw(&rarr1, arr1, sizeof(arr1) / sizeof(int));
	__CMP_RARR_ARR(&rarr1, {1 __C 2}, "TEST rarr_append_with_raw(...)");

	// [1, 2] + [3, 4] => [1, 2, 3, 4]
	int arr2[] = {3, 4};
	ResizableArray rarr2;
	rarr_init(&rarr2, sizeof(int));
	rarr_append_with_raw(&rarr2, arr2, sizeof(arr2) / sizeof(int));
	rarr_append_with_rarr(&rarr1, &rarr2);
	__CMP_RARR_ARR(&rarr1, {1 __C 2 __C 3 __C 4}, "TEST rarr_append_with_rarr(...)");
	rarr_free(&rarr2);

	// INSERT([1, 2, 3, 4], 1, [10, 20]) => [1, 10, 20, 2, 3, 4]
	int arr3[] = {10, 20};
	rarr_insert_with_raw(&rarr1, arr3, sizeof(arr3) / sizeof(int), 1);
	__CMP_RARR_ARR(&rarr1, {1 __C 10 __C 20 __C 2 __C 3 __C 4}, "TEST rarr_insert_with_raw(...)");

	// INSERT([1, 10, 20, 2, 3, 4], 4, [20, 30]) => [1, 10, 20, 2, 20, 30, 3, 4]
	int arr4[] = {20, 30};
	ResizableArray rarr3;
	rarr_init(&rarr3, sizeof(int));
	rarr_append_with_raw(&rarr3, arr4, sizeof(arr4) / sizeof(int));
	rarr_insert_with_rarr(&rarr1, &rarr3, 4);
	__CMP_RARR_ARR(&rarr1, {1 __C 10 __C 20 __C 2 __C 20 __C 30 __C 3 __C 4}, "TEST rarr_insert_with_rarr(...)");
	rarr_free(&rarr3);

	// [100, 200] + [1, 10, 20, 2, 20, 30, 3, 4] => [100, 200, 1, 10, 20, 2, 20, 30, 3, 4]
	int arr5[] = {100, 200};
	rarr_prepend_with_raw(&rarr1, arr5, sizeof(arr5) / sizeof(int));
	__CMP_RARR_ARR(&rarr1, {100 __C 200 __C 1 __C 10 __C 20 __C 2 __C 20 __C 30 __C 3 __C 4}, "TEST rarr_prepend_with_raw(...)");

	// [300, 400] + [100, 200, 1, 10, 20, 2, 20, 30, 3, 4] => [300, 400, 100, 200, 1, 10, 20, 2, 20, 30, 3, 4]
	int arr6[] = {300, 400};
	ResizableArray rarr4;
	rarr_init(&rarr4, sizeof(int));
	rarr_append_with_raw(&rarr4, arr6, sizeof(arr6) / sizeof(int));
	rarr_prepend_with_rarr(&rarr1, &rarr4);
	__CMP_RARR_ARR(&rarr1, {300 __C 400 __C 100 __C 200 __C 1 __C 10 __C 20 __C 2 __C 20 __C 30 __C 3 __C 4}, "TEST rarr_prepend_with_rarr(...)");
	rarr_free(&rarr4);

	rarr_free(&rarr1);

	#undef	__CMP_RARR_ARR
	#undef	__COMMA
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xb0, %rsp
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rbx
movaps %xmm0, (%rbx)
movq $0x4, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
movabsq $0x200000001, %rax      # imm = 0x200000001
leaq -0x70(%rbp), %rsi
movq %rax, (%rsi)
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xa326
cmpq $0x2, 0x8(%rbx)
je 0xa699
leaq 0x21983(%rip), %rdi     # 0x2c009
leaq 0x21b84(%rip), %rdx     # 0x2c211
movl $0xa5, %esi
xorl %eax, %eax
callq 0xcb84
leaq 0x21d14(%rip), %r15     # 0x2c3b4
leaq 0x21962(%rip), %rbx     # 0x2c009
leaq 0x21b88(%rip), %r14     # 0x2c236
xorl %r12d, %r12d
cmpq $0x2, %r12
je 0xa6e6
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xa6dd
movq %rbx, %rdi
movl $0xa5, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcb84
incq %r12
addq $0x4, %r15
jmp 0xa6b1
movabsq $0x400000003, %rax      # imm = 0x400000003
leaq -0x68(%rbp), %rsi
movq %rax, (%rsi)
xorps %xmm0, %xmm0
leaq -0xd0(%rbp), %rbx
movaps %xmm0, (%rbx)
movq $0x4, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xa326
leaq -0x40(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa3fb
cmpq $0x4, 0x8(%r14)
je 0xa74c
leaq 0x218d0(%rip), %rdi     # 0x2c009
leaq 0x21b15(%rip), %rdx     # 0x2c255
movl $0xad, %esi
xorl %eax, %eax
callq 0xcb84
leaq 0x21c6d(%rip), %r15     # 0x2c3c0
leaq 0x218af(%rip), %rbx     # 0x2c009
leaq 0x21b1a(%rip), %r14     # 0x2c27b
xorl %r12d, %r12d
cmpq $0x4, %r12
je 0xa799
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xa790
movq %rbx, %rdi
movl $0xad, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcb84
incq %r12
addq $0x4, %r15
jmp 0xa764
leaq -0xd0(%rbp), %rdi
callq 0xa2e1
movabsq $0x140000000a, %rax     # imm = 0x140000000A
leaq -0x60(%rbp), %rsi
movq %rax, (%rsi)
leaq -0x40(%rbp), %rbx
pushq $0x2
popq %rdx
pushq $0x1
popq %rcx
movq %rbx, %rdi
callq 0xa470
cmpq $0x6, 0x8(%rbx)
je 0xa7e9
leaq 0x21833(%rip), %rdi     # 0x2c009
leaq 0x21abe(%rip), %rdx     # 0x2c29b
movl $0xb3, %esi
xorl %eax, %eax
callq 0xcb84
leaq 0x21be0(%rip), %r15     # 0x2c3d0
leaq 0x21812(%rip), %rbx     # 0x2c009
leaq 0x21ac2(%rip), %r14     # 0x2c2c0
xorl %r12d, %r12d
cmpq $0x6, %r12
je 0xa836
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xa82d
movq %rbx, %rdi
movl $0xb3, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcb84
incq %r12
addq $0x4, %r15
jmp 0xa801
movabsq $0x1e00000014, %rax     # imm = 0x1E00000014
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
xorps %xmm0, %xmm0
leaq -0xb0(%rbp), %rbx
movaps %xmm0, (%rbx)
movq $0x4, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xa326
leaq -0x40(%rbp), %r14
pushq $0x4
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa53e
cmpq $0x8, 0x8(%r14)
je 0xa89f
leaq 0x2177d(%rip), %rdi     # 0x2c009
leaq 0x21a4c(%rip), %rdx     # 0x2c2df
movl $0xbb, %esi
xorl %eax, %eax
callq 0xcb84
leaq 0x21baa(%rip), %r15     # 0x2c450
leaq 0x2175c(%rip), %rbx     # 0x2c009
leaq 0x21a51(%rip), %r14     # 0x2c305
xorl %r12d, %r12d
cmpq $0x8, %r12
je 0xa8ec
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xa8e3
movq %rbx, %rdi
movl $0xbb, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcb84
incq %r12
addq $0x4, %r15
jmp 0xa8b7
leaq -0xb0(%rbp), %rdi
callq 0xa2e1
movabsq $0xc800000064, %rax     # imm = 0xC800000064
leaq -0x50(%rbp), %rsi
movq %rax, (%rsi)
leaq -0x40(%rbp), %rbx
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xa593
cmpq $0xa, 0x8(%rbx)
je 0xa939
leaq 0x216e3(%rip), %rdi     # 0x2c009
leaq 0x219f8(%rip), %rdx     # 0x2c325
movl $0xc1, %esi
xorl %eax, %eax
callq 0xcb84
leaq 0x21ab0(%rip), %r15     # 0x2c3f0
leaq 0x216c2(%rip), %rbx     # 0x2c009
leaq 0x219fd(%rip), %r14     # 0x2c34b
xorl %r12d, %r12d
cmpq $0xa, %r12
je 0xa986
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xa97d
movq %rbx, %rdi
movl $0xc1, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcb84
incq %r12
addq $0x4, %r15
jmp 0xa951
movabsq $0x1900000012c, %rax    # imm = 0x1900000012C
leaq -0x48(%rbp), %rsi
movq %rax, (%rsi)
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rbx
movaps %xmm0, (%rbx)
movq $0x4, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0xa326
leaq -0x40(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa5df
cmpq $0xc, 0x8(%r14)
je 0xa9ec
leaq 0x21630(%rip), %rdi     # 0x2c009
leaq 0x2198b(%rip), %rdx     # 0x2c36b
movl $0xc9, %esi
xorl %eax, %eax
callq 0xcb84
leaq 0x21a2d(%rip), %r15     # 0x2c420
leaq 0x2160f(%rip), %rbx     # 0x2c009
leaq 0x21991(%rip), %r14     # 0x2c392
xorl %r12d, %r12d
cmpq $0xc, %r12
je 0xaa39
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xaa30
movq %rbx, %rdi
movl $0xc9, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcb84
incq %r12
addq $0x4, %r15
jmp 0xaa04
leaq -0x90(%rbp), %rdi
callq 0xa2e1
leaq -0x40(%rbp), %rdi
callq 0xa2e1
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop