// File: /workspace/github_c_makefile_star2_O3/rchiossi[P]dexterity/lib/dex_offset.c
// Function: dx_shift_offset
void dx_shift_offset(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;
  
  dxo_header(dx->header,shift);
  dxo_maplist(dx->map_list,shift);

  for (i=0; i<dx->header->string_ids_size; i++)
    dxo_stringid(dx->string_ids[i],shift);
  
  for (i=0; i<dx->header->type_ids_size; i++)
    dxo_typeid(dx->type_ids[i],shift);
  
  for (i=0; i<dx->header->proto_ids_size; i++)
    dxo_protoid(dx->proto_ids[i],shift);
  
  for (i=0; i<dx->header->field_ids_size; i++)
    dxo_fieldid(dx->field_ids[i],shift);
  
  for (i=0; i<dx->header->method_ids_size; i++)
    dxo_methodid(dx->method_ids[i],shift);
  
  for (i=0; i<dx->header->class_defs_size; i++)
    dxo_classdef(dx->class_defs[i],shift);
    
  //Data
  for (i=0; i<dx->meta.string_data_list_size; i++)
    dxo_stringdata(dx->string_data_list[i],shift);
  
  for (i=0; i<dx->meta.type_lists_size; i++)
    dxo_typelist(dx->type_lists[i],shift);
  
  for (i=0; i<dx->meta.an_directories_size; i++)
    dxo_annotationdirectoryitem(dx->an_directories[i],shift);
  
  for (i=0; i<dx->meta.class_data_size; i++)
    dxo_classdata(dx->class_data[i],shift);
  
  for (i=0; i<dx->meta.encoded_arrays_size; i++)
    dxo_encodedarray(dx->encoded_arrays[i],shift);
  
  for (i=0; i<dx->meta.code_list_size; i++)
    dxo_codeitem(dx->code_list[i],shift);
  
  for (i=0; i<dx->meta.debug_info_list_size; i++)
    dxo_debuginfo(dx->debug_info_list[i],shift);
  
  for (i=0; i<dx->meta.an_set_size; i++)
    dxo_annotationsetitem(dx->an_set[i],shift);
  
  for (i=0; i<dx->meta.an_set_ref_lists_size; i++)
    dxo_annotationsetreflist(dx->an_set_ref_lists[i],shift);
  
  for (i=0; i<dx->meta.annotations_size; i++)
    dxo_annotationitem(dx->annotations[i],shift);  

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

  //ULEB expansion
  while (shift != NULL) {
    printf("delta1 = %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 0x9455
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), %rdi
movq %rax, %rsi
callq 0x4360
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x45a0
movq (%rbx), %rax
movl 0x40(%rax), %ecx
testq %rcx, %rcx
je 0x9115
movq 0x10(%rbx), %rdx
movl (%r14), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl 0x4(%r8), %r9d
cmpl %esi, %r9d
jb 0x90fc
addl 0x4(%r14), %r9d
movl %r9d, 0x4(%r8)
movl 0x8(%r8), %r9d
cmpl %esi, %r9d
jb 0x910d
addl 0x4(%r14), %r9d
movl %r9d, 0x8(%r8)
incq %rdi
cmpq %rdi, %rcx
jne 0x90e7
movl 0x48(%rax), %ecx
testq %rcx, %rcx
je 0x9143
movq 0x18(%rbx), %rdx
movl (%r14), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl 0x4(%r8), %r9d
cmpl %esi, %r9d
jb 0x913b
addl 0x4(%r14), %r9d
movl %r9d, 0x4(%r8)
incq %rdi
cmpq %rdi, %rcx
jne 0x9126
movl 0x50(%rax), %ecx
testq %rcx, %rcx
je 0x9182
movq 0x20(%rbx), %rdx
movl (%r14), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl 0x4(%r8), %r9d
cmpl %esi, %r9d
jb 0x9169
addl 0x4(%r14), %r9d
movl %r9d, 0x4(%r8)
movl 0x10(%r8), %r9d
cmpl %esi, %r9d
jb 0x917a
addl 0x4(%r14), %r9d
movl %r9d, 0x10(%r8)
incq %rdi
cmpq %rdi, %rcx
jne 0x9154
movl 0x58(%rax), %ecx
testq %rcx, %rcx
je 0x91b0
movq 0x28(%rbx), %rdx
movl (%r14), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl 0x4(%r8), %r9d
cmpl %esi, %r9d
jb 0x91a8
addl 0x4(%r14), %r9d
movl %r9d, 0x4(%r8)
incq %rdi
cmpq %rdi, %rcx
jne 0x9193
movl 0x60(%rax), %ecx
testq %rcx, %rcx
je 0x91de
movq 0x30(%rbx), %rdx
movl (%r14), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl 0x4(%r8), %r9d
cmpl %esi, %r9d
jb 0x91d6
addl 0x4(%r14), %r9d
movl %r9d, 0x4(%r8)
incq %rdi
cmpq %rdi, %rcx
jne 0x91c1
cmpl $0x0, 0x68(%rax)
je 0x9205
xorl %r15d, %r15d
movq 0x38(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x40c0
incq %r15
movq (%rbx), %rax
movl 0x68(%rax), %eax
cmpq %rax, %r15
jb 0x91e7
movq 0xc8(%rbx), %rax
testq %rax, %rax
je 0x9239
movq 0x40(%rbx), %rcx
movl (%r14), %edx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
movl 0x4(%rdi), %r8d
cmpl %edx, %r8d
jb 0x922f
addl 0x4(%r14), %r8d
movl %r8d, 0x4(%rdi)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0x921a
cmpq $0x0, 0xd8(%rbx)
je 0x9267
movl $0x1, %ebp
xorl %eax, %eax
movq 0x48(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x4350
movl %ebp, %eax
incl %ebp
cmpq %rax, 0xd8(%rbx)
ja 0x924a
cmpq $0x0, 0xe8(%rbx)
je 0x9295
movl $0x1, %ebp
xorl %eax, %eax
movq 0x50(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x46e0
movl %ebp, %eax
incl %ebp
cmpq %rax, 0xe8(%rbx)
ja 0x9278
cmpq $0x0, 0xf8(%rbx)
je 0x92c3
movl $0x1, %ebp
xorl %eax, %eax
movq 0x58(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x4670
movl %ebp, %eax
incl %ebp
cmpq %rax, 0xf8(%rbx)
ja 0x92a6
cmpq $0x0, 0x108(%rbx)
je 0x92f1
movl $0x1, %ebp
xorl %eax, %eax
movq 0x60(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x4590
movl %ebp, %eax
incl %ebp
cmpq %rax, 0x108(%rbx)
ja 0x92d4
cmpq $0x0, 0x118(%rbx)
je 0x931f
movl $0x1, %ebp
xorl %eax, %eax
movq 0x68(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x47a0
movl %ebp, %eax
incl %ebp
cmpq %rax, 0x118(%rbx)
ja 0x9302
movq 0x128(%rbx), %rax
testq %rax, %rax
je 0x9353
movq 0x70(%rbx), %rcx
movl (%r14), %edx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
movl 0x4(%rdi), %r8d
cmpl %edx, %r8d
jb 0x9349
addl 0x4(%r14), %r8d
movl %r8d, 0x4(%rdi)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0x9334
cmpq $0x0, 0x138(%rbx)
je 0x9381
movl $0x1, %ebp
xorl %eax, %eax
movq 0x78(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x40d0
movl %ebp, %eax
incl %ebp
cmpq %rax, 0x138(%rbx)
ja 0x9364
cmpq $0x0, 0x148(%rbx)
je 0x93b2
movl $0x1, %ebp
xorl %eax, %eax
movq 0x80(%rbx), %rcx
movq (%rcx,%rax,8), %rdi
movq %r14, %rsi
callq 0x4300
movl %ebp, %eax
incl %ebp
cmpq %rax, 0x148(%rbx)
ja 0x9392
cmpq $0x0, 0x158(%rbx)
je 0x93f6
movl $0x1, %ebp
xorl %eax, %eax
movq 0x88(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movl 0x4(%rax), %ecx
cmpl (%r14), %ecx
jb 0x93dd
addl 0x4(%r14), %ecx
movl %ecx, 0x4(%rax)
movq 0x10(%rax), %rdi
movq %r14, %rsi
callq 0x4530
movl %ebp, %eax
incl %ebp
cmpq %rax, 0x158(%rbx)
ja 0x93c3
movq 0x8(%r14), %r15
movq %r14, %rdi
callq 0x4060
testq %r15, %r15
je 0x944d
leaq 0xdce(%rip), %r14       # 0xa1dc
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 0x9431
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 0x940e
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop