// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_makeshdrs
void elf32_makeshdrs(struct GlobalVars *gv)
/* generate all ELF section headers */
{
  struct Phdr *p,*p2;
  struct LinkedSection *ls;
  unsigned long poffs;

  /* touch elf32symlist, to make sure it is initialized */
  elf32_addsym(&elf32symlist,&elf32stringlist,NULL,0,0,0,0,0);

  /* offset, to find section-symbols by section header index */
  secsyms = (int)elf32symlist.nextindex - (int)elf32shdridx;

  /* reset index */
  for (ls=(struct LinkedSection *)gv->lnksec.first;
       ls->n.next!=NULL; ls=(struct LinkedSection *)ls->n.next)
    ls->index = 0;

  for (p=gv->phdrlist; p; p=p->next) {
    if (p->type==PT_LOAD && (p->flags&PHDR_USED) &&
        p->start!=ADDR_NONE && p->start_vma!=ADDR_NONE) {
      /* check file offset for current segment */
      elf32offset += p->alignment_gap;
      poffs = p->offset;
      if (p->flags & (PHDR_PHDRS|PHDR_FILEHDR)) {
        poffs += fff[gv->dest_format]->headersize(gv) + file_hdr_gap;
        elf32offset += file_hdr_gap;
      }
      if (poffs != elf32offset) {
        ierror("elf32_makeshdrs(): PHDR \"%s\" offs %lu != %lu\n",
               p->name,poffs,elf32offset);
      }

      /* find sections which belong to this segment and set their index */
      for (ls=(struct LinkedSection *)gv->lnksec.first;
           ls->n.next!=NULL; ls=(struct LinkedSection *)ls->n.next) {
        if (ls->copybase>=(unsigned long)p->start &&
            (ls->copybase+ls->size)<=(unsigned long)p->mem_end &&
            (ls->flags & SF_ALLOC) && ls->index==0) {
          uint32_t f = SHF_ALLOC;
          bool bss = ls->type==ST_UDATA || (ls->flags&SF_UNINITIALIZED);

          ls->index = (int)elf32shdridx;
          f |= (ls->protection & SP_WRITE) ? SHF_WRITE : 0;
          f |= (ls->protection & SP_EXEC) ? SHF_EXECINSTR : 0;
          add_section_shdr(ls,bss,f);

          /* check if section included in other non-LOAD segments as well */
          for (p2=gv->phdrlist; p2; p2=p2->next) {
            if (p2->type!=PT_LOAD && (p2->flags&PHDR_USED) &&
                p2->start==(lword)ls->copybase)
              p2->offset = elf32offset;
          }

          /* update file offset */
          if (gv->dest_object) {
            if (!bss)
              elf32offset += ls->size;
          }
          else {
            elf32offset += ls->filesize + ls->gapsize;
          }

          /* add section symbol (without name) */
          elf32_addsym(&elf32symlist,&elf32stringlist,noname,
                       (uint32_t)ls->base,0,STB_LOCAL,STT_SECTION,
                       (uint16_t)ls->index);
        }
      }
    }
  }

  /* unallocated sections at last */
  for (ls=(struct LinkedSection *)gv->lnksec.first;
       ls->n.next!=NULL; ls=(struct LinkedSection *)ls->n.next) {
    if (ls->index == 0) {
      uint32_t f = 0;
      bool bss = ls->type==ST_UDATA || (ls->flags&SF_UNINITIALIZED);

      ls->index = (int)elf32shdridx;
      f |= (ls->protection & SP_WRITE) ? SHF_WRITE : 0;
      f |= (ls->protection & SP_EXEC) ? SHF_EXECINSTR : 0;
      add_section_shdr(ls,bss,f);
      /* update file offset */
      if (!bss)
        elf32offset += ls->size;
      /* add section symbol (without name) */
      elf32_addsym(&elf32symlist,&elf32stringlist,noname,(uint32_t)ls->base,0,
                   STB_LOCAL,STT_SECTION,(uint16_t)ls->index);
    }
  }
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
leaq 0x1b430(%rip), %rdi     # 0x401e0
leaq 0x1b489(%rip), %rsi     # 0x40240
xorl %eax, %eax
movl %eax, %edx
xorl %r9d, %r9d
movl %r9d, %ecx
movl %r9d, %r8d
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x22910
movl 0x1b42a(%rip), %eax     # 0x40208
subl 0x1ff0c(%rip), %eax     # 0x44cf0
movl %eax, 0x1ff0a(%rip)     # 0x44cf4
movq 0x50(%rsp), %rax
movq 0x1c0(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq $0x0, (%rax)
je 0x24e21
movq 0x38(%rsp), %rax
movl $0x0, 0x10(%rax)
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0x24dfb
movq 0x50(%rsp), %rax
movq 0x1f8(%rax), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0x25170
movq 0x48(%rsp), %rax
cmpl $0x1, 0x20(%rax)
jne 0x2515c
movq 0x48(%rsp), %rax
movzwl 0x24(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x2515c
movq 0x48(%rsp), %rax
cmpq $-0x1, 0x30(%rax)
je 0x2515c
movq 0x48(%rsp), %rax
cmpq $-0x1, 0x28(%rax)
je 0x2515c
movq 0x48(%rsp), %rax
movq 0x50(%rax), %rax
addq 0x1fe66(%rip), %rax     # 0x44cf8
movq %rax, 0x1fe5f(%rip)     # 0x44cf8
movq 0x48(%rsp), %rax
movq 0x48(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x48(%rsp), %rax
movzwl 0x24(%rax), %eax
andl $0xc00, %eax            # imm = 0xC00
cmpl $0x0, %eax
je 0x24f01
movq 0x50(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x1ab64(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movq 0x18(%rax), %rax
movq 0x50(%rsp), %rdi
callq *%rax
addq 0x1fdee(%rip), %rax     # 0x44cd0
addq 0x30(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x1fddd(%rip), %rax     # 0x44cd0
addq 0x1fdfe(%rip), %rax     # 0x44cf8
movq %rax, 0x1fdf7(%rip)     # 0x44cf8
movq 0x30(%rsp), %rax
cmpq 0x1fdeb(%rip), %rax     # 0x44cf8
je 0x24f32
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rsi
movq 0x30(%rsp), %rdx
movq 0x1fdd4(%rip), %rcx     # 0x44cf8
leaq 0x116d5(%rip), %rdi     # 0x36600
movb $0x0, %al
callq 0x8ae0
movq 0x50(%rsp), %rax
movq 0x1c0(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq $0x0, (%rax)
je 0x2515a
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x48(%rsp), %rcx
cmpq 0x30(%rcx), %rax
jb 0x25146
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x38(%rsp), %rcx
addq 0x48(%rcx), %rax
movq 0x48(%rsp), %rcx
cmpq 0x40(%rcx), %rax
ja 0x25146
movq 0x38(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x25146
movq 0x38(%rsp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x25146
movl $0x2, 0x2c(%rsp)
movq 0x38(%rsp), %rax
movzbl 0x20(%rax), %ecx
movb $0x1, %al
cmpl $0x3, %ecx
movb %al, 0x1f(%rsp)
je 0x24fe1
movq 0x38(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
setne %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x28(%rsp)
movl 0x1fcfc(%rip), %ecx     # 0x44cf0
movq 0x38(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x38(%rsp), %rax
movzbl 0x22(%rax), %edx
andl $0x2, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
orl 0x2c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x38(%rsp), %rax
movzbl 0x22(%rax), %edx
andl $0x4, %edx
xorl %eax, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
orl 0x2c(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x38(%rsp), %rdi
movl 0x28(%rsp), %esi
movl 0x2c(%rsp), %edx
callq 0x252c0
movq 0x50(%rsp), %rax
movq 0x1f8(%rax), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, 0x40(%rsp)
je 0x250ba
movq 0x40(%rsp), %rax
cmpl $0x1, 0x20(%rax)
je 0x250a9
movq 0x40(%rsp), %rax
movzwl 0x24(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x250a9
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rsp), %rcx
cmpq 0x38(%rcx), %rax
jne 0x250a9
movq 0x1fc58(%rip), %rcx     # 0x44cf8
movq 0x40(%rsp), %rax
movq %rcx, 0x48(%rax)
jmp 0x250ab
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x25061
movq 0x50(%rsp), %rax
cmpl $0x0, 0x54(%rax)
je 0x250e5
cmpl $0x0, 0x28(%rsp)
jne 0x250e3
movq 0x38(%rsp), %rax
movq 0x48(%rax), %rax
addq 0x1fc1c(%rip), %rax     # 0x44cf8
movq %rax, 0x1fc15(%rip)     # 0x44cf8
jmp 0x25105
movq 0x38(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x38(%rsp), %rcx
addq 0x58(%rcx), %rax
addq 0x1fbfa(%rip), %rax     # 0x44cf8
movq %rax, 0x1fbf3(%rip)     # 0x44cf8
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
movl %eax, %ecx
movq 0x38(%rsp), %rax
movl 0x10(%rax), %eax
leaq 0x1b0c1(%rip), %rdi     # 0x401e0
leaq 0x1b11a(%rip), %rsi     # 0x40240
leaq 0x10523(%rip), %rdx     # 0x35650
xorl %r9d, %r9d
movl %r9d, %r8d
movl $0x3, (%rsp)
movzwl %ax, %eax
movl %eax, 0x8(%rsp)
callq 0x22910
jmp 0x25148
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0x24f43
jmp 0x2515c
jmp 0x2515e
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
jmp 0x24e32
movq 0x50(%rsp), %rax
movq 0x1c0(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq $0x0, (%rax)
je 0x252b3
movq 0x38(%rsp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x2529f
movl $0x0, 0x24(%rsp)
movq 0x38(%rsp), %rax
movzbl 0x20(%rax), %ecx
movb $0x1, %al
cmpl $0x3, %ecx
movb %al, 0x1e(%rsp)
je 0x251d1
movq 0x38(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
setne %al
movb %al, 0x1e(%rsp)
movb 0x1e(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x20(%rsp)
movl 0x1fb0c(%rip), %ecx     # 0x44cf0
movq 0x38(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x38(%rsp), %rax
movzbl 0x22(%rax), %edx
andl $0x2, %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
orl 0x24(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x38(%rsp), %rax
movzbl 0x22(%rax), %edx
andl $0x4, %edx
xorl %eax, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
orl 0x24(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x38(%rsp), %rdi
movl 0x20(%rsp), %esi
movl 0x24(%rsp), %edx
callq 0x252c0
cmpl $0x0, 0x20(%rsp)
jne 0x2525e
movq 0x38(%rsp), %rax
movq 0x48(%rax), %rax
addq 0x1faa1(%rip), %rax     # 0x44cf8
movq %rax, 0x1fa9a(%rip)     # 0x44cf8
movq 0x38(%rsp), %rax
movq 0x40(%rax), %rax
movl %eax, %ecx
movq 0x38(%rsp), %rax
movl 0x10(%rax), %eax
leaq 0x1af68(%rip), %rdi     # 0x401e0
leaq 0x1afc1(%rip), %rsi     # 0x40240
leaq 0x103ca(%rip), %rdx     # 0x35650
xorl %r9d, %r9d
movl %r9d, %r8d
movl $0x3, (%rsp)
movzwl %ax, %eax
movl %eax, 0x8(%rsp)
callq 0x22910
jmp 0x252a1
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0x25181
addq $0x58, %rsp
retq
nopl (%rax,%rax)