// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_aout.c
// Function: aoutstd_relocs
void aoutstd_relocs(struct GlobalVars *gv,struct ObjectUnit *ou,
                    struct aout_hdr *hdr,int be,
                    struct relocation_info *reloc,uint32_t rsize,
                    struct Section *sec,uint32_t saddr)
/* reads all relocations in standard format for a section */
{
  static uint16_t bsize[4] = { 8,16,32,64 };
  struct LinkFile *lf = ou->lnkfile;
  uint32_t mid = GETMID(hdr);

  if (sec) {
    int i;

    if (((uint8_t *)reloc < lf->data) ||
        (((uint8_t *)reloc)+rsize > lf->data + lf->length))
      error(85,lf->pathname,"stdreloc",lf->objname);  /* illegal offset */

    if (rsize % sizeof(struct relocation_info) != 0)  /* reloc sanity check */
      error(86,lf->pathname,"stdreloc",lf->objname,
            sizeof(struct relocation_info));

    for (i=0; i<(rsize/sizeof(struct relocation_info)); i++,reloc++) {
      uint32_t *info = &reloc->r_info;
      uint32_t symnum = readbf32(be,info,RELB_symbolnum,RELS_symbolnum);
      int size = readbf32(be,info,RSTDB_length,RSTDS_length);
      int pcrel = readbf32(be,info,RSTDB_pcrel,RSTDS_pcrel);
      int baserel = readbf32(be,info,RSTDB_baserel,RSTDS_baserel);
      int jmptable = readbf32(be,info,RSTDB_jmptable,RSTDS_jmptable);
      int relative = readbf32(be,info,RSTDB_relative,RSTDS_relative);
      int copy = readbf32(be,info,RSTDB_copy,RSTDS_copy);
      int xtern = readbf32(be,info,RSTDB_extern,RSTDS_extern);
      uint8_t rtype;

      if (!pcrel && !baserel && !jmptable && !relative && !copy) {
        rtype = R_ABS;
      }
      else if (pcrel && !baserel && !jmptable && !relative && !copy) {
        rtype = R_PC;
      }
      else if (baserel && !pcrel && !jmptable && !relative && !copy) {
        rtype = R_SD;
      }
      else if (!mid && !pcrel && !baserel && !jmptable && !relative &&
               copy && size==2) {
        /* MID 0 and 32-bit COPY reloc may indicate a Jaguar GPU
           MOVEI RISC-instruction, which has swapped 16-bit words */
        rtype = R_AOUT_MOVEI;
        if (gv->endianess < 0)
          gv->endianess = _BIG_ENDIAN_;  /* Jaguar is big-endian */
      }
      else
        ierror("aoutstd_relocs(): %s (%s): Reloc type "
               "<pcrel=%d len=%d extern=%d baserel=%d jmptab=%d "
               "rel=%d copy=%d> in %s is currently not supported",
               lf->pathname,lf->objname,pcrel,bsize[size],xtern,baserel,
               jmptable,relative,copy,sec->name);

      if (rtype) {
        /* create a.out relocation */
        aout_newreloc(gv,hdr,sec,saddr,symnum,xtern!=0,rtype,bsize[size],
                      read32(be,&reloc->r_address),be);
      }
      else {
        /* illegal a.out relocation */
        error(90,lf->pathname,sec->name,lf->objname,
              (uint32_t)read32(be,&reloc->r_address),pcrel,size,xtern,
              baserel,jmptable,relative,copy);
      }
    }
  }

  else if (rsize) {
    /* no section for these relocations! */
    error(89,lf->pathname,lf->objname);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, %ebx
movq %r8, %r14
movl %ecx, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
movl 0xb8(%rsp), %ebp
movq 0xb0(%rsp), %r12
movq 0x10(%rsi), %r15
movq %rdx, 0x50(%rsp)
movq %rdx, %rdi
callq 0x6607
movl %eax, 0x34(%rsp)
movq %r12, 0x10(%rsp)
testq %r12, %r12
je 0x1a171
movq 0x28(%r15), %rax
movl %ebx, %ebx
cmpq %r14, %rax
ja 0x19b4b
leaq (%r14,%rbx), %rcx
addq 0x30(%r15), %rax
cmpq %rax, %rcx
jbe 0x19b64
movq 0x10(%r15), %rsi
movq 0x20(%r15), %rcx
leaq 0x89d4(%rip), %rdx      # 0x2252e
pushq $0x55
popq %rdi
xorl %eax, %eax
callq 0x6c19
testb $0x7, %bl
je 0x19b86
movq 0x10(%r15), %rsi
movq 0x20(%r15), %rcx
leaq 0x89b6(%rip), %rdx      # 0x2252e
pushq $0x56
popq %rdi
pushq $0x8
popq %r8
xorl %eax, %eax
callq 0x6c19
shrl $0x3, %ebx
andl $0x3ff0000, 0x34(%rsp)  # imm = 0x3FF0000
movl %ebp, %eax
movq %rax, 0x68(%rsp)
movq 0x50(%rsp), %rax
leaq 0x4(%rax), %rcx
movq %rcx, 0x48(%rsp)
addq $0x8, %rax
movq %rax, 0x60(%rsp)
movq %r15, 0x58(%rsp)
subq $0x1, %rbx
jb 0x1a195
movb %bpl, 0xc(%rsp)
movq %rbx, 0x70(%rsp)
movq %r14, 0x40(%rsp)
leaq 0x4(%r14), %rbx
movl 0x8(%rsp), %r13d
movl %r13d, %edi
movq %rbx, %rsi
xorl %edx, %edx
pushq $0x18
popq %rbp
movl %ebp, %ecx
callq 0x673d
movl %eax, 0x20(%rsp)
movl %r13d, %edi
movq %rbx, %rsi
pushq $0x19
popq %rdx
pushq $0x2
popq %rcx
callq 0x673d
movl %eax, 0x28(%rsp)
movl %r13d, %edi
movq %rbx, %rsi
movl %ebp, %edx
pushq $0x1
popq %r15
movl %r15d, %ecx
callq 0x673d
movl %eax, 0x4(%rsp)
movl %r13d, %edi
movq %rbx, %rsi
pushq $0x1c
popq %rdx
movl %r15d, %ecx
callq 0x673d
movl %eax, %ebp
movl %r13d, %edi
movq %rbx, %rsi
pushq $0x1d
popq %rdx
movl %r15d, %ecx
callq 0x673d
movl %eax, %r14d
movl %r13d, %edi
movq %rbx, %rsi
pushq $0x1e
popq %rdx
movl %r15d, %ecx
callq 0x673d
movl %eax, %r12d
movl %r13d, %edi
movq %rbx, %rsi
pushq $0x1f
popq %rdx
movl %r15d, %ecx
callq 0x673d
movl %r13d, %edi
movq %rax, %r13
movq %rbx, %rsi
pushq $0x1b
popq %rdx
movl %r15d, %ecx
callq 0x673d
movl 0x28(%rsp), %edi
movl 0x4(%rsp), %ecx
movq %rbp, %r11
movl %eax, %r15d
movl %ecx, %eax
orl %r11d, %eax
movl %r14d, %edx
orl %r12d, %edx
orl %eax, %edx
movb $0x1, %bpl
orl %r13d, %edx
movslq %edi, %rbx
je 0x19d71
movl %r11d, %eax
orl %r14d, %eax
testl %ecx, %ecx
sete %sil
movl %eax, %edx
orl %r12d, %edx
orl %r13d, %edx
setne %dl
orb %sil, %dl
movb $0x2, %bpl
cmpb $0x1, %dl
jne 0x19d71
movl %ecx, %esi
orl %r14d, %esi
testl %r11d, %r11d
sete %dl
orl %r12d, %esi
orl %r13d, %esi
setne %sil
orb %dl, %sil
movb $0xa, %bpl
cmpb $0x1, %sil
jne 0x19d71
testl %r13d, %r13d
setne %sil
movl %ecx, %edx
orl 0x34(%rsp), %edx
orl %eax, %edx
orl %r12d, %edx
xorl $0x2, %edi
orl %edx, %edi
sete %al
andb %sil, %al
cmpb $0x1, %al
jne 0x19d29
movq 0x18(%rsp), %rax
cmpb $0x0, 0x202(%rax)
jns 0x19d24
movb $0x1, 0x202(%rax)
movb $0x11, %bpl
jmp 0x19d71
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %rdx
leaq 0x87e9(%rip), %rax      # 0x22526
movzwl (%rax,%rbx,2), %r8d
subq $0x8, %rsp
leaq 0x87ea(%rip), %rdi      # 0x22537
movl %r15d, %r9d
xorl %eax, %eax
movq 0x18(%rsp), %r10
pushq 0x20(%r10)
pushq %r13
pushq %r12
pushq %r14
pushq %r11
callq 0x6b2c
addq $0x30, %rsp
movb 0xc(%rsp), %bpl
leaq 0x87ae(%rip), %rax      # 0x22526
movzwl (%rax,%rbx,2), %ebx
movl 0x8(%rsp), %edi
movq 0x40(%rsp), %r14
movq %r14, %rsi
callq 0x664d
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %r12
movq 0x10(%r12), %r13
movl %eax, %eax
movq 0x40(%rcx), %rdx
movq %rax, 0x28(%rsp)
addq %rax, %rdx
movzwl %bx, %r8d
movzbl %bpl, %ebx
movq 0x18(%rsp), %rdi
movl %ebx, %esi
xorl %ecx, %ecx
movl %r8d, 0xc(%rsp)
pushq $-0x1
popq %r9
callq 0xae9b
movq %rax, %r10
cmpb $0x11, %bl
jne 0x19de2
roll $0x10, %r10d
movq %r10, %rdi
pushq $0x20
popq %rsi
callq 0x6ad8
movq %rax, %r10
testl %r15d, %r15d
je 0x19eef
movq %r10, %r15
movq %rbx, 0x38(%rsp)
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl 0x8(%rsp), %r12d
movl %r12d, %esi
callq 0x1be42
movb %bpl, 0x4(%rsp)
movl %eax, %ebp
addq %rbx, %rbp
movq %rbx, %rdi
movl %r12d, %esi
callq 0x1be67
movl %eax, %r14d
addq %rbx, %r14
movl 0x20(%rsp), %eax
imulq $0xc, %rax, %rbx
leaq (%r14,%rbx), %rsi
movl %r12d, %edi
callq 0x664d
movl %eax, %r12d
addq %rbp, %r12
movb 0x4(%rsp), %bpl
movq 0x68(%rsp), %rax
movq 0x28(%rsp), %r9
addq %r9, %rax
cmpb $0x2, %bpl
movl $0x0, %ecx
cmovneq %rcx, %rax
cmpb $0x1, 0x4(%rbx,%r14)
jne 0x19f65
cmpb $0x11, %bpl
movq 0x40(%rsp), %r14
jne 0x19f89
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %r13
movq %r13, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r9, %rbp
pushq %r15
pushq $0x1
popq %rax
pushq %rax
callq 0xabec
popq %rcx
popq %rdx
movl $0xffff, %r8d           # imm = 0xFFFF
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
pushq $0x10
popq %rcx
callq 0xac9f
leal 0x2(%rbp), %r9d
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq %r15
pushq $0x1
popq %rax
pushq %rax
movb 0x14(%rsp), %bpl
callq 0xabec
popq %rcx
popq %rdx
movl $0xffff0000, %r8d       # imm = 0xFFFF0000
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
pushq $0x10
popq %rcx
jmp 0x1a15e
movl 0x20(%rsp), %edx
testl $0xffffffe1, %edx       # imm = 0xFFFFFFE1
je 0x19f29
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x10(%r13), %rsi
movq 0x20(%r13), %r8
pushq $0x5c
popq %rdi
movl 0x20(%rsp), %edx
movq 0x28(%rsp), %r9
xorl %eax, %eax
movq %r10, %r15
callq 0x6c19
movq %r15, %r10
movl 0x20(%rsp), %edx
andl $0x1e, %edx
movq %r10, %r15
cmpl $0x8, %edx
je 0x19fea
cmpl $0x6, %edx
je 0x19fac
cmpl $0x4, %edx
jne 0x1a046
movq %r12, %rdi
pushq $0x1
popq %rsi
pushq $0x5
popq %rdx
callq 0xb758
testq %rax, %rax
je 0x1a060
movq %rax, %r12
jmp 0x1a078
movq 0x10(%r13), %rsi
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rcx
pushq $0x5b
popq %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x6c19
movq 0x40(%rsp), %r14
jmp 0x1a163
addq %rax, %r15
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
pushq %r15
pushq 0x40(%rsp)
jmp 0x1a147
movq %r12, %rdi
pushq $0x2
popq %rsi
pushq $0x3
popq %rdx
callq 0xb758
movq %rax, %r12
testq %rax, %rax
jne 0x19fd7
leaq 0x86aa(%rip), %rdi      # 0x22673
leaq 0x8676(%rip), %rsi      # 0x22646
xorl %eax, %eax
callq 0x6b2c
movl 0x8(%rsp), %edi
movq 0x48(%rsp), %rsi
callq 0x664d
jmp 0x1a07a
movq %rbx, 0x38(%rsp)
movl %ebp, %r13d
movq %r12, %rdi
pushq $0x3
popq %rdx
movl %edx, %esi
callq 0xb758
movq %rax, %r12
testq %rax, %rax
jne 0x1a01c
leaq 0x8680(%rip), %rdi      # 0x2268e
leaq 0x8631(%rip), %rsi      # 0x22646
xorl %eax, %eax
callq 0x6b2c
movl 0x8(%rsp), %ebx
movl %ebx, %edi
movq 0x48(%rsp), %rsi
callq 0x664d
movl %eax, %ebp
movl %ebx, %edi
movq 0x60(%rsp), %rsi
callq 0x664d
addl %ebp, %eax
movl %r13d, %ebp
movq 0x38(%rsp), %rbx
jmp 0x1a07a
xorl %r12d, %r12d
leaq 0x8658(%rip), %rdi      # 0x226a8
leaq 0x85ef(%rip), %rsi      # 0x22646
xorl %eax, %eax
callq 0x6b2c
jmp 0x1a078
xorl %r12d, %r12d
leaq 0x85ee(%rip), %rdi      # 0x22658
leaq 0x85d5(%rip), %rsi      # 0x22646
xorl %eax, %eax
callq 0x6b2c
xorl %eax, %eax
cmpb $0x11, %bpl
movq 0x28(%rsp), %r9
je 0x1a093
cmpl $0x2, %ebx
je 0x1a129
cmpl $0x1, %ebx
jne 0x1a098
movl %eax, %eax
subq %rax, %r15
cmpb $0x11, %bpl
jne 0x1a124
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rcx
movq %r12, 0x20(%rsp)
movq 0x10(%rsp), %r12
movq %r12, %rsi
xorl %edx, %edx
xorl %r8d, %r8d
movq %r9, %r13
pushq %r15
pushq $0x1
popq %rax
pushq %rax
callq 0xabec
popq %rcx
popq %rdx
movl $0xffff, %r8d           # imm = 0xFFFF
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
movb %bpl, 0x4(%rsp)
pushq $0x10
popq %rbp
movl %ebp, %ecx
callq 0xac9f
leal 0x2(%r13), %r9d
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq 0x20(%rsp), %rcx
xorl %r8d, %r8d
pushq %r15
pushq $0x1
popq %rax
pushq %rax
callq 0xabec
popq %rcx
popq %rdx
movl $0xffff0000, %r8d       # imm = 0xFFFF0000
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl %ebp, %ecx
movb 0x4(%rsp), %bpl
jmp 0x1a15e
movq %rbx, %rax
jmp 0x1a12f
movq %rbx, %rax
addq %r9, %r15
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rsi
xorl %edx, %edx
movq %r12, %rcx
xorl %r8d, %r8d
pushq %r15
pushq %rax
callq 0xabec
popq %rcx
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl 0xc(%rsp), %ecx
pushq $-0x1
popq %r8
callq 0xac9f
addq $0x8, %r14
movq 0x70(%rsp), %rbx
jmp 0x19bb4
testl %ebx, %ebx
je 0x1a195
movq 0x10(%r15), %rsi
movq 0x20(%r15), %rdx
pushq $0x59
popq %rdi
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c19
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq