// File: /workspace/github_c_makefile_star2_O3/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
movl $0x1, %edi
callq 0x1dc0
movq %rax, %rbx
movl $0x7, %edi
callq 0x1b9c
movq %rax, %r14
xorl %r15d, %r15d
movl %r15d, %edi
callq 0x1b9c
movq %rax, %r12
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x1f49
movq %r12, %rdi
callq 0x2b76
cmpl $0x2, %eax
jne 0x1a82
movq %r12, %rdi
callq 0x2b0a
incq %r15
cmpq $0x6, %r15
jne 0x1641
movq %rbx, %rdi
callq 0x1f20
cmpl $0x6, %eax
jne 0x1aa8
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21bf
movq %rax, %rdi
callq 0x1d97
movl %eax, %eax
cmpq %rax, %r15
jne 0x1a87
incq %r15
cmpq $0x6, %r15
jne 0x1690
movl $0xc, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f49
movq %rbx, %rdi
callq 0x1f20
cmpl $0xd, %eax
jne 0x1aad
movl $0xc, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1f49
movq %rbx, %rdi
callq 0x1f20
cmpl $0x6, %eax
jne 0x1ab2
movq %r14, %rdi
callq 0x2b76
cmpl $0x1, %eax
jne 0x1ab7
movl $0x3, %esi
movq %rbx, %rdi
callq 0x21bf
movq %rax, %r15
movq %rax, %rdi
callq 0x2b3f
movl $0x3, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f49
movq %r15, %rdi
callq 0x2b76
cmpl $0x1, %eax
jne 0x1abc
movq %rbx, %rdi
callq 0x1f20
cmpl $0x6, %eax
jne 0x1aa3
movl $0x3, %esi
movq %rbx, %rdi
callq 0x21bf
movq %rax, %rdi
callq 0x1d97
movl %eax, %ebp
movq %r14, %rdi
callq 0x1d97
cmpl %eax, %ebp
jne 0x1aa3
movl $0x3, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1f49
movq %r15, %rdi
callq 0x2b0a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x232e
testb %al, %al
jne 0x1ac1
movl $0xa, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f49
movq %rbx, %rdi
callq 0x1f20
cmpl $0xb, %eax
jne 0x1ac6
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x23b6
movq %rbx, %rdi
callq 0x1f20
cmpl $0x7, %eax
jne 0x1acb
movq %rbx, %rdi
callq 0x1f20
testl %eax, %eax
je 0x1837
xorl %r15d, %r15d
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21bf
movq %rax, %rdi
callq 0x1d97
cmpl %eax, %ebp
ja 0x1a8f
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21bf
movq %rax, %rdi
callq 0x1d97
movl %eax, %ebp
incq %r15
movq %rbx, %rdi
callq 0x1f20
movl %eax, %eax
cmpq %rax, %r15
jb 0x17f5
movl $0x6, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1f49
movl $0xa, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f49
movq %rbx, %rdi
movl $0x1, %esi
callq 0x23b6
movq %rbx, %rdi
callq 0x1f20
cmpl $0x7, %eax
jne 0x1ad3
movq %rbx, %rdi
callq 0x1f20
testl %eax, %eax
je 0x18ca
movl $0xa, %ebp
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21bf
movq %rax, %rdi
callq 0x1d97
cmpl %eax, %ebp
jb 0x1a94
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21bf
movq %rax, %rdi
callq 0x1d97
movl %eax, %ebp
incq %r15
movq %rbx, %rdi
callq 0x1f20
movl %eax, %eax
cmpq %rax, %r15
jb 0x1888
movq %rbx, %rdi
callq 0x1ea8
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2a87
testb %al, %al
jne 0x1ad8
movq %r15, %rdi
callq 0x2a48
movq %rax, %r12
movq %rbx, %rdi
callq 0x2a48
cmpq %rax, %r12
jne 0x1af7
movq %r14, %rdi
callq 0x2b0a
movq %rbx, %rdi
callq 0x1f20
testl %eax, %eax
je 0x1949
xorl %r14d, %r14d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21bf
movq %rax, %rdi
callq 0x2b76
cmpl $0x2, %eax
jne 0x1a99
incq %r14
movq %rbx, %rdi
callq 0x1f20
movl %eax, %eax
cmpq %rax, %r14
jb 0x191b
movl $0x3, %esi
movq %rbx, %rdi
callq 0x21bf
movq %rax, %r14
movq %rax, %rdi
callq 0x2b3f
movl $0x3, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1f49
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2a87
cmpb $0x2, %al
jne 0x1b16
movq %r15, %rdi
callq 0x2a48
movq %rax, %r12
movq %rbx, %rdi
callq 0x2a48
cmpq %rax, %r12
je 0x1b35
movq %rbx, %rdi
movq %r14, %rsi
callq 0x232e
testb %al, %al
jne 0x1b54
movl $0x3, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f49
movq %rbx, %rdi
callq 0x1f20
cmpl $0x7, %eax
jne 0x1b59
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2251
movq %rbx, %rdi
callq 0x1f20
cmpl $0xe, %eax
jne 0x1b78
movq %rbx, %rdi
callq 0x1f20
cmpl $0x2, %eax
jb 0x1a42
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x21bf
movq %rax, %rdi
callq 0x1d97
movl %eax, %ebp
addq $0x7, %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x21bf
movq %rax, %rdi
callq 0x1d97
cmpl %eax, %ebp
jne 0x1a9e
movq %rbx, %rdi
callq 0x1f20
shrl %eax
addq $-0x6, %r12
cmpq %rax, %r12
jb 0x19ff
movq %rbx, %rdi
callq 0x2b0a
movq %r15, %rdi
callq 0x2b0a
movq %r14, %rdi
callq 0x2b76
cmpl $0x1, %eax
jne 0x1b97
movq %r14, %rdi
callq 0x2b0a
leaq 0x1be4(%rip), %rdi      # 0x3656
callq 0x1040
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x1110
movq %r15, %rdi
callq 0x115a
callq 0x132b
callq 0x1375
callq 0x139a
callq 0x13e4
callq 0x1226
callq 0x1135
callq 0x1192
callq 0x11b7
callq 0x11dc
callq 0x1201
callq 0x124b
callq 0x1270
movq %rbx, %rdi
callq 0x1295
callq 0x1350
leaq 0x18e5(%rip), %rdi      # 0x33c4
leaq 0x191a(%rip), %rsi      # 0x3400
leaq 0x192d(%rip), %rcx      # 0x341a
movl $0x98, %edx
callq 0x1060
leaq 0x1927(%rip), %rdi      # 0x3425
leaq 0x18fb(%rip), %rsi      # 0x3400
leaq 0x190e(%rip), %rcx      # 0x341a
movl $0x99, %edx
callq 0x1060
leaq 0x1982(%rip), %rdi      # 0x349f
leaq 0x18dc(%rip), %rsi      # 0x3400
leaq 0x18ef(%rip), %rcx      # 0x341a
movl $0xac, %edx
callq 0x1060
leaq 0x19a0(%rip), %rdi      # 0x34dc
leaq 0x18bd(%rip), %rsi      # 0x3400
leaq 0x18d0(%rip), %rcx      # 0x341a
movl $0xad, %edx
callq 0x1060
callq 0x13bf
leaq 0x19fd(%rip), %rdi      # 0x355d
leaq 0x1899(%rip), %rsi      # 0x3400
leaq 0x18ac(%rip), %rcx      # 0x341a
movl $0xb6, %edx
callq 0x1060
leaq 0x19fd(%rip), %rdi      # 0x357c
leaq 0x187a(%rip), %rsi      # 0x3400
leaq 0x188d(%rip), %rcx      # 0x341a
movl $0xb8, %edx
callq 0x1060
callq 0x1409