// File: /workspace/github_c_makefile_star2_O2/theck01[P]offbrand_lib/src/tests/obvector_test.c
// Function: main
int main(){

  uint32_t i, id;
  obtest *tests[6], *singleton, *tmp;
  obvector *main_vec, *copy_vec;

  main_vec = obvector_new(1);
  singleton = obtest_new(7);

  for(i=0; i<6; i++){
    tests[i] = obtest_new(i);
    obvector_store_at_index(main_vec, (obj *)tests[i], i);

    if(ob_reference_count((obj *)tests[i]) != 2){
      fprintf(stderr, "obvector_test: vector did not properly ob_retain element "
                      "TEST FAILED\n");
      exit(1);
    }

    ob_release((obj *)tests[i]); /* vector should maintain only references */
  }

  if(obvector_length(main_vec) != 6){
    fprintf(stderr, "obvector_test: vector size is off, TEST FAILED\n");
    exit(1);
  }

  for(i=0; i<6; i++){
    if(obtest_id((obtest *)obvector_obj_at_index(main_vec,i)) != i){
      fprintf(stderr, "obvector_test: vector does not contain added contents "
                      "in expected order\nTEST FAILED\n");
      printf("%d\n", i);
      exit(1);
    }
  }

  obvector_store_at_index(main_vec, (obj *)singleton, 12);
  if(obvector_length(main_vec) != 13){
    fprintf(stderr, "obvector_test: store did not properly extend length "
                    "TEST FAILED\n");
    exit(1);
  }


  obvector_store_at_index(main_vec, NULL, 12);
  if(obvector_length(main_vec) != 6){
    fprintf(stderr, "obvector_test: remove did not properly get rid of element "
                    "TEST FAILED\n");
    exit(1);
  }

  if(ob_reference_count((obj *)singleton) != 1){
    fprintf(stderr, "obvector_test: vector did not ob_release element on removal "
                    "TEST FAILED\n");
    exit(1);
  }

  tmp = (obtest *)obvector_obj_at_index(main_vec, 3);
  ob_retain((obj *)tmp);

  obvector_store_at_index(main_vec, (obj *)singleton, 3);
  if(ob_reference_count((obj *)tmp) != 1){
    fprintf(stderr, "obvector_test: vector did not ob_release element on "
                    "replacement, TEST FAILED\n");
    exit(1);
  }

  if(obvector_length(main_vec) != 6 ||
     obtest_id((obtest *)obvector_obj_at_index(main_vec, 3)) !=
     obtest_id(singleton)){
    fprintf(stderr, "obvector_test: element was not added properly to vector "
                    "at index\nTEST FAILED\n");
    exit(1);
  }

  obvector_store_at_index(main_vec, (obj *)tmp, 3);

  /* reduce reference count to 1, so only vector holds reference to obj */
  ob_release((obj *)tmp);

  if(obvector_find_obj(main_vec, (obj *)singleton)){
    fprintf(stderr, "obvector_test: vector did not replace element correctly, "
                    "or was not found\nTEST FAILED\n");
    exit(1);
  }

  obvector_store_at_index(main_vec, (obj *)singleton, 10);
  if(obvector_length(main_vec) != 11){
    fprintf(stderr, "obvector_test: store did not properly extend length "
                    "TEST FAILED\n");
    exit(1);
  }

  obvector_sort(main_vec, OB_LEAST_TO_GREATEST);
  if(obvector_length(main_vec) != 7){
    fprintf(stderr, "obvector_test: sort did not properly remove NULLs "
                    "TEST FAILED\n");
    fprintf(stderr, "obvector_test: vector size == %d\n",
                    obvector_length(main_vec));
    for(i=0; i<obvector_length(main_vec); i++){
      if(obvector_obj_at_index(main_vec, i)) printf("object\n");
      else printf("NULL\n");
    }
    exit(1);
  }

  id = 0;
  for(i=0; i<obvector_length(main_vec); i++){
    if(id > obtest_id((obtest *)obvector_obj_at_index(main_vec, i))){
      fprintf(stderr, "obvector_test: vector was not sorted least to "
                      "greatest, TEST FAILED\n");
      exit(1);
    }
    id = obtest_id((obtest *)obvector_obj_at_index(main_vec, i));
  }

  obvector_store_at_index(main_vec, NULL, 6);
  obvector_store_at_index(main_vec, (obj *)singleton, 10);

  obvector_sort(main_vec, OB_GREATEST_TO_LEAST);
  if(obvector_length(main_vec) != 7){
    fprintf(stderr, "obvector_test: second sort did not properly remove NULLs "
                    "TEST FAILED\n");
    exit(1);
  }

  id = 10;
  for(i=0; i<obvector_length(main_vec); i++){
    if(id < obtest_id((obtest *)obvector_obj_at_index(main_vec, i))){
      fprintf(stderr, "obvector_test: vector was not sorted greatest to "
                      "least, TEST FAILED\n");
      exit(1);
    }
    id = obtest_id((obtest *)obvector_obj_at_index(main_vec, i));
  }

  copy_vec = obvector_copy(main_vec);

  assert(ob_compare((obj *)copy_vec, (obj *)main_vec) == OB_EQUAL_TO);
  assert(ob_hash((obj *)copy_vec) == ob_hash((obj *)main_vec));

  ob_release((obj *)singleton); /* ob_release singleton once so it is only referenced
                                by containing vectors */

  for(i=0; i<obvector_length(main_vec); i++){
    if(ob_reference_count((obj *)(obtest *)obvector_obj_at_index(main_vec, i)) != 2){
      fprintf(stderr, "obvector_test: vector contents not ob_retained on copy, "
                      "TEST FAILED\n");
      exit(1);
    }
  }

  /* get obj at index and ob_retain it so it isnt deallocated */
  tmp = (obtest *)obvector_obj_at_index(main_vec, 3);
  ob_retain((obj *)tmp);

  obvector_store_at_index(main_vec, NULL, 3);

  assert(ob_compare((obj *)copy_vec, (obj *)main_vec) == OB_NOT_EQUAL);
  assert(ob_hash((obj *)copy_vec) != ob_hash((obj *)main_vec));

  if(obvector_find_obj(main_vec, (obj *)tmp)){
    fprintf(stderr, "obvector_test: Item was not removed properly from vector"
                    "index, TEST FAILED\n");
    exit(1);
  }

  obvector_store_at_index(main_vec, (obj *)tmp, 3);
  assert(obvector_length(main_vec) == 7);
  obvector_concat(main_vec, copy_vec);
  assert(obvector_length(main_vec) == 14);

  for(i=0; i<obvector_length(main_vec)/2; i++){
    if(obtest_id((obtest *)obvector_obj_at_index(main_vec,i)) !=
       obtest_id((obtest *)obvector_obj_at_index(main_vec,i+7))){
      fprintf(stderr, "obvector_test: Copy of vector not appended properly, "
                      "TEST FAILED\n");
      exit(1);
    }
  }

  ob_release((obj *)main_vec);
  ob_release((obj *)copy_vec);

  if(ob_reference_count((obj *)tmp) != 1){
    fprintf(stderr, "obvector_test: ob_releases of obvector container did not "
                    "properly manage\ncontained obtest reference count, TEST "
                    "FAILED\n");
    exit(1);
  }

  ob_release((obj *)tmp);

  printf("obvector: TESTS PASSED\n");
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq $0x1
popq %rdi
callq 0x1ae0
movq %rax, %rbx
pushq $0x7
popq %rdi
callq 0x18d4
movq %rax, %r14
xorl %r15d, %r15d
cmpq $0x6, %r15
je 0x125a
movl %r15d, %edi
callq 0x18d4
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x1c55
movq %r12, %rdi
callq 0x27d0
cmpl $0x2, %eax
jne 0x16c0
movq %r12, %rdi
callq 0x2766
incq %r15
jmp 0x121d
movq %rbx, %rdi
callq 0x1c2e
cmpl $0x6, %eax
jne 0x1763
xorl %r15d, %r15d
cmpq $0x6, %r15
je 0x1297
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1e06
movq %rax, %rdi
callq 0x1ab7
movl %eax, %eax
cmpq %rax, %r15
jne 0x16d5
incq %r15
jmp 0x126e
pushq $0xc
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1c55
movq %rbx, %rdi
callq 0x1c2e
cmpl $0xd, %eax
jne 0x174e
pushq $0xc
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1c55
movq %rbx, %rdi
callq 0x1c2e
cmpl $0x6, %eax
jne 0x1778
movq %r14, %rdi
callq 0x27d0
cmpl $0x1, %eax
jne 0x178d
pushq $0x3
popq %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1e06
movq %rax, %r15
movq %rax, %rdi
callq 0x279b
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x1c55
movq %r15, %rdi
callq 0x27d0
cmpl $0x1, %eax
jne 0x17a2
movq %rbx, %rdi
callq 0x1c2e
cmpl $0x6, %eax
jne 0x173b
pushq $0x3
popq %rsi
movq %rbx, %rdi
callq 0x1e06
movq %rax, %rdi
callq 0x1ab7
movl %eax, %ebp
movq %r14, %rdi
callq 0x1ab7
cmpl %eax, %ebp
jne 0x173b
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1c55
movq %r15, %rdi
callq 0x2766
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f3f
testb %al, %al
jne 0x17ba
pushq $0xa
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1c55
movq %rbx, %rdi
callq 0x1c2e
cmpl $0xb, %eax
jne 0x174e
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x1fb9
movq %rbx, %rdi
callq 0x1c2e
cmpl $0x7, %eax
jne 0x1643
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x1c2e
movl %eax, %eax
cmpq %rax, %r15
jae 0x1401
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1e06
movq %rax, %rdi
callq 0x1ab7
cmpl %eax, %ebp
ja 0x1704
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1e06
movq %rax, %rdi
callq 0x1ab7
movl %eax, %ebp
incq %r15
jmp 0x13bd
pushq $0x6
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1c55
pushq $0xa
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1c55
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x1fb9
movq %rbx, %rdi
callq 0x1c2e
cmpl $0x7, %eax
jne 0x17d2
pushq $0xa
popq %rbp
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x1c2e
movl %eax, %eax
movq %rbx, %rdi
cmpq %rax, %r15
jae 0x1482
movq %r15, %rsi
callq 0x1e06
movq %rax, %rdi
callq 0x1ab7
cmpl %eax, %ebp
jb 0x1717
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1e06
movq %rax, %rdi
callq 0x1ab7
movl %eax, %ebp
incq %r15
jmp 0x143e
callq 0x1bbc
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x26af
testb %al, %al
jne 0x17e8
movq %r15, %rdi
callq 0x2676
movq %rax, %r12
movq %rbx, %rdi
callq 0x2676
cmpq %rax, %r12
jne 0x1807
movq %r14, %rdi
callq 0x2766
xorl %r14d, %r14d
movq %rbx, %rdi
callq 0x1c2e
movl %eax, %eax
cmpq %rax, %r14
jae 0x1504
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1e06
movq %rax, %rdi
callq 0x27d0
incq %r14
cmpl $0x2, %eax
je 0x14c4
movq 0x4b03(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1f5b(%rip), %rdi      # 0x345a
jmp 0x1728
pushq $0x3
popq %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1e06
movq %rax, %r14
movq %rax, %rdi
callq 0x279b
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x1c55
movq %r15, %rdi
movq %rbx, %rsi
callq 0x26af
cmpb $0x2, %al
jne 0x1826
movq %r15, %rdi
callq 0x2676
movq %rax, %r12
movq %rbx, %rdi
callq 0x2676
cmpq %rax, %r12
je 0x1845
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f3f
testb %al, %al
jne 0x1864
pushq $0x3
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1c55
movq %rbx, %rdi
callq 0x1c2e
cmpl $0x7, %eax
jne 0x187c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1e8a
movq %rbx, %rdi
callq 0x1c2e
cmpl $0xe, %eax
jne 0x189b
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x1c2e
shrl %eax
cmpq %rax, %r12
jae 0x1603
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1e06
movq %rax, %rdi
callq 0x1ab7
movl %eax, %ebp
leaq 0x7(%r12), %rsi
movq %rbx, %rdi
callq 0x1e06
movq %rax, %rdi
callq 0x1ab7
incq %r12
cmpl %eax, %ebp
je 0x15ab
movq 0x4a06(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1fa0(%rip), %rdi      # 0x359c
pushq $0x41
jmp 0x172a
movq %rbx, %rdi
callq 0x2766
movq %r15, %rdi
callq 0x2766
movq %r14, %rdi
callq 0x27d0
cmpl $0x1, %eax
jne 0x18ba
movq %r14, %rdi
callq 0x2766
leaq 0x2023(%rip), %rdi      # 0x3656
callq 0x1040
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x49ae(%rip), %r14      # 0x5ff8
movq (%r14), %rcx
leaq 0x1c3f(%rip), %rdi      # 0x3293
pushq $0x3e
popq %rsi
pushq $0x1
popq %rdx
callq 0x10e0
movq (%r14), %r15
movq %rbx, %rdi
callq 0x1c2e
leaq 0x1c61(%rip), %rsi      # 0x32d2
xorl %r14d, %r14d
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x10a0
leaq 0x270e(%rip), %r15      # 0x3d95
leaq 0x1fdf(%rip), %r12      # 0x366d
movq %rbx, %rdi
callq 0x1c2e
movl %eax, %eax
cmpq %rax, %r14
jae 0x1733
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1e06
testq %rax, %rax
movq %r12, %rdi
cmoveq %r15, %rdi
callq 0x1040
incq %r14
jmp 0x168e
movq 0x4931(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1933(%rip), %rdi      # 0x3004
pushq $0x45
jmp 0x172a
movq 0x491c(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1994(%rip), %rdi      # 0x307a
pushq $0x54
popq %rsi
pushq $0x1
popq %rdx
callq 0x10e0
leaq 0x1bf8(%rip), %rdi      # 0x32f0
movl %r15d, %esi
xorl %eax, %eax
callq 0x1050
jmp 0x1733
movq 0x48ed(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1bdf(%rip), %rdi      # 0x32f4
jmp 0x1728
movq 0x48da(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1c57(%rip), %rdi      # 0x337f
pushq $0x44
popq %rsi
pushq $0x1
popq %rdx
callq 0x10e0
pushq $0x1
popq %rdi
callq 0x10d0
movq 0x48b6(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1aa2(%rip), %rdi      # 0x31ee
jmp 0x17b3
movq 0x48a3(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1970(%rip), %rdi      # 0x30cf
pushq $0x40
jmp 0x172a
movq 0x488e(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x18d6(%rip), %rdi      # 0x304a
pushq $0x2f
jmp 0x172a
movq 0x4879(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1987(%rip), %rdi      # 0x3110
pushq $0x46
jmp 0x172a
movq 0x4864(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x19b9(%rip), %rdi      # 0x3157
pushq $0x48
jmp 0x172a
movq 0x484f(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x19ed(%rip), %rdi      # 0x31a0
pushq $0x4d
jmp 0x172a
movq 0x4837(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1a71(%rip), %rdi      # 0x323c
pushq $0x56
jmp 0x172a
movq 0x481f(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1b56(%rip), %rdi      # 0x3339
jmp 0x16d1
leaq 0x1bd5(%rip), %rdi      # 0x33c4
leaq 0x1c0a(%rip), %rsi      # 0x3400
leaq 0x1c1d(%rip), %rcx      # 0x341a
movl $0x98, %edx
callq 0x1060
leaq 0x1c17(%rip), %rdi      # 0x3425
leaq 0x1beb(%rip), %rsi      # 0x3400
leaq 0x1bfe(%rip), %rcx      # 0x341a
movl $0x99, %edx
callq 0x1060
leaq 0x1c72(%rip), %rdi      # 0x349f
leaq 0x1bcc(%rip), %rsi      # 0x3400
leaq 0x1bdf(%rip), %rcx      # 0x341a
movl $0xac, %edx
callq 0x1060
leaq 0x1c90(%rip), %rdi      # 0x34dc
leaq 0x1bad(%rip), %rsi      # 0x3400
leaq 0x1bc0(%rip), %rcx      # 0x341a
movl $0xad, %edx
callq 0x1060
movq 0x478d(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1c9c(%rip), %rdi      # 0x3511
pushq $0x4b
jmp 0x172a
leaq 0x1cda(%rip), %rdi      # 0x355d
leaq 0x1b76(%rip), %rsi      # 0x3400
leaq 0x1b89(%rip), %rcx      # 0x341a
movl $0xb6, %edx
callq 0x1060
leaq 0x1cda(%rip), %rdi      # 0x357c
leaq 0x1b57(%rip), %rsi      # 0x3400
leaq 0x1b6a(%rip), %rcx      # 0x341a
movl $0xb8, %edx
callq 0x1060
movq 0x4737(%rip), %rax      # 0x5ff8
movq (%rax), %rcx
leaq 0x1d13(%rip), %rdi      # 0x35de
pushq $0x77
jmp 0x172a
nop