// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_elf32arm.c
// Function: armle_reloc_vlink2elf
static uint8_t armle_reloc_vlink2elf(struct Reloc *r)
/* Try to map vlink-internal representation to a valid ELF reloc type */
{
  struct RelocInsert *ri;

  if (ri = r->insert) {
    int pos = (int)ri->bpos;
    int size = (int)ri->bsiz;
    lword mask = ri->mask;
    struct RelocInsert *ri2 = ri->next;

    switch (r->rtype) {
      case R_ABS:
        if (!(pos&7) && mask==-1 && !ri2) {
          switch (size) {
            case 32: return R_ARM_ABS32;
            case 16: return R_ARM_ABS16;
            case 8: return R_ARM_ABS8;
          }
        }
        else if (size==24 && (pos&31)==8 && mask==0xffffff && !ri2)
          return R_ARM_SWI24; /* @@@ obsolete */
        else if (size==12 && (pos&31)==20 && mask==0xfff && !ri2)
          return R_ARM_ABS12;
        else if (size==8 && (pos&15)==8 && mask==0xff && !ri2)
          return R_ARM_THM_SWI8; /* @@@ obsolete */
        else if (size==5 && (pos&15)==5 && mask==0x1f && !ri2)
          return R_ARM_THM_ABS5;
        break;

      case R_PC:
        if (size==32 && !(pos&7) && mask==-1 && !ri2)
          return R_ARM_REL32;
        else if (size==24 && (pos&31)==8 && mask==0x3fffffc && !ri2)
          return R_ARM_PC24;  /* @@@ deprecated: use R_ARM_CALL/JUMP24!!! */
        else if (size==12 && (pos&31)==20 && mask==0x1fff && !ri2)
          return R_ARM_LDR_PC_G0;
        else if (size==8 && (pos&31)==24 && mask==0xff && !ri2)
          return R_ARM_ALU_PCREL_7_0;  /* @@@ obsolete */
        else if (size==8 && (pos&31)==24 && mask==0xff00 && !ri2)
          return R_ARM_ALU_PCREL_15_8;  /* @@@ obsolete */
        else if (size==8 && (pos&31)==24 && mask==0xff0000 && !ri2)
          return R_ARM_ALU_PCREL_23_15;  /* @@@ obsolete */
        else if (size==8 && (pos&15)==8 && mask==0x3fc && !ri2)
          return R_ARM_THM_PC8;
        else if (size==11 && (pos&15)==5 && ri2) {
          if (ri2->bsiz==11 && (ri2->bpos&15)==5) {
            if ((mask==0x7ff000 && ri2->mask==0xffe) ||
                (mask==0xffe && ri2->mask==0x7ff000))
              return R_ARM_THM_CALL;
          }
        }
        break;
    }
  }

  return R_NONE;
}

