// File: /workspace/github_c_makefile_star2_O2/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 0x8da6
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %rbx
pushq $0x10
popq %rdi
callq 0x46a0
movq %rax, %r14
movl %r15d, (%rax)
movl %ebp, 0x4(%rax)
andq $0x0, 0x8(%rax)
movq (%rbx), %rdi
movq %rax, %rsi
callq 0x43c0
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x4630
xorl %r15d, %r15d
movq (%rbx), %rax
movl 0x40(%rax), %ecx
cmpq %rcx, %r15
jae 0x8b16
movq 0x10(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x46e0
incq %r15
jmp 0x8af6
movl 0x48(%rax), %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x8b3c
movq 0x18(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movl 0x4(%rsi), %edi
cmpl (%r14), %edi
jb 0x8b37
addl 0x4(%r14), %edi
movl %edi, 0x4(%rsi)
incq %rdx
jmp 0x8b1b
xorl %r15d, %r15d
movl 0x50(%rax), %ecx
cmpq %rcx, %r15
jae 0x8b5f
movq 0x20(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x4190
incq %r15
movq (%rbx), %rax
jmp 0x8b3f
movl 0x58(%rax), %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x8b85
movq 0x28(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movl 0x4(%rsi), %edi
cmpl (%r14), %edi
jb 0x8b80
addl 0x4(%r14), %edi
movl %edi, 0x4(%rsi)
incq %rdx
jmp 0x8b64
movl 0x60(%rax), %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x8bab
movq 0x30(%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movl 0x4(%rsi), %edi
cmpl (%r14), %edi
jb 0x8ba6
addl 0x4(%r14), %edi
movl %edi, 0x4(%rsi)
incq %rdx
jmp 0x8b8a
xorl %r15d, %r15d
movl 0x68(%rax), %eax
cmpq %rax, %r15
jae 0x8bce
movq 0x38(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x40c0
incq %r15
movq (%rbx), %rax
jmp 0x8bae
movq 0xc8(%rbx), %rax
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x8bf9
movq 0x40(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movl 0x4(%rdx), %esi
cmpl (%r14), %esi
jb 0x8bf5
addl 0x4(%r14), %esi
movl %esi, 0x4(%rdx)
incl %ecx
jmp 0x8bd7
xorl %eax, %eax
movl %eax, %r15d
cmpq %r15, 0xd8(%rbx)
jbe 0x8c1d
movq 0x48(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x43b0
leal 0x1(%r15), %eax
jmp 0x8bfb
xorl %eax, %eax
movl %eax, %r15d
cmpq %r15, 0xe8(%rbx)
jbe 0x8c41
movq 0x50(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x47a0
leal 0x1(%r15), %eax
jmp 0x8c1f
xorl %eax, %eax
movl %eax, %r15d
cmpq %r15, 0xf8(%rbx)
jbe 0x8c65
movq 0x58(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x4720
leal 0x1(%r15), %eax
jmp 0x8c43
xorl %eax, %eax
movl %eax, %r15d
cmpq %r15, 0x108(%rbx)
jbe 0x8c89
movq 0x60(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x4620
leal 0x1(%r15), %eax
jmp 0x8c67
xorl %eax, %eax
movl %eax, %r15d
cmpq %r15, 0x118(%rbx)
jbe 0x8cad
movq 0x68(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x4870
leal 0x1(%r15), %eax
jmp 0x8c8b
movq 0x128(%rbx), %rax
xorl %ecx, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x8cd8
movq 0x70(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movl 0x4(%rdx), %esi
cmpl (%r14), %esi
jb 0x8cd4
addl 0x4(%r14), %esi
movl %esi, 0x4(%rdx)
incl %ecx
jmp 0x8cb6
xorl %eax, %eax
movl %eax, %r15d
cmpq %r15, 0x138(%rbx)
jbe 0x8cfc
movq 0x78(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x40d0
leal 0x1(%r15), %eax
jmp 0x8cda
xorl %eax, %eax
movl %eax, %r15d
cmpq %r15, 0x148(%rbx)
jbe 0x8d23
movq 0x80(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x4360
leal 0x1(%r15), %eax
jmp 0x8cfe
xorl %eax, %eax
movl %eax, %r15d
cmpq %r15, 0x158(%rbx)
jbe 0x8d4a
movq 0x88(%rbx), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x43f0
leal 0x1(%r15), %eax
jmp 0x8d25
movq 0x8(%r14), %r15
movq %r14, %rdi
callq 0x4060
leaq 0x147f(%rip), %r14      # 0xa1dc
testq %r15, %r15
je 0x8d9e
movl 0x4(%r15), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x4250
movl 0x4(%r15), %edx
movq (%rbx), %rax
addl %edx, 0x28(%rax)
movl (%r15), %esi
cmpl 0x74(%rax), %esi
jbe 0x8d85
addl %edx, 0x70(%rax)
movq %rbx, %rdi
callq 0x4610
movq 0x8(%r15), %r12
movq %r15, %rdi
callq 0x4060
movq %r12, %r15
jmp 0x8d5d
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop