// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_rawbin.c
// Function: ihex_write
static void ihex_write(struct GlobalVars *gv,FILE *f)
{
  bool firstsec = TRUE;
  struct LinkedSection *ls;
  unsigned long len,addr;
  uint8_t *p;

  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>MAXIREC) ? MAXIREC : len;

      if ((((unsigned long)addr)&0xffff)+nbytes > 0xffff)
        nbytes = 0x10000 - (((unsigned long)addr) & 0xffff);
      IHexOut(f,addr,p,nbytes);
      p += nbytes;
      addr += nbytes;
      len -= nbytes;
    }
  }

  fprintf(f,":00000001FF\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x6d6b(%rip), %r12      # 0x23704
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x1ce4b
testq %rax, %rax
je 0x1cb2a
movq %rax, %rbp
cmpq $0x0, 0x48(%rax)
je 0x1c99c
testb $0x1, 0x21(%rbp)
je 0x1c99c
testb $0x1, 0x24(%rbp)
jne 0x1c99c
testb $0x1, %r14b
jne 0x1c9e7
movq 0xa0(%r15), %rdi
testq %rdi, %rdi
je 0x1c9e7
movq 0x38(%rbp), %rdx
leaq 0x6d00(%rip), %rsi      # 0x236e0
xorl %eax, %eax
callq 0x5180
movq %r15, %rdi
movq %rbp, %rsi
callq 0xb170
movq 0x78(%rbp), %rdx
movq 0x38(%rbp), %rax
movq %rax, 0x8(%rsp)
movq 0x50(%rbp), %rcx
movq %r15, 0x18(%rsp)
testq %rcx, %rcx
je 0x1cb22
movq %rdx, 0x10(%rsp)
cmpq $0x20, %rcx
pushq $0x20
popq %rax
movq %rcx, 0x20(%rsp)
cmovbq %rcx, %rax
movq 0x8(%rsp), %rsi
movzwl %si, %ecx
movl $0x10000, %r14d         # imm = 0x10000
subl %ecx, %r14d
addl %eax, %ecx
movl $0x10000, %edx          # imm = 0x10000
cmpl %edx, %ecx
cmovbl %eax, %r14d
movq %rsi, %rcx
shrq $0x10, %rcx
movzwl %cx, %edx
cmpq 0x1751b(%rip), %rdx     # 0x33f70
je 0x1ca88
movq %rdx, 0x17512(%rip)     # 0x33f70
shrl $0x8, %edx
leal (%rdx,%rcx), %eax
movl $0xff, %esi
andl %esi, %ecx
movl $0xfa, %r8d
subl %eax, %r8d
andl %esi, %r8d
movq %rbx, %rdi
leaq 0x6c95(%rip), %rsi      # 0x23716
xorl %eax, %eax
callq 0x5180
movl %r14d, %edx
movl $0xff, %eax
andl %eax, %edx
movq 0x8(%rsp), %r13
movq %r13, %r15
shrq $0x8, %r15
movl %r15d, %ecx
andl %eax, %ecx
movl %r13d, %r8d
andl %eax, %r8d
movq %rbx, %rdi
leaq 0x6c7a(%rip), %rsi      # 0x2372d
xorl %eax, %eax
callq 0x5180
movl %r14d, %ebp
addl %r13d, %r15d
addl %r14d, %r15d
movq 0x10(%rsp), %r13
testl %r14d, %r14d
jle 0x1caeb
movzbl (%r13), %edx
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x5180
addb (%r13), %r15b
incq %r13
decl %r14d
jmp 0x1cac8
negb %r15b
movzbl %r15b, %edx
movq %rbx, %rdi
leaq 0x6c2b(%rip), %rsi      # 0x23727
xorl %eax, %eax
callq 0x5180
movq 0x10(%rsp), %rdx
addq %rbp, %rdx
addq %rbp, 0x8(%rsp)
movq 0x20(%rsp), %rcx
subq %rbp, %rcx
movq 0x18(%rsp), %r15
jmp 0x1ca08
movb $0x1, %r14b
jmp 0x1c99c
leaq 0x6bd8(%rip), %rdi      # 0x23709
pushq $0xc
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5280