// File: /workspace/github_c_makefile_star2_O1/rchiossi[P]dexterity/lib/dex_stringid.c
// Function: dx_shift_stringid
void dx_shift_stringid(Dex* dx, uint32_t base, int32_t delta) {
  unsigned int i;

  dx_shift *shift, *prev;

  if (dx == NULL) return;

  shift = (dx_shift*) malloc_s(sizeof(dx_shift));

  shift->base = base;
  shift->delta = delta;
  shift->next = NULL;

  for (i=0; i<dx->header->type_ids_size; i++)
    dxsi_typeid(dx->type_ids[i],shift);
  
  for (i=0; i<dx->header->proto_ids_size; i++)
    dxsi_protoid(dx->proto_ids[i],shift);
  
  for (i=0; i<dx->header->field_ids_size; i++)
    dxsi_fieldid(dx->field_ids[i],shift);
  
  for (i=0; i<dx->header->method_ids_size; i++)
    dxsi_methodid(dx->method_ids[i],shift);
  
  for (i=0; i<dx->header->class_defs_size; i++)
    dxsi_classdef(dx->class_defs[i],shift);
  
  for (i=0; i<dx->meta.encoded_arrays_size; i++)
    dxsi_encodedarray(dx->encoded_arrays[i],shift);
  
  for (i=0; i<dx->meta.debug_info_list_size; i++)
    dxsi_debuginfo(dx->debug_info_list[i],shift);
  
  for (i=0; i<dx->meta.annotations_size; i++)
    dxsi_annotationitem(dx->annotations[i],shift);

  prev = shift;
  shift = shift->next;
  free(prev);

  //ULEB expansion  
  while (shift != NULL) {
    printf("delta2 = %d\n",shift->delta);
    dx->header->file_size += shift->delta;

    if (shift->base > dx->header->data_off)
      dx->header->data_size += shift->delta;

    dx_shift_offset(dx,shift->base,shift->delta);

    prev = shift;
    shift = shift->next;
    free(prev);
  }
  
}

// Assembly:
testq %rdi, %rdi
je 0x971a
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %rbx
movl $0x10, %edi
callq 0x4600
movq %rax, %r14
movl %r15d, (%rax)
movl %ebp, 0x4(%rax)
movq $0x0, 0x8(%rax)
movq (%rbx), %rax
movl 0x48(%rax), %ecx
testq %rcx, %rcx
je 0x9585
movq 0x18(%rbx), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movl 0x8(%rdi), %r8d
cmpl %r15d, %r8d
jb 0x957d
addl %ebp, %r8d
movl %r8d, 0x8(%rdi)
incq %rsi
cmpq %rsi, %rcx
jne 0x9569
movl 0x50(%rax), %ecx
testq %rcx, %rcx
je 0x95af
movq 0x20(%rbx), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movl 0x8(%rdi), %r8d
cmpl %r15d, %r8d
jb 0x95a7
addl %ebp, %r8d
movl %r8d, 0x8(%rdi)
incq %rsi
cmpq %rsi, %rcx
jne 0x9593
movl 0x58(%rax), %ecx
testq %rcx, %rcx
je 0x95d9
movq 0x28(%rbx), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movl 0xc(%rdi), %r8d
cmpl %r15d, %r8d
jb 0x95d1
addl %ebp, %r8d
movl %r8d, 0xc(%rdi)
incq %rsi
cmpq %rsi, %rcx
jne 0x95bd
movl 0x60(%rax), %ecx
testq %rcx, %rcx
je 0x9603
movq 0x30(%rbx), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movl 0xc(%rdi), %r8d
cmpl %r15d, %r8d
jb 0x95fb
addl %ebp, %r8d
movl %r8d, 0xc(%rdi)
incq %rsi
cmpq %rsi, %rcx
jne 0x95e7
movl 0x68(%rax), %eax
testq %rax, %rax
je 0x962a
movq 0x38(%rbx), %rcx
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
movl 0x18(%rsi), %edi
cmpl %r15d, %edi
jb 0x9622
addl %ebp, %edi
movl %edi, 0x18(%rsi)
incq %rdx
cmpq %rdx, %rax
jne 0x9611
cmpq $0x0, 0x108(%rbx)
je 0x9658
movl $0x1, %ebp
xorl %eax, %eax
movq 0x60(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x42f0
movl %ebp, %eax
incl %ebp
cmpq %rax, 0x108(%rbx)
ja 0x963b
cmpq $0x0, 0x128(%rbx)
je 0x9686
movl $0x1, %ebp
xorl %eax, %eax
movq 0x70(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x4440
movl %ebp, %eax
incl %ebp
cmpq %rax, 0x128(%rbx)
ja 0x9669
cmpq $0x0, 0x158(%rbx)
je 0x96bb
movl $0x1, %ebp
xorl %eax, %eax
movq 0x88(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movq 0x10(%rax), %rdi
movq %r14, %rsi
callq 0x46d0
movl %ebp, %eax
incl %ebp
cmpq %rax, 0x158(%rbx)
ja 0x9697
movq 0x8(%r14), %r15
movq %r14, %rdi
callq 0x4060
testq %r15, %r15
je 0x9712
leaq 0xb2b(%rip), %r14       # 0xa1fe
movl 0x4(%r15), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x4210
movl 0x4(%r15), %edx
movq (%rbx), %rax
addl %edx, 0x28(%rax)
movl (%r15), %esi
cmpl 0x74(%rax), %esi
jbe 0x96f6
addl %edx, 0x70(%rax)
movq %rbx, %rdi
callq 0x4580
movq 0x8(%r15), %r12
movq %r15, %rdi
callq 0x4060
movq %r12, %r15
testq %r12, %r12
jne 0x96d3
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop