// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_makestabs
void elf32_makestabs(struct GlobalVars *gv)
/* create .stab, .stabstr und .rela.stab sections from StabDebug records */
{
  static const char *fn = "elf32_makestabs";
  bool be = elf32_endianess == _BIG_ENDIAN_;

  stabdebugidx = 0;
  initlist(&elf32stabcompunits);

  if (gv->strip_symbols < STRIP_DEBUG) {
    struct StabCompUnit *cu = NULL;
    bool so_found = FALSE;
    struct LinkedSection *ls;
    struct ObjectUnit *obj;
    struct StabDebug *stab;
    unsigned long stabsize = 0;

    /* determine size of .stab section to generate */
    for (obj=(struct ObjectUnit *)gv->selobjects.first,stabsize=0;
         obj->n.next!=NULL; obj=(struct ObjectUnit *)obj->n.next) {

      while (stab=(struct StabDebug *)remhead(&obj->stabs)) {

        if (stab->n_type==N_SO && stab->name.ptr!=NULL) {
          if (*stab->name.ptr != '\0') {
            if (!so_found) {
              /* allocate and initialize new compilation unit */
              stabsize += sizeof(struct nlist32);  /* comp.unit header */
              cu = newCompUnit();
              addtail(&elf32stabcompunits,&cu->n);
              so_found = TRUE;
            }
          }
        }
        else
          so_found = FALSE;

        if (cu == NULL)
          ierror("%s: N_SO missing",fn);
        if (cu->entries >= 0x7fff)
          ierror("%s: too many stab-entries for compilation unit",fn);
        stabsize += sizeof(struct nlist32);  /* stab entry */
        cu->entries++;

        /* register symbol name in comp.unit's string table */
        if (stab->name.ptr)
          stab->name.idx = elf32_addstrlist(&cu->strtab,stab->name.ptr);
        else
          stab->name.idx = 0;

        if (so_found)
          cu->nameidx = stab->name.idx;  /* set comp.unit name */

        /* append stab entry to current comp.unit */
        addtail(&cu->stabs,&stab->n);
      }
    }

    if (stabsize) {
      /* create .stab section with contents for real */
      struct nlist32 *nlst = alloc(stabsize);

      if (ls = find_lnksec(gv,".stab",0,0,0,0)) {
        if (ls->size > 0)
          ierror("%s: .stab already in use",fn);
      }
      else
        ls = create_lnksect(gv,".stab",ST_DATA,0,SP_READ,2);
      ls->size = ls->filesize = stabsize;
      ls->data = (uint8_t *)nlst;

      /* allocate SHDR name for .stabstr */
      stabdebugidx = elf32_addshdrstr(".stabstr");

      /* transfer nodes from compilation units to section's data area */
      for (cu=(struct StabCompUnit *)elf32stabcompunits.first;
           cu->n.next!=NULL; cu=(struct StabCompUnit *)cu->n.next) {
        bool within_fun = FALSE;
        uint32_t fun_addr = 0;

        /* write compilation unit stab header containing number
           of stabs and length of string-table */
        write_nlist(be,nlst++,cu->nameidx,0,0,cu->entries,
                    cu->strtab.nextindex);

        /* write comp.unit's stabs */
        for (stab=(struct StabDebug *)cu->stabs.first;
             stab->n.next!=NULL; stab=(struct StabDebug *)stab->n.next) {

          switch (stab->n_type) {
            case N_SO:
              within_fun = FALSE;
              break;
            case N_FUN:
              if (stab->name.idx) {
                within_fun = TRUE;
                fun_addr = stab->n_value;
              }
              else {  /* function end address needs to be relative (size) */
                within_fun = FALSE;
                stab->n_value -= fun_addr;
                stab->relsect = NULL;
              }
              break;
            case N_SLINE:
              if (within_fun && stab->relsect) {
                /* convert address into a function-offset */
                stab->n_value -= fun_addr;
                stab->relsect = NULL;
              }
              break;
          }

          /* add relocation, if required */
          if (stab->relsect) {
            struct Reloc *r = alloczero(sizeof(struct Reloc));

            stab->n_value += stab->relsect->offset;
            r->relocsect.lnk = stab->relsect->lnksec;
            r->offset = (uint8_t *)&nlst->n_value - ls->data;
            r->addend = (lword)stab->n_value;
            r->rtype = R_ABS;
            addreloc(NULL,r,0,32,-1);
            addtail(&ls->relocs,&r->n);
          }

          /* write stab entry to section */
          write_nlist(be,nlst++,stab->name.idx,stab->n_type,
                      stab->n_othr,stab->n_desc,stab->n_value);
        }
      }
    }
  }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movsbl 0x1a440(%rip), %eax     # 0x402d0
cmpl $0x1, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x5c(%rsp)
movl $0x0, 0x1ee5f(%rip)     # 0x44d08
leaq 0x1ee60(%rip), %rdi     # 0x44d10
callq 0x7330
movq 0x60(%rsp), %rax
movzbl 0x6c(%rax), %eax
cmpl $0x1, %eax
jge 0x263bc
movq $0x0, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x60(%rsp), %rax
movq 0x138(%rax), %rax
movq %rax, 0x38(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x38(%rsp), %rax
cmpq $0x0, (%rax)
je 0x2607c
jmp 0x25f0c
movq 0x38(%rsp), %rdi
addq $0x50, %rdi
callq 0x74d0
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
je 0x26068
movq 0x30(%rsp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x64, %eax
jne 0x25f90
movq 0x30(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x25f90
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x25f8e
cmpl $0x0, 0x4c(%rsp)
jne 0x25f8c
movq 0x28(%rsp), %rax
addq $0xc, %rax
movq %rax, 0x28(%rsp)
callq 0x263d0
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rsi
leaq 0x1ed91(%rip), %rdi     # 0x44d10
callq 0x7470
movl $0x1, 0x4c(%rsp)
jmp 0x25f8e
jmp 0x25f98
movl $0x0, 0x4c(%rsp)
cmpq $0x0, 0x50(%rsp)
jne 0x25fb5
movq 0x1a3d9(%rip), %rsi     # 0x40380
leaq 0x10696(%rip), %rdi     # 0x36644
movb $0x0, %al
callq 0x8ae0
movq 0x50(%rsp), %rax
cmpq $0x7fff, 0x18(%rax)     # imm = 0x7FFF
jb 0x25fd9
movq 0x1a3b5(%rip), %rsi     # 0x40380
leaq 0x10683(%rip), %rdi     # 0x36655
movb $0x0, %al
callq 0x8ae0
movq 0x28(%rsp), %rax
addq $0xc, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq 0x30(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x2602a
movq 0x50(%rsp), %rdi
addq $0x38, %rdi
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0x23a10
movl %eax, %eax
movl %eax, %ecx
movq 0x30(%rsp), %rax
movq %rcx, 0x18(%rax)
jmp 0x26037
movq 0x30(%rsp), %rax
movq $0x0, 0x18(%rax)
cmpl $0x0, 0x4c(%rsp)
je 0x26050
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x50(%rsp), %rdi
addq $0x20, %rdi
movq 0x30(%rsp), %rsi
callq 0x7470
jmp 0x25f0c
jmp 0x2606a
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
jmp 0x25efb
cmpq $0x0, 0x28(%rsp)
je 0x263ba
movq 0x28(%rsp), %rdi
callq 0x71f0
movq %rax, 0x20(%rsp)
movq 0x60(%rsp), %rdi
leaq 0x10643(%rip), %rsi     # 0x366e6
xorl %r9d, %r9d
movl %r9d, %edx
movl %r9d, %ecx
movl %r9d, %r8d
callq 0x12110
movq %rax, 0x40(%rsp)
cmpq $0x0, %rax
je 0x260e2
movq 0x40(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jbe 0x260e0
movq 0x1a2ae(%rip), %rsi     # 0x40380
leaq 0x105ab(%rip), %rdi     # 0x36684
movb $0x0, %al
callq 0x8ae0
jmp 0x26109
movq 0x60(%rsp), %rdi
leaq 0x105f8(%rip), %rsi     # 0x366e6
movl $0x2, %r9d
xorl %ecx, %ecx
movl $0x1, %r8d
movl %r9d, %edx
callq 0x12a60
movq %rax, 0x40(%rsp)
movq 0x28(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x50(%rax)
movq 0x40(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x20(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x78(%rax)
leaq 0x10568(%rip), %rdi     # 0x3669d
callq 0x25b90
movl %eax, 0x1ebc8(%rip)     # 0x44d08
movq 0x1ebc9(%rip), %rax     # 0x44d10
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq $0x0, (%rax)
je 0x263b8
movl $0x0, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movl 0x5c(%rsp), %edi
movq 0x20(%rsp), %rsi
movq %rsi, %rax
addq $0xc, %rax
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rdx
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rax
movw %ax, %r9w
movq 0x50(%rsp), %rax
movl 0x60(%rax), %eax
xorl %r8d, %r8d
movl %r8d, %ecx
movswl %r9w, %r9d
movl %eax, (%rsp)
callq 0x26400
movq 0x50(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
cmpq $0x0, (%rax)
je 0x263a4
movq 0x30(%rsp), %rax
movzbl 0x20(%rax), %eax
movl %eax, 0xc(%rsp)
subl $0x24, %eax
je 0x26205
jmp 0x261e1
movl 0xc(%rsp), %eax
subl $0x44, %eax
je 0x2624f
jmp 0x261ec
movl 0xc(%rsp), %eax
subl $0x64, %eax
jne 0x26282
jmp 0x261fb
movl $0x0, 0x1c(%rsp)
jmp 0x26282
movq 0x30(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x26227
movl $0x1, 0x1c(%rsp)
movq 0x30(%rsp), %rax
movl 0x24(%rax), %eax
movl %eax, 0x18(%rsp)
jmp 0x2624d
movl $0x0, 0x1c(%rsp)
movl 0x18(%rsp), %edx
movq 0x30(%rsp), %rax
movl 0x24(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x24(%rax)
movq 0x30(%rsp), %rax
movq $0x0, 0x10(%rax)
jmp 0x26282
cmpl $0x0, 0x1c(%rsp)
je 0x26280
movq 0x30(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x26280
movl 0x18(%rsp), %edx
movq 0x30(%rsp), %rax
movl 0x24(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x24(%rax)
movq 0x30(%rsp), %rax
movq $0x0, 0x10(%rax)
jmp 0x26282
movq 0x30(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2633e
movl $0x40, %edi
callq 0x7290
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x38(%rax), %rdx
movq 0x30(%rsp), %rax
movl 0x24(%rax), %ecx
addq %rdx, %rcx
movl %ecx, 0x24(%rax)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x20(%rsp), %rcx
addq $0x8, %rcx
movq 0x40(%rsp), %rax
movq 0x78(%rax), %rax
subq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x30(%rsp), %rax
movl 0x24(%rax), %eax
movl %eax, %ecx
movq 0x10(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x10(%rsp), %rax
movb $0x1, 0x38(%rax)
movq 0x10(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edi
xorl %edx, %edx
movl $0x20, %ecx
movq $-0x1, %r8
callq 0x109b0
movq 0x40(%rsp), %rdi
addq $0x80, %rdi
movq 0x10(%rsp), %rsi
callq 0x7470
movl 0x5c(%rsp), %edi
movq 0x20(%rsp), %rsi
movq %rsi, %rax
addq $0xc, %rax
movq %rax, 0x20(%rsp)
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rdx
movq 0x30(%rsp), %rax
movb 0x20(%rax), %cl
movq 0x30(%rsp), %rax
movb 0x21(%rax), %r8b
movq 0x30(%rsp), %rax
movw 0x22(%rax), %r9w
movq 0x30(%rsp), %rax
movl 0x24(%rax), %eax
movzbl %cl, %ecx
movsbl %r8b, %r8d
movswl %r9w, %r9d
movl %eax, (%rsp)
callq 0x26400
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x261be
jmp 0x263a6
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x50(%rsp)
jmp 0x2614c
jmp 0x263ba
jmp 0x263bc
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)