// File: /workspace/github_c_makefile_star2_O2/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 0x1151d
movq %rsi, %r14
movq 0x10(%rbx), %r12
leaq 0x1e21a(%rip), %rdi     # 0x2f728
pushq $0x2
popq %rdx
movq %r12, %rsi
callq 0x5070
testl %eax, %eax
je 0x11536
movq %r15, %rdi
movq %rbx, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10ea5
addq $0x2, %r12
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0xaa79
testq %rax, %rax
je 0x1151d
movq %r12, %rdi
callq 0x50e0
leaq 0x3(%rax), %rdi
callq 0x6340
movq %rax, %r13
pushq $0x4
popq %rdi
callq 0x638a
movq %rax, %rbp
leaq 0xfcc7(%rip), %rsi      # 0x2123a
movq %r13, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x5260
movq %r15, %rdi
movq %r13, %rsi
movq %rbp, %rdx
pushq $0x4
popq %r13
movq %r13, %rcx
callq 0xb906
subq $0x8, %rsp
pushq $0x2
popq %r8
leaq 0xfc9b(%rip), %rsi      # 0x2123f
pushq $0x1
popq %r9
movq %rax, %rdi
movq %rbp, %rdx
movq %r13, %rcx
pushq $0x0
pushq %r8
movq %r8, %r13
pushq $0x3
callq 0xbab3
addq $0x20, %rsp
movq %rax, %rbp
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq $0x0
pushq $0x1
popq %r12
pushq %r12
callq 0xabec
addq $0x10, %rsp
pushq $0x20
popq %rcx
pushq $-0x1
popq %r8
movq %rbp, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0xac9f
movq 0x10(%rbx), %rdx
subq $0x8, %rsp
movq %r15, %rdi
movq %rbp, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
movl %r13d, %r9d
pushq $0x0
pushq $0x4
pushq %r13
pushq %r12
pushq $0x0
callq 0xa5d5
addq $0x30, %rsp
testq %rax, %rax
je 0x1163c
movq 0x10(%rbx), %rsi
leaq 0xfc10(%rip), %rdi      # 0x21245
xorl %eax, %eax
callq 0x6b2c
movq 0x10(%rbx), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0xa220
movq %rax, %r14
testq %rax, %rax
jne 0x11668
movq 0x10(%rbx), %rsi
leaq 0xfc34(%rip), %rdi      # 0x21292
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x6b2c
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq