// File: /workspace/github_c_makefile_star2_O3/deplinenoise[P]vlink/t_amigahunk.c
// Function: ehf_lnksym
static struct Symbol *ehf_lnksym(struct GlobalVars *gv,struct Section *sec,
                                 struct Reloc *xref)
/* Checks if undefined symbol is an EHF-linker symbol */
{
  if (!gv->dest_object) {

    if (!strncmp(ehf_addrsym,xref->xrefname,sizeof(ehf_addrsym)-1)) {
      const char *symname = xref->xrefname + (sizeof(ehf_addrsym) - 1);

      if (find_any_symbol(gv,sec,symname)) {
        /* Reference to an unknown symbol, which starts with "@_". */
        /* The symbol without "@_" has to exist. */
        char *objname = alloc(strlen(symname)+3);
        uint8_t *dat = alloczero(sizeof(uint32_t)); /* space for a 32-bit ptr */
        struct ObjectUnit *ou;
        struct Section *s;
        struct Symbol *sym;
        struct Reloc *r;

        /* create an artificial object with a ".tocd" data section */
        sprintf(objname,"%s.o",symname);
        ou = art_objunit(gv,objname,dat,sizeof(uint32_t));
        s = add_section(ou,".tocd",dat,sizeof(uint32_t),ST_DATA,
                        SF_ALLOC,SP_READ|SP_WRITE,2,FALSE);

        /* "@__name" contains a 32-bit reloc pointer, which has an */
        /* external reference to the symbol "_name". */
        r = newreloc(gv,s,symname,NULL,0,0,R_ABS,0);
        addreloc(s,r,0,32,-1);

        /* make "@__name" visible for the further linking process: */
        if (addsymbol(gv,s,xref->xrefname,NULL,0,SYM_RELOC,0,SYMI_OBJECT,
                      SYMB_GLOBAL,sizeof(uint32_t),FALSE))
          ierror("ehf_lnksym(): %s was assumed to be undefined, but "
                 "in reality it *is* defined",xref->xrefname);

        if (!(sym = findsymbol(gv,sec,xref->xrefname)))
          ierror("ehf_lnksym(): The just defined symbol %s has "
                 "disappeared",xref->xrefname);
        return (sym);
      }
    }
  }

  return (ados_lnksym(gv,sec,xref));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rdi, %r15
cmpl $0x0, 0x54(%rdi)
jne 0x122f4
movq %rsi, %r14
movq 0x10(%rbx), %r12
leaq 0x1d435(%rip), %rdi     # 0x2f718
movl $0x2, %edx
movq %r12, %rsi
callq 0x5070
testl %eax, %eax
je 0x1230d
movq %r15, %rdi
movq %rbx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11c1e
addq $0x2, %r12
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xafab
testq %rax, %rax
je 0x122f4
movq %r12, %rdi
callq 0x50e0
leaq 0x3(%rax), %rdi
callq 0x6638
movq %rax, %rbp
movl $0x4, %edi
callq 0x6686
movq %rax, %r13
leaq 0x10ede(%rip), %rsi     # 0x2322a
movq %rbp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x5250
movl $0x4, %ecx
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xbf37
subq $0x8, %rsp
movl $0x2, %ebp
leaq 0x10eb3(%rip), %rsi     # 0x2322f
movl $0x4, %ecx
movq %rax, %rdi
movq %r13, %rdx
movl $0x2, %r8d
movl $0x1, %r9d
xorl %eax, %eax
pushq %rax
pushq %rbp
pushq $0x3
callq 0xc11b
addq $0x20, %rsp
movq %rax, %r13
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
movl $0x1, %r12d
pushq %r12
callq 0xb13c
addq $0x10, %rsp
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x20, %ecx
movq $-0x1, %r8
callq 0xb1f1
movq 0x10(%rbx), %rdx
subq $0x8, %rsp
movq %r15, %rdi
movq %r13, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
movl $0x2, %r9d
xorl %eax, %eax
pushq %rax
pushq $0x4
pushq %rbp
pushq %r12
pushq %rax
callq 0xaad4
addq $0x30, %rsp
testq %rax, %rax
je 0x12424
movq 0x10(%rbx), %rsi
leaq 0x10e18(%rip), %rdi     # 0x23235
xorl %eax, %eax
callq 0x52b0
movq 0x10(%rbx), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0xa728
movq %rax, %r14
testq %rax, %rax
jne 0x12450
movq 0x10(%rbx), %rsi
leaq 0x10e3c(%rip), %rdi     # 0x23282
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x52b0
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq