// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/ldscript.c
// Function: add_phdr
static struct Phdr *add_phdr(struct GlobalVars *gv,const char *name,
                             uint32_t type,uint16_t flags,lword addr,
                             struct MemoryDescr *vmreg,struct MemoryDescr *lmreg)
{
  struct Phdr *p,*new;

  if (type == PT_PHDR) {
    flags |= PHDR_USED;
  }
  else if ((flags&(PHDR_FILEHDR|PHDR_PHDRS))==PHDR_FILEHDR ||
           (flags&(PHDR_FILEHDR|PHDR_PHDRS))==PHDR_PHDRS) {
    /* must include both: FILEHDR and PHDR */
    error(77,scriptname,getlineno(),name);
    return NULL;
  }

  new = alloczero(sizeof(struct Phdr));
  new->name = allocstring(name);
  new->type = type;
  new->flags = flags;
  new->start = addr;
  new->start_vma = ADDR_NONE;
  new->vmregion = vmreg;
  new->lmregion = lmreg;

  if (type == PT_LOAD) {
    if (!gv->no_page_align)
      new->alignment = shiftcnt(fff[gv->dest_format]->page_size);
  }
  else if (type == PT_PHDR)
    new->alignment = 2;

  if (p = gv->phdrlist) {
    while (p->next) {
      if (type==PT_PHDR && p->type==PT_PHDR) {
        free(new);
        return NULL;  /* reject double PHDR segment */
      }
      p = p->next;
    }
    p->next = new;
  }
  else
    gv->phdrlist = new;

  return new;
}

// Assembly:
subq $0x48, %rsp
movw %cx, %ax
movq 0x50(%rsp), %rcx
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movl %edx, 0x2c(%rsp)
movw %ax, 0x2a(%rsp)
movq %r8, 0x20(%rsp)
movq %r9, 0x18(%rsp)
cmpl $0x6, 0x2c(%rsp)
jne 0x1769f
movzwl 0x2a(%rsp), %eax
orl $0x10, %eax
movw %ax, 0x2a(%rsp)
jmp 0x176f8
movzwl 0x2a(%rsp), %eax
andl $0xc00, %eax            # imm = 0xC00
cmpl $0x800, %eax            # imm = 0x800
je 0x176c1
movzwl 0x2a(%rsp), %eax
andl $0xc00, %eax            # imm = 0xC00
cmpl $0x400, %eax            # imm = 0x400
jne 0x176f6
movq 0x2d328(%rip), %rax     # 0x449f0
movq %rax, (%rsp)
callq 0x18f50
movq (%rsp), %rsi
movl %eax, %edx
movq 0x30(%rsp), %rcx
movl $0x4d, %edi
movb $0x0, %al
callq 0x8c00
movq $0x0, 0x40(%rsp)
jmp 0x17843
jmp 0x176f8
movl $0x58, %edi
callq 0x7290
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
callq 0x72d0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
movl 0x2c(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x20(%rax)
movw 0x2a(%rsp), %cx
movq 0x8(%rsp), %rax
movw %cx, 0x24(%rax)
movq 0x20(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x8(%rsp), %rax
movq $-0x1, 0x28(%rax)
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
movq 0x50(%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x18(%rax)
cmpl $0x1, 0x2c(%rsp)
jne 0x177ad
movq 0x38(%rsp), %rax
cmpl $0x0, 0x7c(%rax)
jne 0x177ab
movq 0x38(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x2829e(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movl 0x98(%rax), %edi
callq 0x8860
movb %al, %cl
movq 0x8(%rsp), %rax
movb %cl, 0x26(%rax)
jmp 0x177bf
cmpl $0x6, 0x2c(%rsp)
jne 0x177bd
movq 0x8(%rsp), %rax
movb $0x2, 0x26(%rax)
jmp 0x177bf
movq 0x38(%rsp), %rax
movq 0x1f8(%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x17828
jmp 0x177d8
movq 0x10(%rsp), %rax
cmpq $0x0, (%rax)
je 0x17819
cmpl $0x6, 0x2c(%rsp)
jne 0x1780a
movq 0x10(%rsp), %rax
cmpl $0x6, 0x20(%rax)
jne 0x1780a
movq 0x8(%rsp), %rdi
callq 0x5030
movq $0x0, 0x40(%rsp)
jmp 0x17843
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x177d8
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rax
movq %rcx, (%rax)
jmp 0x17839
movq 0x8(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x1f8(%rax)
movq 0x8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopl (%rax)