// Assembly:
movq 0x30(%rdi), %rcx
testq %rcx, %rcx
je 0x19913
movzwl 0x8(%rcx), %esi
movzwl 0xa(%rcx), %eax
movq (%rcx), %rdx
movq 0x10(%rcx), %rcx
movzbl 0x38(%rdi), %edi
cmpl $0x2, %edi
je 0x196d3
cmpl $0x1, %edi
jne 0x19913
testb $0x7, %sil
setne %dil
cmpq $-0x1, %rcx
setne %r8b
orb %dil, %r8b
testq %rdx, %rdx
setne %dil
orb %r8b, %dil
je 0x1971e
cmpl $0x5, %eax
je 0x198f1
cmpl $0x8, %eax
je 0x198a4
cmpl $0xc, %eax
je 0x198cb
cmpl $0x18, %eax
jne 0x19913
testq %rdx, %rdx
setne %al
andl $0x1f, %esi
cmpl $0x8, %esi
setne %dl
cmpq $0xffffff, %rcx         # imm = 0xFFFFFF
setne %cl
orb %al, %cl
orb %dl, %cl
movb $0xd, %al
jne 0x19913
jmp 0x1973b
cmpl $0x8, %eax
je 0x197f5
cmpl $0xb, %eax
je 0x1973c
cmpl $0xc, %eax
je 0x197cb
cmpl $0x18, %eax
je 0x197a1
cmpl $0x20, %eax
jne 0x19913
testb $0x7, %sil
setne %al
cmpq $-0x1, %rcx
setne %cl
orb %al, %cl
testq %rdx, %rdx
setne %al
orb %cl, %al
movb $0x3, %al
jne 0x19913
jmp 0x1973b
cmpl $0x8, %eax
je 0x198a1
cmpl $0x20, %eax
je 0x1989e
cmpl $0x10, %eax
jne 0x19913
movb $0x5, %al
retq
andl $0xf, %esi
cmpl $0x5, %esi
sete %al
testq %rdx, %rdx
setne %sil
andb %al, %sil
cmpb $0x1, %sil
jne 0x19913
cmpw $0xb, 0xa(%rdx)
jne 0x19913
movzwl 0x8(%rdx), %eax
andl $0xf, %eax
cmpw $0x5, %ax
jne 0x19913
cmpq $0xffe, %rcx            # imm = 0xFFE
je 0x19916
cmpq $0x7ff000, %rcx         # imm = 0x7FF000
jne 0x19913
movb $0xa, %al
cmpq $0xffe, 0x10(%rdx)      # imm = 0xFFE
jne 0x19913
jmp 0x1973b
andl $0x1f, %esi
cmpl $0x8, %esi
setne %al
cmpq $0x3fffffc, %rcx        # imm = 0x3FFFFFC
setne %cl
testq %rdx, %rdx
setne %dl
orb %cl, %dl
orb %al, %dl
movb $0x1, %al
jne 0x19913
jmp 0x1973b
andl $0x1f, %esi
cmpl $0x14, %esi
setne %al
cmpq $0x1fff, %rcx           # imm = 0x1FFF
setne %cl
testq %rdx, %rdx
setne %dl
orb %cl, %dl
orb %al, %dl
movb $0x4, %al
jne 0x19913
jmp 0x1973b
movl %esi, %edi
andl $0x1f, %edi
cmpl $0x18, %edi
setne %al
cmpq $0xff, %rcx
setne %r8b
testq %rdx, %rdx
setne %r9b
orb %r8b, %r9b
orb %al, %r9b
movb $0x20, %al
cmpb $0x1, %r9b
jne 0x1973b
testq %rdx, %rdx
setne %al
cmpl $0x18, %edi
setne %r8b
cmpq $0xff00, %rcx           # imm = 0xFF00
setne %r9b
orb %al, %r9b
orb %r8b, %r9b
movb $0x21, %al
cmpb $0x1, %r9b
jne 0x1973b
testq %rdx, %rdx
setne %al
cmpl $0x18, %edi
setne %dil
cmpq $0xff0000, %rcx         # imm = 0xFF0000
setne %r8b
orb %al, %r8b
orb %dil, %r8b
movb $0x22, %al
cmpb $0x1, %r8b
jne 0x1973b
testq %rdx, %rdx
setne %al
andl $0xf, %esi
cmpl $0x8, %esi
setne %dl
cmpq $0x3fc, %rcx            # imm = 0x3FC
setne %cl
orb %al, %cl
orb %dl, %cl
movb $0xb, %al
jne 0x19913
jmp 0x1973b
movb $0x2, %al
retq
movb $0x8, %al
retq
testq %rdx, %rdx
setne %al
andl $0xf, %esi
cmpl $0x8, %esi
setne %dl
cmpq $0xff, %rcx
setne %cl
orb %al, %cl
orb %dl, %cl
movb $0xe, %al
je 0x1973b
jmp 0x19913
testq %rdx, %rdx
setne %al
andl $0x1f, %esi
cmpl $0x14, %esi
setne %dl
cmpq $0xfff, %rcx            # imm = 0xFFF
setne %cl
orb %al, %cl
orb %dl, %cl
movb $0x6, %al
jne 0x19913
jmp 0x1973b
testq %rdx, %rdx
setne %al
andl $0xf, %esi
cmpl $0x5, %esi
setne %dl
cmpq $0x1f, %rcx
setne %cl
orb %al, %cl
orb %dl, %cl
movb $0x7, %al
je 0x1973b
xorl %eax, %eax
retq
movb $0xa, %al
cmpq $0x7ff000, 0x10(%rdx)   # imm = 0x7FF000
jne 0x19913
jmp 0x1973b
nop