// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/t_rawbin.c
// Function: srec_write
static void srec_write(struct GlobalVars *gv,FILE *f,int addrsize)
{
  bool firstsec = TRUE;
  struct LinkedSection *ls;
  unsigned long len,addr;
  uint8_t *p,buf[MAXSREC+8];

  /* write header */
  buf[0] = buf[1] = 0;
  strncpy(&buf[2],gv->dest_name,MAXSREC+6);
  SRecOut(f,0,buf,(strlen(gv->dest_name)<(MAXSREC+6)) ?
          strlen(gv->dest_name)+2 : MAXSREC+8);

  while (ls = get_next_section(gv)) {
    if (ls->size == 0 || !(ls->flags & SF_ALLOC) || (ls->ld_flags & LSF_NOLOAD))
      continue;  /* ignore empty sections */

    if (firstsec) {
      if (gv->trace_file)
        fprintf(gv->trace_file,"Base address = 0x%08lx.\n",ls->copybase);
      firstsec = FALSE;
    }

    /* resolve all relocations and write section contents */
    calc_relocs(gv,ls);

    for (p=ls->data,addr=ls->copybase,len=ls->filesize; len>0; ) {
      int nbytes = (len>MAXSREC) ? MAXSREC : len;

      switch (addrsize) {
        case 2:
          write16be(buf,(uint16_t)addr);
          memcpy(buf+2,p,nbytes);
          SRecOut(f,1,buf,2+nbytes);
          break;
        case 3:
          buf[0] = (uint8_t)((addr>>16)&0xff);
          buf[1] = (uint8_t)((addr>>8)&0xff);
          buf[2] = (uint8_t)(addr&0xff);
          memcpy(buf+3,p,nbytes);
          SRecOut(f,2,buf,3+nbytes);
          break;
        case 4:
          write32be(buf,(uint32_t)addr);
          memcpy(buf+4,p,nbytes);
          SRecOut(f,3,buf,4+nbytes);
          break;
        default:
          ierror("srec_write(): Illegal SRec-type: %d",addrsize);
          nbytes = len;
          break;
      }
      p += nbytes;
      addr += nbytes;
      len -= nbytes;
    }
  }

  /* write trailer */
  memset(buf,0,4);
  SRecOut(f,11-addrsize,buf,addrsize);
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x90(%rsp)
movq %rsi, 0x88(%rsp)
movl %edx, 0x84(%rsp)
movl $0x1, 0x80(%rsp)
movb $0x0, 0x31(%rsp)
movb $0x0, 0x30(%rsp)
leaq 0x30(%rsp), %rdi
addq $0x2, %rdi
movq 0x90(%rsp), %rax
movq 0x48(%rax), %rsi
movl $0x26, %edx
callq 0x5040
movq 0x88(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x90(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0x50c0
cmpq $0x26, %rax
jae 0x3101c
movq 0x90(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0x50c0
addq $0x2, %rax
movq %rax, 0x10(%rsp)
jmp 0x31028
movl $0x28, %eax
movq %rax, 0x10(%rsp)
jmp 0x31028
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %rax
movl %eax, %ecx
xorl %esi, %esi
callq 0x31320
movq 0x90(%rsp), %rdi
callq 0x30ef0
movq %rax, 0x78(%rsp)
cmpq $0x0, %rax
je 0x312d7
movq 0x78(%rsp), %rax
cmpq $0x0, 0x48(%rax)
je 0x3108a
movq 0x78(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3108a
movq 0x78(%rsp), %rax
movzwl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3108c
jmp 0x31040
cmpl $0x0, 0x80(%rsp)
je 0x310d9
movq 0x90(%rsp), %rax
cmpq $0x0, 0xa0(%rax)
je 0x310ce
movq 0x90(%rsp), %rax
movq 0xa0(%rax), %rdi
movq 0x78(%rsp), %rax
movq 0x38(%rax), %rdx
leaq 0x7049(%rip), %rsi      # 0x38110
movb $0x0, %al
callq 0x5150
movl $0x0, 0x80(%rsp)
movq 0x90(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x114f0
movq 0x78(%rsp), %rax
movq 0x78(%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x78(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x68(%rsp)
movq 0x78(%rsp), %rax
movq 0x50(%rax), %rax
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
jbe 0x312d2
cmpq $0x20, 0x70(%rsp)
jbe 0x31135
movl $0x20, %eax
movq %rax, 0x8(%rsp)
jmp 0x3113f
movq 0x70(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movl %eax, 0x2c(%rsp)
movl 0x84(%rsp), %eax
movl %eax, 0x4(%rsp)
subl $0x2, %eax
je 0x31177
jmp 0x3115a
movl 0x4(%rsp), %eax
subl $0x3, %eax
je 0x311c4
jmp 0x31165
movl 0x4(%rsp), %eax
subl $0x4, %eax
je 0x31231
jmp 0x3127a
leaq 0x30(%rsp), %rdi
movq 0x68(%rsp), %rax
movzwl %ax, %esi
callq 0x7ae0
leaq 0x30(%rsp), %rdi
addq $0x2, %rdi
movq 0x60(%rsp), %rsi
movslq 0x2c(%rsp), %rdx
callq 0x5170
movq 0x88(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movl 0x2c(%rsp), %ecx
addl $0x2, %ecx
movl $0x1, %esi
callq 0x31320
jmp 0x31298
movq 0x68(%rsp), %rax
shrq $0x10, %rax
andq $0xff, %rax
movb %al, 0x30(%rsp)
movq 0x68(%rsp), %rax
shrq $0x8, %rax
andq $0xff, %rax
movb %al, 0x31(%rsp)
movq 0x68(%rsp), %rax
andq $0xff, %rax
movb %al, 0x32(%rsp)
leaq 0x30(%rsp), %rdi
addq $0x3, %rdi
movq 0x60(%rsp), %rsi
movslq 0x2c(%rsp), %rdx
callq 0x5170
movq 0x88(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movl 0x2c(%rsp), %ecx
addl $0x3, %ecx
movl $0x2, %esi
callq 0x31320
jmp 0x31298
leaq 0x30(%rsp), %rdi
movq 0x68(%rsp), %rax
movl %eax, %esi
callq 0x7b30
leaq 0x30(%rsp), %rdi
addq $0x4, %rdi
movq 0x60(%rsp), %rsi
movslq 0x2c(%rsp), %rdx
callq 0x5170
movq 0x88(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movl 0x2c(%rsp), %ecx
addl $0x4, %ecx
movl $0x3, %esi
callq 0x31320
jmp 0x31298
movl 0x84(%rsp), %esi
leaq 0x6ea8(%rip), %rdi      # 0x38130
movb $0x0, %al
callq 0x8ae0
movq 0x70(%rsp), %rax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %ecx
movq 0x60(%rsp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, 0x60(%rsp)
movslq 0x2c(%rsp), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x68(%rsp)
movslq 0x2c(%rsp), %rcx
movq 0x70(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x70(%rsp)
jmp 0x31115
jmp 0x31040
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x5100
movq 0x88(%rsp), %rdi
movl $0xb, %esi
subl 0x84(%rsp), %esi
leaq 0x30(%rsp), %rdx
movl 0x84(%rsp), %ecx
callq 0x31320
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)