// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/ldscript.c
// Function: add_section_to_segments
static void add_section_to_segments(struct GlobalVars *gv,
                                    struct LinkedSection *ls,
                                    struct Phdr **plist)
{
  struct Phdr **pp = plist;
  struct Phdr *p,*p2;
  bool loadseg_present = FALSE;

  if (!(ls->flags & SF_ALLOC) || ls->type==ST_UNDEFINED)
    return; /* non-allocated or empty sections are not part of any segment! */

  while (p = *pp++) {
    if (p->flags & PHDR_CLOSED) {
      /* segment is closed and can't be reused */
      error(75,scriptname,getlineno(),p->name);
    }
    else {
      if (p->type == PT_LOAD) {
        if (loadseg_present) {
          /* Section was assigned to more than one PT_LOAD segment */
          error(80,scriptname,getlineno(),ls->name);
          p->flags &= ~PHDR_USED;
          continue;
        }
        else
          loadseg_present = TRUE;
      }
      if (p->start == ADDR_NONE)
        p->start = p->file_end = ls->copybase;
      if (p->start_vma == ADDR_NONE)
        p->start_vma = ls->base;
      p->mem_end = ls->copybase + ls->size;
      if (ls->filesize)
        p->file_end = ls->copybase + ls->filesize;
      if (ls->alignment > p->alignment)
        p->alignment = ls->alignment;
    }

    /* move referenced segment to the end of the list */
    if (gv->phdrlist == p) {
      gv->phdrlist = p->next;
    }
    else {
      for (p2=gv->phdrlist; p2; p2=p2->next) {
        if (p2->next == p)
          p2->next = p->next;
      }
    }
    if (gv->phdrlist == NULL) {
      gv->phdrlist = p;
    }
    else {
      for (p2=gv->phdrlist; p2->next; p2=p2->next);
      p2->next = p;
    }
    p->next = NULL;
  }

  /* close all unreferenced segments */
  for (p=gv->phdrlist; p; p=p->next) {
    for (pp=plist; *pp; pp++) {
      if (p == *pp)
        break;
    }
    if (*pp == NULL) {
      if (p->start != ADDR_NONE)
        p->flags |= PHDR_CLOSED;  /* close no longer used segment */
    }
  }
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x38(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x162d4
movq 0x38(%rsp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x0, %eax
jne 0x162d9
jmp 0x165bd
jmp 0x162db
movq 0x28(%rsp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, 0x28(%rsp)
movq (%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
je 0x1652f
movq 0x20(%rsp), %rax
movzwl 0x24(%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x16343
movq 0x2e6d8(%rip), %rax     # 0x449f0
movq %rax, 0x8(%rsp)
callq 0x18f50
movq 0x8(%rsp), %rsi
movl %eax, %edx
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rcx
movl $0x4b, %edi
movb $0x0, %al
callq 0x8c00
jmp 0x1644e
movq 0x20(%rsp), %rax
cmpl $0x1, 0x20(%rax)
jne 0x1639f
cmpl $0x0, 0x14(%rsp)
je 0x16395
movq 0x2e694(%rip), %rax     # 0x449f0
movq %rax, (%rsp)
callq 0x18f50
movq (%rsp), %rsi
movl %eax, %edx
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rcx
movl $0x50, %edi
movb $0x0, %al
callq 0x8c00
movq 0x20(%rsp), %rax
movzwl 0x24(%rax), %ecx
andl $-0x11, %ecx
movw %cx, 0x24(%rax)
jmp 0x162db
movl $0x1, 0x14(%rsp)
jmp 0x1639f
movq 0x20(%rsp), %rax
cmpq $-0x1, 0x30(%rax)
jne 0x163c6
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x20(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x20(%rsp), %rax
cmpq $-0x1, 0x28(%rax)
jne 0x163e4
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rcx
movq 0x38(%rsp), %rax
addq 0x48(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x40(%rax)
movq 0x38(%rsp), %rax
cmpq $0x0, 0x50(%rax)
je 0x16426
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rcx
movq 0x38(%rsp), %rax
addq 0x50(%rax), %rcx
movq 0x20(%rsp), %rax
movq %rcx, 0x38(%rax)
movq 0x38(%rsp), %rax
movzbl 0x23(%rax), %eax
movq 0x20(%rsp), %rcx
movzbl 0x26(%rcx), %ecx
cmpl %ecx, %eax
jle 0x1644c
movq 0x38(%rsp), %rax
movb 0x23(%rax), %cl
movq 0x20(%rsp), %rax
movb %cl, 0x26(%rax)
jmp 0x1644e
movq 0x40(%rsp), %rax
movq 0x1f8(%rax), %rax
cmpq 0x20(%rsp), %rax
jne 0x16477
movq 0x20(%rsp), %rax
movq (%rax), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x1f8(%rax)
jmp 0x164c2
movq 0x40(%rsp), %rax
movq 0x1f8(%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x164c0
movq 0x18(%rsp), %rax
movq (%rax), %rax
cmpq 0x20(%rsp), %rax
jne 0x164af
movq 0x20(%rsp), %rax
movq (%rax), %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
jmp 0x164b1
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x16488
jmp 0x164c2
movq 0x40(%rsp), %rax
cmpq $0x0, 0x1f8(%rax)
jne 0x164e4
movq 0x20(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x1f8(%rax)
jmp 0x1651e
movq 0x40(%rsp), %rax
movq 0x1f8(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
cmpq $0x0, (%rax)
je 0x16511
jmp 0x16502
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x164f5
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
movq 0x20(%rsp), %rax
movq $0x0, (%rax)
jmp 0x162db
movq 0x40(%rsp), %rax
movq 0x1f8(%rax), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x165bd
movq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq $0x0, (%rax)
je 0x16580
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq (%rcx), %rax
jne 0x1656e
jmp 0x16580
jmp 0x16570
movq 0x28(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x28(%rsp)
jmp 0x16552
movq 0x28(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x165ac
movq 0x20(%rsp), %rax
cmpq $-0x1, 0x30(%rax)
je 0x165aa
movq 0x20(%rsp), %rax
movzwl 0x24(%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
movw %cx, 0x24(%rax)
jmp 0x165ac
jmp 0x165ae
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x16540
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)