// File: /workspace/github_c_makefile_star2_O1/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 0x92f0
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 0x8fad
movq 0x10(%rbx), %rdx
movl (%r14), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl 0x4(%r8), %r9d
cmpl %esi, %r9d
jb 0x8f94
addl 0x4(%r14), %r9d
movl %r9d, 0x4(%r8)
movl 0x8(%r8), %r9d
cmpl %esi, %r9d
jb 0x8fa5
addl 0x4(%r14), %r9d
movl %r9d, 0x8(%r8)
incq %rdi
cmpq %rdi, %rcx
jne 0x8f7f
movl 0x48(%rax), %ecx
testq %rcx, %rcx
je 0x8fdb
movq 0x18(%rbx), %rdx
movl (%r14), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl 0x4(%r8), %r9d
cmpl %esi, %r9d
jb 0x8fd3
addl 0x4(%r14), %r9d
movl %r9d, 0x4(%r8)
incq %rdi
cmpq %rdi, %rcx
jne 0x8fbe
movl 0x50(%rax), %ecx
testq %rcx, %rcx
je 0x901a
movq 0x20(%rbx), %rdx
movl (%r14), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl 0x4(%r8), %r9d
cmpl %esi, %r9d
jb 0x9001
addl 0x4(%r14), %r9d
movl %r9d, 0x4(%r8)
movl 0x10(%r8), %r9d
cmpl %esi, %r9d
jb 0x9012
addl 0x4(%r14), %r9d
movl %r9d, 0x10(%r8)
incq %rdi
cmpq %rdi, %rcx
jne 0x8fec
movl 0x58(%rax), %ecx
testq %rcx, %rcx
je 0x9048
movq 0x28(%rbx), %rdx
movl (%r14), %esi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
movl 0x4(%r8), %r9d
cmpl %esi, %r9d
jb 0x9040
addl 0x4(%r14), %r9d
movl %r9d, 0x4(%r8)
incq %rdi
cmpq %rdi, %rcx
jne 0x902b
movl 0x60(%rax), %eax
testq %rax, %rax
je 0x9076
movq 0x30(%rbx), %rcx
movl (%r14), %edx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
movl 0x4(%rdi), %r8d
cmpl %edx, %r8d
jb 0x906e
addl 0x4(%r14), %r8d
movl %r8d, 0x4(%rdi)
incq %rsi
cmpq %rsi, %rax
jne 0x9059
movq (%rbx), %rax
cmpl $0x0, 0x68(%rax)
je 0x90a0
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 0x9082
movq 0xc8(%rbx), %rax
testq %rax, %rax
je 0x90d4
movq 0x40(%rbx), %rcx
movl (%r14), %edx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
movl 0x4(%rdi), %r8d
cmpl %edx, %r8d
jb 0x90ca
addl 0x4(%r14), %r8d
movl %r8d, 0x4(%rdi)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0x90b5
cmpq $0x0, 0xd8(%rbx)
je 0x9102
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 0x90e5
cmpq $0x0, 0xe8(%rbx)
je 0x9130
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 0x9113
cmpq $0x0, 0xf8(%rbx)
je 0x915e
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 0x9141
cmpq $0x0, 0x108(%rbx)
je 0x918c
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 0x916f
cmpq $0x0, 0x118(%rbx)
je 0x91ba
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 0x919d
movq 0x128(%rbx), %rax
testq %rax, %rax
je 0x91ee
movq 0x70(%rbx), %rcx
movl (%r14), %edx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
movl 0x4(%rdi), %r8d
cmpl %edx, %r8d
jb 0x91e4
addl 0x4(%r14), %r8d
movl %r8d, 0x4(%rdi)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0x91cf
cmpq $0x0, 0x138(%rbx)
je 0x921c
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 0x91ff
cmpq $0x0, 0x148(%rbx)
je 0x924d
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 0x922d
cmpq $0x0, 0x158(%rbx)
je 0x9291
movl $0x1, %ebp
xorl %eax, %eax
movq 0x88(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movl 0x4(%rax), %ecx
cmpl (%r14), %ecx
jb 0x9278
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 0x925e
movq 0x8(%r14), %r15
movq %r14, %rdi
callq 0x4060
testq %r15, %r15
je 0x92e8
leaq 0xf3b(%rip), %r14       # 0xa1e4
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 0x92cc
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 0x92a9
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)