// File: /workspace/github_c_makefile_star2_O1/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 $0x88, %rsp
movl %r9d, %ebx
movq %r8, %r15
movl %ecx, 0x8(%rsp)
movq %rdi, 0x40(%rsp)
movl 0xc8(%rsp), %ebp
movq 0xc0(%rsp), %r12
movq 0x10(%rsi), %r14
movq %rdx, 0x60(%rsp)
movq %rdx, %rdi
callq 0x695d
movl %eax, 0x2c(%rsp)
movq %r12, 0x18(%rsp)
testq %r12, %r12
movq %r14, 0x50(%rsp)
je 0x1ba71
movq 0x28(%r14), %rax
movl %ebx, %r12d
cmpq %r15, %rax
ja 0x1b418
leaq (%r15,%r12), %rcx
addq 0x30(%r14), %rax
cmpq %rax, %rcx
jbe 0x1b433
movq 0x10(%r14), %rsi
movq 0x20(%r14), %rcx
leaq 0x94f7(%rip), %rdx      # 0x2491e
movl $0x55, %edi
xorl %eax, %eax
callq 0x6f84
testb $0x7, %r12b
je 0x1b45a
movq 0x10(%r14), %rsi
movq 0x20(%r14), %rcx
leaq 0x94d6(%rip), %rdx      # 0x2491e
movl $0x8, %r8d
movl $0x56, %edi
xorl %eax, %eax
callq 0x6f84
cmpl $0x8, %ebx
jb 0x1ba9f
shrl $0x3, %r12d
andl $0x3ff0000, 0x2c(%rsp)  # imm = 0x3FF0000
movq 0x60(%rsp), %rax
leaq 0x1c(%rax), %rcx
movq %rcx, 0x78(%rsp)
movl %ebp, %ecx
movq %rcx, 0x70(%rsp)
leaq 0x4(%rax), %rcx
movq %rcx, 0x58(%rsp)
addq $0x8, %rax
movq %rax, 0x68(%rsp)
movq %r12, 0x80(%rsp)
movb %al, 0x38(%rsp)
movq %r15, 0x48(%rsp)
leaq 0x4(%r15), %r14
movl 0x8(%rsp), %ebx
movl %ebx, %edi
movq %r14, %rsi
xorl %edx, %edx
movl $0x18, %ecx
callq 0x6b38
movl %eax, 0x34(%rsp)
movl %ebx, %edi
movq %r14, %rsi
movl $0x19, %edx
movl $0x2, %ecx
callq 0x6b38
movl %eax, 0xc(%rsp)
movl %ebx, %edi
movq %r14, %rsi
movl $0x18, %edx
movl $0x1, %ecx
callq 0x6b38
movl %eax, 0x10(%rsp)
movl %ebx, %edi
movq %r14, %rsi
movl $0x1c, %edx
movl $0x1, %ecx
callq 0x6b38
movl %eax, %r13d
movl %ebx, %edi
movq %r14, %rsi
movl $0x1d, %edx
movl $0x1, %ecx
callq 0x6b38
movl %eax, %r15d
movl %ebx, %edi
movq %r14, %rsi
movl $0x1e, %edx
movl $0x1, %ecx
callq 0x6b38
movl %eax, %ebp
movl %ebx, %edi
movq %r14, %rsi
movl $0x1f, %edx
movl $0x1, %ecx
callq 0x6b38
movl %eax, %r12d
movl %ebx, %edi
movq %r14, %rsi
movl $0x1b, %edx
movl $0x1, %ecx
callq 0x6b38
movq %rbp, %r11
movl 0xc(%rsp), %ebp
movl 0x10(%rsp), %ecx
movl %eax, %ebx
movl %ecx, %eax
orl %r13d, %eax
movl %r15d, %edx
orl %r11d, %edx
orl %eax, %edx
movb $0x1, %sil
orl %r12d, %edx
movslq %ebp, %r14
je 0x1b65a
movl %r13d, %eax
orl %r15d, %eax
testl %ecx, %ecx
sete %sil
movl %eax, %edx
orl %r11d, %edx
orl %r12d, %edx
setne %dl
orb %sil, %dl
movb $0x2, %sil
cmpb $0x1, %dl
jne 0x1b65a
movl %ecx, %esi
orl %r15d, %esi
testl %r13d, %r13d
sete %dl
orl %r11d, %esi
orl %r12d, %esi
setne %dil
orb %dl, %dil
movb $0xa, %sil
cmpb $0x1, %dil
jne 0x1b65a
testl %r12d, %r12d
setne %sil
movl %ecx, %edx
orl 0x2c(%rsp), %edx
orl %eax, %edx
orl %r11d, %edx
xorl $0x2, %ebp
orl %edx, %ebp
sete %al
andb %sil, %al
cmpb $0x1, %al
jne 0x1b612
movb $0x11, %sil
movq 0x40(%rsp), %rax
cmpb $0x0, 0x202(%rax)
jns 0x1b65a
movb $0x1, 0x202(%rax)
jmp 0x1b65a
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %rdx
leaq 0x92f0(%rip), %rax      # 0x24916
movzwl (%rax,%r14,2), %r8d
subq $0x8, %rsp
leaq 0x92f1(%rip), %rdi      # 0x24927
movl %ebx, %r9d
xorl %eax, %eax
movq 0x20(%rsp), %r10
pushq 0x20(%r10)
pushq %r12
pushq %r11
pushq %r15
pushq %r13
callq 0x52b0
addq $0x30, %rsp
movb 0x38(%rsp), %sil
leaq 0x92b5(%rip), %rax      # 0x24916
movzwl (%rax,%r14,2), %r14d
movl 0x8(%rsp), %edi
movq 0x48(%rsp), %r15
movl %esi, %r12d
movq %r15, %rsi
callq 0x69b3
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rbp
movq 0x10(%rbp), %rdx
movq %rdx, 0x38(%rsp)
movl %eax, %eax
movq 0x40(%rcx), %rdx
movq %rax, 0x10(%rsp)
addq %rax, %rdx
movzwl %r14w, %r8d
movb %r12b, 0xc(%rsp)
movzbl %r12b, %r12d
movq 0x40(%rsp), %r14
movq %r14, %rdi
movl %r12d, %esi
xorl %ecx, %ecx
movl %r8d, 0x30(%rsp)
movq $-0x1, %r9
callq 0xb4bf
movq %rax, %r13
cmpb $0x11, %r12b
jne 0x1b6e2
roll $0x10, %r13d
movq %r13, %rdi
movl $0x20, %esi
callq 0x6f17
movq %rax, %r13
movq %r12, 0x20(%rsp)
testl %ebx, %ebx
je 0x1b7dc
movq 0x60(%rsp), %r12
movq %r12, %rdi
movl 0x8(%rsp), %r14d
movl %r14d, %esi
callq 0x1d900
movl %eax, %r15d
addq %r12, %r15
movq %r12, %rdi
movl %r14d, %esi
callq 0x1c5b2
movl %eax, %ebx
movl %r14d, %edi
movq 0x78(%rsp), %rsi
callq 0x69b3
addl %ebx, %eax
addq %r12, %rax
movl 0x34(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,4), %r12
movl %r14d, %edi
movq %r12, %rsi
callq 0x69b3
movl %eax, %ebx
addq %r15, %rbx
movq 0x70(%rsp), %rax
movq 0x10(%rsp), %rcx
addq %rcx, %rax
movb 0xc(%rsp), %dl
cmpb $0x2, %dl
movl $0x0, %ecx
cmovneq %rcx, %rax
cmpb $0x1, 0x4(%r12)
jne 0x1b872
addq %rax, %r13
cmpb $0x11, %dl
movq 0x48(%rsp), %r15
movq 0x40(%rsp), %r14
jne 0x1b89d
movq %r14, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x10(%rsp), %rbp
movq %rbp, %r9
pushq %r13
movl $0x1, %eax
pushq %rax
callq 0xb202
addq $0x10, %rsp
movl $0xffff, %r8d           # imm = 0xFFFF
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x10, %ecx
callq 0xb2b7
leal 0x2(%rbp), %r9d
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
jmp 0x1b9f0
movl 0x34(%rsp), %r12d
testl $0xffffffe1, %r12d      # imm = 0xFFFFFFE1
je 0x1b814
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %r8
movl $0x5c, %edi
movl %r12d, %edx
movq 0x10(%rsp), %r9
xorl %eax, %eax
callq 0x6f84
andl $0x1e, %r12d
cmpl $0x8, %r12d
je 0x1b901
cmpl $0x6, %r12d
je 0x1b8c0
cmpl $0x4, %r12d
jne 0x1b956
movq %rbp, %rdi
movl $0x1, %esi
movl $0x5, %edx
callq 0xbe23
movq %rax, %rbx
xorl %ebp, %ebp
testq %rax, %rax
jne 0x1b972
xorl %ebp, %ebp
leaq 0x91e9(%rip), %rdi      # 0x24a48
leaq 0x91d0(%rip), %rsi      # 0x24a36
xorl %eax, %eax
callq 0x52b0
jmp 0x1b972
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rcx
movl $0x5b, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6f84
movq 0x48(%rsp), %r15
jmp 0x1ba56
movq %r14, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq 0x10(%rsp), %r9
pushq %r13
pushq 0x28(%rsp)
jmp 0x1ba35
movq %rbp, %rdi
movl $0x2, %esi
movl $0x3, %edx
callq 0xbe23
movq %rax, %rbx
testq %rax, %rax
jne 0x1b8ef
leaq 0x9182(%rip), %rdi      # 0x24a63
leaq 0x914e(%rip), %rsi      # 0x24a36
xorl %eax, %eax
callq 0x52b0
movl 0x8(%rsp), %edi
movq 0x58(%rsp), %rsi
callq 0x69b3
movl %eax, %ebp
jmp 0x1b972
movq %rbp, %rdi
movl $0x3, %esi
movl $0x3, %edx
callq 0xbe23
movq %rax, %rbx
testq %rax, %rax
jne 0x1b930
leaq 0x915c(%rip), %rdi      # 0x24a7e
leaq 0x910d(%rip), %rsi      # 0x24a36
xorl %eax, %eax
callq 0x52b0
movl 0x8(%rsp), %ebp
movl %ebp, %edi
movq 0x58(%rsp), %rsi
callq 0x69b3
movl %eax, %r12d
movl %ebp, %edi
movq 0x68(%rsp), %rsi
callq 0x69b3
movl %eax, %ebp
addl %r12d, %ebp
jmp 0x1b972
xorl %ebx, %ebx
leaq 0x9139(%rip), %rdi      # 0x24a98
leaq 0x90d0(%rip), %rsi      # 0x24a36
movl %r12d, %edx
xorl %eax, %eax
callq 0x52b0
xorl %ebp, %ebp
movq 0x20(%rsp), %r10
movb 0xc(%rsp), %cl
cmpb $0x11, %cl
je 0x1b98c
cmpl $0x2, %r10d
je 0x1b993
cmpl $0x1, %r10d
jne 0x1b998
movl %ebp, %eax
subq %rax, %r13
jmp 0x1b998
addq 0x10(%rsp), %r13
cmpb $0x11, %cl
jne 0x1ba19
movq %r14, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
xorl %edx, %edx
movq %rbx, %rcx
xorl %r8d, %r8d
movq 0x10(%rsp), %rbp
movq %rbp, %r9
pushq %r13
movl $0x1, %eax
pushq %rax
callq 0xb202
addq $0x10, %rsp
movl $0xffff, %r8d           # imm = 0xFFFF
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x10, %ecx
callq 0xb2b7
leal 0x2(%rbp), %r9d
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rbx, %rcx
xorl %r8d, %r8d
pushq %r13
movl $0x1, %eax
pushq %rax
callq 0xb202
addq $0x10, %rsp
movl $0xffff0000, %r8d       # imm = 0xFFFF0000
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x10, %ecx
jmp 0x1ba51
movq %r14, %rdi
movq 0x18(%rsp), %r14
movq %r14, %rsi
xorl %edx, %edx
movq %rbx, %rcx
xorl %r8d, %r8d
movq 0x10(%rsp), %r9
pushq %r13
pushq %r10
callq 0xb202
addq $0x10, %rsp
movq %r14, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl 0x30(%rsp), %ecx
movq $-0x1, %r8
callq 0xb2b7
addq $0x8, %r15
movq 0x80(%rsp), %r12
decq %r12
movb 0xc(%rsp), %al
jne 0x1b496
jmp 0x1ba9f
testl %ebx, %ebx
je 0x1ba9f
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x20(%rax), %rdx
movl $0x59, %edi
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6f84
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq