// File: /workspace/github_c_makefile_star2_O3/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)
movq $0x0, 0x18(%rbx)
movabsq $0x200000001, %rax      # imm = 0x200000001
leaq -0xd0(%rbp), %rsi
movq %rax, (%rsi)
movl $0x2, %edx
movq %rbx, %rdi
callq 0xa3f8
cmpq $0x2, 0x8(%rbx)
je 0xa7a9
leaq 0x22873(%rip), %rdi     # 0x2d009
leaq 0x22a74(%rip), %rdx     # 0x2d211
movl $0xa5, %esi
xorl %eax, %eax
callq 0xcf58
movb $0x1, %r15b
leaq 0x22c01(%rip), %r12     # 0x2d3b4
leaq 0x2284f(%rip), %rbx     # 0x2d009
leaq 0x22a75(%rip), %r14     # 0x2d236
xorl %eax, %eax
movl (%r12,%rax,4), %ecx
movq -0x28(%rbp), %rdx
imulq -0x30(%rbp), %rax
cmpl (%rdx,%rax), %ecx
je 0xa7e7
movq %rbx, %rdi
movl $0xa5, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcf58
movl $0x1, %eax
testb $0x1, %r15b
movl $0x0, %r15d
jne 0xa7c3
movabsq $0x400000003, %rax      # imm = 0x400000003
leaq -0xc8(%rbp), %rsi
movq %rax, (%rsi)
xorps %xmm0, %xmm0
leaq -0xa0(%rbp), %rbx
movaps %xmm0, (%rbx)
movq $0x4, 0x10(%rbx)
movq $0x0, 0x18(%rbx)
movl $0x2, %edx
movq %rbx, %rdi
callq 0xa3f8
leaq -0x40(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa4d5
cmpq $0x4, 0x8(%r14)
je 0xa866
leaq 0x227b6(%rip), %rdi     # 0x2d009
leaq 0x229fb(%rip), %rdx     # 0x2d255
movl $0xad, %esi
xorl %eax, %eax
callq 0xcf58
leaq 0x22b53(%rip), %r15     # 0x2d3c0
leaq 0x22795(%rip), %rbx     # 0x2d009
leaq 0x22a00(%rip), %r14     # 0x2d27b
xorl %r12d, %r12d
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xa8a4
movq %rbx, %rdi
movl $0xad, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcf58
incq %r12
addq $0x4, %r15
cmpq $0x4, %r12
jne 0xa87e
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0xa8c2
callq 0xa1a0
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movabsq $0x140000000a, %rax     # imm = 0x140000000A
leaq -0xc0(%rbp), %rsi
movq %rax, (%rsi)
leaq -0x40(%rbp), %rbx
movl $0x2, %edx
movl $0x1, %ecx
movq %rbx, %rdi
callq 0xa558
cmpq $0x6, 0x8(%rbx)
je 0xa91e
leaq 0x226fe(%rip), %rdi     # 0x2d009
leaq 0x22989(%rip), %rdx     # 0x2d29b
movl $0xb3, %esi
xorl %eax, %eax
callq 0xcf58
leaq 0x22aab(%rip), %r15     # 0x2d3d0
leaq 0x226dd(%rip), %rbx     # 0x2d009
leaq 0x2298d(%rip), %r14     # 0x2d2c0
xorl %r12d, %r12d
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xa95c
movq %rbx, %rdi
movl $0xb3, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcf58
incq %r12
addq $0x4, %r15
cmpq $0x6, %r12
jne 0xa936
movabsq $0x1e00000014, %rax     # imm = 0x1E00000014
leaq -0xb8(%rbp), %rsi
movq %rax, (%rsi)
xorps %xmm0, %xmm0
leaq -0x80(%rbp), %rbx
movaps %xmm0, (%rbx)
movq $0x4, 0x10(%rbx)
movq $0x0, 0x18(%rbx)
movl $0x2, %edx
movq %rbx, %rdi
callq 0xa3f8
movq 0x8(%rbx), %rdx
movq 0x18(%rbx), %rsi
leaq -0x40(%rbp), %rbx
movl $0x4, %ecx
movq %rbx, %rdi
callq 0xa558
cmpq $0x8, 0x8(%rbx)
je 0xa9de
leaq 0x2263e(%rip), %rdi     # 0x2d009
leaq 0x2290d(%rip), %rdx     # 0x2d2df
movl $0xbb, %esi
xorl %eax, %eax
callq 0xcf58
leaq 0x22a6b(%rip), %r15     # 0x2d450
leaq 0x2261d(%rip), %rbx     # 0x2d009
leaq 0x22912(%rip), %r14     # 0x2d305
xorl %r12d, %r12d
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xaa1c
movq %rbx, %rdi
movl $0xbb, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcf58
incq %r12
addq $0x4, %r15
cmpq $0x8, %r12
jne 0xa9f6
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0xaa37
callq 0xa1a0
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movabsq $0xc800000064, %rax     # imm = 0xC800000064
leaq -0xb0(%rbp), %rsi
movq %rax, (%rsi)
leaq -0x40(%rbp), %rbx
movl $0x2, %edx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xa558
cmpq $0xa, 0x8(%rbx)
je 0xaa8a
leaq 0x22592(%rip), %rdi     # 0x2d009
leaq 0x228a7(%rip), %rdx     # 0x2d325
movl $0xc1, %esi
xorl %eax, %eax
callq 0xcf58
leaq 0x2295f(%rip), %r15     # 0x2d3f0
leaq 0x22571(%rip), %rbx     # 0x2d009
leaq 0x228ac(%rip), %r14     # 0x2d34b
xorl %r12d, %r12d
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xaac8
movq %rbx, %rdi
movl $0xc1, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcf58
incq %r12
addq $0x4, %r15
cmpq $0xa, %r12
jne 0xaaa2
movabsq $0x1900000012c, %rax    # imm = 0x1900000012C
leaq -0xa8(%rbp), %rsi
movq %rax, (%rsi)
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
movq $0x4, 0x10(%rbx)
movq $0x0, 0x18(%rbx)
movl $0x2, %edx
movq %rbx, %rdi
callq 0xa3f8
movq 0x8(%rbx), %rdx
movq 0x18(%rbx), %rsi
leaq -0x40(%rbp), %rbx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xa558
cmpq $0xc, 0x8(%rbx)
je 0xab47
leaq 0x224d5(%rip), %rdi     # 0x2d009
leaq 0x22830(%rip), %rdx     # 0x2d36b
movl $0xc9, %esi
xorl %eax, %eax
callq 0xcf58
leaq 0x228d2(%rip), %r15     # 0x2d420
leaq 0x224b4(%rip), %rbx     # 0x2d009
leaq 0x22836(%rip), %r14     # 0x2d392
xorl %r12d, %r12d
movl (%r15), %eax
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rdx
imulq %r12, %rdx
cmpl (%rcx,%rdx), %eax
je 0xab85
movq %rbx, %rdi
movl $0xc9, %esi
movq %r14, %rdx
xorl %eax, %eax
callq 0xcf58
incq %r12
addq $0x4, %r15
cmpq $0xc, %r12
jne 0xab5f
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0xaba0
callq 0xa1a0
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movq -0x28(%rbp), %rdi
testq %rdi, %rdi
je 0xabb9
callq 0xa1a0
addq $0xb0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)