// File: /workspace/github_c_makefile_star2_O0/negge[P]xlink/src/xlink.c
// Function: xlink_module_split_segments
void xlink_module_split_segments(xlink_module *mod) {
  int i, j, k, n, m;
  for (i = 0; i < mod->nsegments; i++) {
    xlink_segment *seg;
    seg = mod->segments[i];
    if (seg->npublics > 1) {
      int *offsets;
      xlink_segment **segs;
      /* Allocate space for the worst case, a segment for every public */
      segs = xlink_malloc(seg->npublics*sizeof(xlink_segment *));
      offsets = xlink_malloc(seg->npublics*sizeof(int));
      /* All publics with offset == 0 stay in the existing segment */
      for (n = 0; n < seg->npublics && seg->publics[n]->offset == 0; n++);
      /* All publics with offset > 0 are split into their own segment */
      for (m = 0, j = seg->npublics - 1; j > n - 1; m++) {
        xlink_public *pub;
        pub = seg->publics[j];
        segs[m] = xlink_malloc(sizeof(xlink_segment));
        offsets[m] = pub->offset;
        *segs[m] = *seg;
        segs[m]->publics = NULL;
        segs[m]->relocs = NULL;
        segs[m]->npublics = segs[m]->nrelocs = 0;
        segs[m]->length = seg->length - offsets[m];
        if (seg->info & SEG_HAS_DATA) {
          segs[m]->data = xlink_malloc(segs[m]->length);
          segs[m]->mask = NULL;
          memcpy(segs[m]->data, &seg->data[offsets[m]], segs[m]->length);
        }
        seg->length -= segs[m]->length;
        /* Add all publics with the same offset to this new segment */
        for (; pub->offset == offsets[m]; j--, pub = seg->publics[j]) {
          pub->offset = 0;
          pub->segment = segs[m];
          xlink_segment_add_public(segs[m], pub);
        }
      }
      seg->npublics = n;
      /* Add the new segments to the module in the original order */
      for (j = m; j-- > 0; ) {
        XLINK_LIST_ADD(module, segment, mod, segs[j]);
      }
      /* All relocs with offset < seg->length stay in the existing segment */
      n = 0;
      for (; n < seg->nrelocs && seg->relocs[n]->offset < seg->length; n++) {
        xlink_reloc *rel;
        rel = seg->relocs[n];
        XLINK_ERROR(seg->length < rel->offset + OMF_FIXUP_SIZE[rel->location],
         ("FIXUP offset %i past segment end %i", rel->offset, seg->length));
      }
      /* Move all relocs with offset >= seg->length to the right segment */
      for (k = m - 1, j = n; j < seg->nrelocs; j++) {
        xlink_reloc *rel;
        rel = seg->relocs[j];
        for (; k >= 0 && offsets[k] + segs[k]->length < rel->offset; k--);
        XLINK_ERROR(k < 0,
         ("Could not find segment for reloc offset %i", rel->offset));
        rel->offset -= offsets[k];
        XLINK_ERROR(
         segs[k]->length < rel->offset + OMF_FIXUP_SIZE[rel->location],
         ("FIXUP offset %i past segment end %i", rel->offset, seg->length));
        rel->segment = segs[k];
        xlink_segment_add_reloc(segs[k], rel);
      }
      seg->nrelocs = n;
      /* If seg was part of a group, insert new segments into that group */
      if (seg->group != NULL) {
        xlink_group *grp;
        grp = seg->group;
        for (n = 0; n < grp->nsegments && grp->segments[n] != seg; n++);
        n++;
        grp->nsegments += m;
        grp->segments =
         xlink_realloc(grp->segments, grp->nsegments*sizeof(xlink_segment *));
        memmove(&grp->segments[n + m], &grp->segments[n],
         (grp->nsegments - (n + m))*sizeof(xlink_segment *));
        for (j = m; j-- > 0; ) {
          grp->segments[n + m - (j + 1)] = segs[j];
        }
      }
      /* If any relocs pointed into the segment, set their index and offset */
      for (j = 0; j < mod->nrelocs; j++) {
        xlink_reloc *rel;
        rel = mod->relocs[j];
        if (rel->target == OMF_TARGET_SEG && rel->target_idx == seg->index ) {
          k = 0;
          while (k < m && offsets[k] + segs[k]->length < rel->addend.offset) {
            k++;
          }
          XLINK_ERROR(k == m,
           ("Could not find segment for reloc offset %i", rel->offset));
          rel->target_idx = segs[k]->index;
          rel->addend.offset -= offsets[k];
        }
      }
      free(segs);
      free(offsets);
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x130(%rcx), %eax
jge 0x60a7
movq -0x8(%rbp), %rax
movq 0x128(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, 0x58(%rax)
jle 0x6097
movq -0x28(%rbp), %rax
movslq 0x58(%rax), %rdi
shlq $0x3, %rdi
callq 0xae70
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movslq 0x58(%rax), %rdi
shlq $0x2, %rdi
callq 0xae70
movq %rax, -0x30(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rdx
xorl %eax, %eax
cmpl 0x58(%rdx), %ecx
movb %al, -0x61(%rbp)
jge 0x59ca
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, 0x124(%rax)
sete %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x59d3
jmp 0x59e0
jmp 0x59d5
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x599c
movl $0x0, -0x1c(%rbp)
movq -0x28(%rbp), %rax
movl 0x58(%rax), %eax
subl $0x1, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x5bef
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movl $0x80, %edi
callq 0xae70
movq %rax, %rdx
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
movl 0x124(%rax), %edx
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x28(%rbp), %rsi
movl $0x80, %edx
callq 0x2100
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq $0x0, 0x50(%rax)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq $0x0, 0x70(%rax)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x0, 0x78(%rax)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl $0x0, 0x58(%rax)
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rdx
subl (%rax,%rdx,4), %ecx
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x1c(%rax)
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5b57
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x1c(%rax), %rdi
callq 0xae70
movq %rax, %rcx
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x38(%rax)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq $0x0, 0x40(%rax)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x38(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rsi
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x1c(%rax), %rdx
callq 0x2100
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1c(%rax), %edx
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x1c(%rax)
movq -0x40(%rbp), %rax
movl 0x124(%rax), %eax
movq -0x30(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x5bdf
movq -0x40(%rbp), %rax
movl $0x0, 0x124(%rax)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x40(%rbp), %rsi
callq 0x2360
movl -0x10(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x10(%rbp)
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
jmp 0x5b72
jmp 0x5be1
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x59f4
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x58(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x10(%rbp)
cmpl $0x0, %eax
jle 0x5c55
movq -0x8(%rbp), %rax
movl 0x130(%rax), %ecx
addl $0x1, %ecx
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rcx
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x33b0
jmp 0x5bff
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rdx
xorl %eax, %eax
cmpl 0x78(%rdx), %ecx
movb %al, -0x62(%rbp)
jge 0x5c8d
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x18(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
setb %al
movb %al, -0x62(%rbp)
movb -0x62(%rbp), %al
testb $0x1, %al
jne 0x5c96
jmp 0x5d07
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x48(%rbp), %rcx
movl 0x18(%rcx), %ecx
movq -0x48(%rbp), %rdx
movl 0x20(%rdx), %edx
movl %edx, %esi
leaq 0x8868(%rip), %rdx      # 0xe530
addl (%rdx,%rsi,4), %ecx
cmpl %ecx, %eax
jae 0x5cf5
movq -0x48(%rbp), %rax
movl 0x18(%rax), %esi
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %edx
leaq 0x9085(%rip), %rdi      # 0xed69
movb $0x0, %al
callq 0xad90
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21c0
jmp 0x5cf7
jmp 0x5cf9
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x5c5c
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x78(%rcx), %eax
jge 0x5e4e
movq -0x28(%rbp), %rax
movq 0x70(%rax), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x63(%rbp)
jl 0x5d6c
movq -0x30(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x38(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
addl 0x1c(%rcx), %eax
movq -0x50(%rbp), %rcx
cmpl 0x18(%rcx), %eax
setb %al
movb %al, -0x63(%rbp)
movb -0x63(%rbp), %al
testb $0x1, %al
jne 0x5d75
jmp 0x5d82
jmp 0x5d77
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5d3a
jmp 0x5d84
cmpl $0x0, -0x14(%rbp)
jge 0x5da9
movq -0x50(%rbp), %rax
movl 0x18(%rax), %esi
leaq 0x8ff5(%rip), %rdi      # 0xed8d
movb $0x0, %al
callq 0xad90
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21c0
jmp 0x5dab
movq -0x30(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x50(%rbp), %rax
movl 0x18(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x18(%rax)
movq -0x38(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x1c(%rax), %eax
movq -0x50(%rbp), %rcx
movl 0x18(%rcx), %ecx
movq -0x50(%rbp), %rdx
movl 0x20(%rdx), %edx
movl %edx, %esi
leaq 0x8748(%rip), %rdx      # 0xe530
addl (%rdx,%rsi,4), %ecx
cmpl %ecx, %eax
jae 0x5e15
movq -0x50(%rbp), %rax
movl 0x18(%rax), %esi
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %edx
leaq 0x8f65(%rip), %rdi      # 0xed69
movb $0x0, %al
callq 0xad90
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21c0
jmp 0x5e17
movq -0x38(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x50(%rbp), %rsi
callq 0x25c0
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x5d16
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x78(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x5f7d
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %ecx
movq -0x58(%rbp), %rdx
xorl %eax, %eax
cmpl 0x20(%rdx), %ecx
movb %al, -0x64(%rbp)
jge 0x5ea5
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x28(%rbp), %rax
setne %al
movb %al, -0x64(%rbp)
movb -0x64(%rbp), %al
testb $0x1, %al
jne 0x5eae
jmp 0x5ebb
jmp 0x5eb0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x5e7a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x58(%rbp), %rax
addl 0x20(%rax), %ecx
movl %ecx, 0x20(%rax)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x58(%rbp), %rax
movslq 0x20(%rax), %rsi
shlq $0x3, %rsi
callq 0xaed0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x18(%rbp), %eax
addl -0x1c(%rbp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rdi
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rsi
movslq -0x18(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
movq -0x58(%rbp), %rax
movl 0x20(%rax), %eax
movl -0x18(%rbp), %ecx
addl -0x1c(%rbp), %ecx
subl %ecx, %eax
movslq %eax, %rdx
shlq $0x3, %rdx
callq 0x2170
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x10(%rbp)
cmpl $0x0, %eax
jle 0x5f7b
movq -0x38(%rbp), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x18(%rbp), %ecx
addl -0x1c(%rbp), %ecx
movl -0x10(%rbp), %esi
addl $0x1, %esi
subl %esi, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x5f40
jmp 0x5f7d
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x180(%rcx), %eax
jge 0x6085
movq -0x8(%rbp), %rax
movq 0x178(%rax), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x4, 0x28(%rax)
jne 0x6075
movq -0x60(%rbp), %rax
movl 0x30(%rax), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x6075
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0x65(%rbp)
jge 0x600a
movq -0x30(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x38(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
addl 0x1c(%rcx), %eax
movq -0x60(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
setl %al
movb %al, -0x65(%rbp)
movb -0x65(%rbp), %al
testb $0x1, %al
jne 0x6013
jmp 0x601e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5fd6
jmp 0x6020
movl -0x14(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x6047
movq -0x60(%rbp), %rax
movl 0x18(%rax), %esi
leaq 0x8d57(%rip), %rdi      # 0xed8d
movb $0x0, %al
callq 0xad90
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21c0
jmp 0x6049
movq -0x38(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x30(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x60(%rbp), %rax
movl 0x3c(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x3c(%rax)
jmp 0x6077
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x5f84
movq -0x38(%rbp), %rdi
callq 0x2030
movq -0x30(%rbp), %rdi
callq 0x2030
jmp 0x6099
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x5933
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)