// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/targets.c
// Function: writesection
lword writesection(struct GlobalVars *gv,uint8_t *dest,struct Reloc *r,lword v)
/* Write 'v' into the bit-field defined by the relocation type in 'r'.
   Do range checks first, depending on the reloc type.
   Returns 0 on success or the masked and normalized value which failed
   on the range check. */
{
  struct RelocInsert *ri;

  if (r->rtype == R_NONE)
    return 0;

  if (ri = r->insert) {
    lword lastval = 0;  /* add reloc-addends to this value */
    uint8_t t = r->rtype;
    bool signedval = t==R_PC||t==R_GOTPC||t==R_GOTOFF||t==R_PLTPC||t==R_PLTOFF
                     ||t==R_SD||t==R_SD2||t==R_SD21||t==R_MOSDREL;
    bool be = gv->endianess == _BIG_ENDIAN_;

    do {
      /* first mask and normalize the value, then check if it
         fits into the bitfield */
      lword mask = ri->mask;
      lword insval = v & mask;
      uint8_t *p = dest + (ri->bpos >> 3);
      int bpos = (int)ri->bpos & 7;
      int bsiz = (int)ri->bsiz;
      int n;

      insval >>= lshiftcnt(mask);  /* normalize according mask */
      if (mask>=0 && signedval)
        insval = sign_extend(insval,bsiz);
      insval += lastval;
      lastval = insval;
      if (!checkrange(insval,signedval,bsiz))
        return insval;  /* range check failed on 'insval' */

      /* insert into bitfield, obeying target endianess */
      if (n = (bpos + bsiz + 7) >> 3) {
        if (be) {  /* write for big-endian target */
          int sh = (8 - ((bpos + bsiz) & 7)) & 7;
          uint8_t m = 0xff << sh;  /* mask for LSB */
          uint8_t b;

          insval <<= sh;  /* shift to fit bitfield */
          p += n;
          while (n--) {
            if (!n)
              m &= (1 << (8-(bpos&7))) - 1;  /* apply mask for MSB */

            b = *(--p) & ~m;
            *p = b | ((uint8_t)insval & m);
            insval >>= 8;
            m = 0xff;
          }
        }
        else {  /* write for little-endian target */
          uint8_t m = 0xff << bpos;  /* mask for LSB */
          uint8_t b;

          insval <<= bpos;  /* shift to fit bitfield */
          while (n--) {
            if (!n && ((bpos+bsiz)&7)!=0)
              m &= (1 << ((bpos+bsiz)&7)) - 1;  /* apply mask for MSB */

            b = *p & ~m;
            *p++ = b | ((uint8_t)insval & m);
            insval >>= 8;
            m = 0xff;
          }
        }
      }
    }
    while (ri = ri->next);

    return 0;
  }

  ierror("writesection(): Reloc (type=%d offs=%lu add=%lld) without "
         " insert field def.\n",(int)r->rtype,r->offset,r->addend);
  return -1;
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %rcx, 0x50(%rsp)
movq 0x58(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x0, %eax
jne 0x110f4
movq $0x0, 0x70(%rsp)
jmp 0x114e4
movq 0x58(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, %rax
je 0x114b2
movq $0x0, 0x40(%rsp)
movq 0x58(%rsp), %rax
movb 0x38(%rax), %al
movb %al, 0x3f(%rsp)
movzbl 0x3f(%rsp), %ecx
movb $0x1, %al
cmpl $0x2, %ecx
movb %al, 0x3(%rsp)
je 0x111b0
movzbl 0x3f(%rsp), %ecx
movb $0x1, %al
cmpl $0x4, %ecx
movb %al, 0x3(%rsp)
je 0x111b0
movzbl 0x3f(%rsp), %ecx
movb $0x1, %al
cmpl $0x5, %ecx
movb %al, 0x3(%rsp)
je 0x111b0
movzbl 0x3f(%rsp), %ecx
movb $0x1, %al
cmpl $0x8, %ecx
movb %al, 0x3(%rsp)
je 0x111b0
movzbl 0x3f(%rsp), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, 0x3(%rsp)
je 0x111b0
movzbl 0x3f(%rsp), %ecx
movb $0x1, %al
cmpl $0xa, %ecx
movb %al, 0x3(%rsp)
je 0x111b0
movzbl 0x3f(%rsp), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, 0x3(%rsp)
je 0x111b0
movzbl 0x3f(%rsp), %ecx
movb $0x1, %al
cmpl $0x21, %ecx
movb %al, 0x3(%rsp)
je 0x111b0
movzbl 0x3f(%rsp), %eax
cmpl $0x22, %eax
sete %al
movb %al, 0x3(%rsp)
movb 0x3(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x38(%rsp)
movq 0x68(%rsp), %rax
movsbl 0x202(%rax), %eax
cmpl $0x1, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x34(%rsp)
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
andq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x60(%rsp), %rax
movq 0x48(%rsp), %rcx
movzwl 0x8(%rcx), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rax
movzwl 0x8(%rax), %eax
andl $0x7, %eax
movl %eax, 0x14(%rsp)
movq 0x48(%rsp), %rax
movzwl 0xa(%rax), %eax
movl %eax, 0x10(%rsp)
movq 0x28(%rsp), %rdi
callq 0x88c0
movl %eax, %ecx
movq 0x20(%rsp), %rax
movl %ecx, %ecx
sarq %cl, %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x28(%rsp)
jl 0x1126b
cmpl $0x0, 0x38(%rsp)
je 0x1126b
movq 0x20(%rsp), %rdi
movl 0x10(%rsp), %esi
callq 0x89f0
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x20(%rsp), %rdi
movl 0x38(%rsp), %esi
movl 0x10(%rsp), %edx
callq 0x77b0
cmpl $0x0, %eax
jne 0x112aa
movq 0x20(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x114e4
movl 0x14(%rsp), %eax
addl 0x10(%rsp), %eax
addl $0x7, %eax
sarl $0x3, %eax
movl %eax, 0xc(%rsp)
cmpl $0x0, %eax
je 0x1148e
cmpl $0x0, 0x34(%rsp)
je 0x113c0
movl 0x14(%rsp), %ecx
addl 0x10(%rsp), %ecx
andl $0x7, %ecx
movl $0x8, %eax
subl %ecx, %eax
andl $0x7, %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %ecx
movl $0xff, %eax
shll %cl, %eax
movb %al, 0x7(%rsp)
movl 0x8(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, %ecx
shlq %cl, %rax
movq %rax, 0x20(%rsp)
movl 0xc(%rsp), %ecx
movq 0x18(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0xc(%rsp)
cmpl $0x0, %eax
je 0x113bb
cmpl $0x0, 0xc(%rsp)
jne 0x11361
movl 0x14(%rsp), %eax
andl $0x7, %eax
movl $0x8, %ecx
subl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
subl $0x1, %ecx
movzbl 0x7(%rsp), %eax
andl %ecx, %eax
movb %al, 0x7(%rsp)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, 0x18(%rsp)
movzbl -0x1(%rax), %eax
movzbl 0x7(%rsp), %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movb %al, 0x6(%rsp)
movzbl 0x6(%rsp), %eax
movq 0x20(%rsp), %rcx
movzbl %cl, %ecx
movzbl 0x7(%rsp), %edx
andl %edx, %ecx
orl %ecx, %eax
movb %al, %cl
movq 0x18(%rsp), %rax
movb %cl, (%rax)
movq 0x20(%rsp), %rax
sarq $0x8, %rax
movq %rax, 0x20(%rsp)
movb $-0x1, 0x7(%rsp)
jmp 0x1131f
jmp 0x1148c
movl 0x14(%rsp), %ecx
movl $0xff, %eax
shll %cl, %eax
movb %al, 0x5(%rsp)
movl 0x14(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, %ecx
shlq %cl, %rax
movq %rax, 0x20(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, 0xc(%rsp)
cmpl $0x0, %eax
je 0x1148a
cmpl $0x0, 0xc(%rsp)
jne 0x11431
movl 0x14(%rsp), %eax
addl 0x10(%rsp), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x11431
movl 0x14(%rsp), %ecx
addl 0x10(%rsp), %ecx
andl $0x7, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
subl $0x1, %ecx
movzbl 0x5(%rsp), %eax
andl %ecx, %eax
movb %al, 0x5(%rsp)
movq 0x18(%rsp), %rax
movzbl (%rax), %eax
movzbl 0x5(%rsp), %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movb %al, 0x4(%rsp)
movzbl 0x4(%rsp), %eax
movq 0x20(%rsp), %rcx
movzbl %cl, %ecx
movzbl 0x5(%rsp), %edx
andl %edx, %ecx
orl %ecx, %eax
movb %al, %cl
movq 0x18(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rsp)
movb %cl, (%rax)
movq 0x20(%rsp), %rax
sarq $0x8, %rax
movq %rax, 0x20(%rsp)
movb $-0x1, 0x5(%rsp)
jmp 0x113e2
jmp 0x1148c
jmp 0x1148e
jmp 0x11490
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, %rax
jne 0x111d8
movq $0x0, 0x70(%rsp)
jmp 0x114e4
movq 0x58(%rsp), %rax
movzbl 0x38(%rax), %esi
movq 0x58(%rsp), %rax
movq 0x20(%rax), %rdx
movq 0x58(%rsp), %rax
movq 0x28(%rax), %rcx
leaq 0x24280(%rip), %rdi     # 0x35754
movb $0x0, %al
callq 0x8ae0
movq $-0x1, 0x70(%rsp)
movq 0x70(%rsp), %rax
addq $0x78, %rsp
retq
nop