// File: /workspace/github_c_makefile_star2_O1/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
callq 0x1e98f
testq %rax, %rax
je 0x1e636
movq %rax, %rbp
leaq 0x7646(%rip), %r12      # 0x25adc
xorl %r14d, %r14d
cmpq $0x0, 0x48(%rbp)
je 0x1e4ac
testb $0x1, 0x21(%rbp)
je 0x1e4ac
testb $0x1, 0x24(%rbp)
je 0x1e4c1
movq %r15, %rdi
callq 0x1e98f
movq %rax, %rbp
testq %rax, %rax
jne 0x1e499
jmp 0x1e636
testb $0x1, %r14b
jne 0x1e4e1
movq 0xa0(%r15), %rdi
testq %rdi, %rdi
je 0x1e4e1
movq 0x38(%rbp), %rdx
movq %r12, %rsi
xorl %eax, %eax
callq 0x5180
movq %r15, 0x8(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0xb7c8
movq 0x50(%rbp), %rcx
testq %rcx, %rcx
je 0x1e613
movq 0x38(%rbp), %r13
movq 0x78(%rbp), %r12
cmpq $0x20, %rcx
movl $0x20, %eax
movq %rcx, 0x20(%rsp)
cmovbq %rcx, %rax
movzwl %r13w, %ecx
movl $0x10000, %r14d         # imm = 0x10000
subl %ecx, %r14d
addl %eax, %ecx
movl $0x10000, %edx          # imm = 0x10000
cmpl %edx, %ecx
cmovbl %eax, %r14d
movq %r13, %rcx
shrq $0x10, %rcx
movzwl %cx, %edx
cmpq 0x1563d(%rip), %rdx     # 0x33b80
je 0x1e576
movq %rdx, 0x15634(%rip)     # 0x33b80
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 0x75a3(%rip), %rsi      # 0x25b12
xorl %eax, %eax
callq 0x5180
movl %r14d, %edx
movl $0xff, %eax
andl %eax, %edx
movq %r13, %r15
shrq $0x8, %r15
movl %r15d, %ecx
andl %eax, %ecx
movl %r13d, %r8d
andl %eax, %r8d
movq %rbx, %rdi
leaq 0x758d(%rip), %rsi      # 0x25b29
xorl %eax, %eax
callq 0x5180
addl %r13d, %r15d
addl %r14d, %r15d
movq %r14, 0x10(%rsp)
leal 0x1(%r14), %ebp
movq %r12, 0x18(%rsp)
leaq 0x7542(%rip), %r14      # 0x25b00
movzbl (%r12), %edx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x5180
addb (%r12), %r15b
incq %r12
decl %ebp
cmpl $0x1, %ebp
jg 0x1e5be
negb %r15b
movzbl %r15b, %edx
movq %rbx, %rdi
leaq 0x7534(%rip), %rsi      # 0x25b23
xorl %eax, %eax
callq 0x5180
movl 0x10(%rsp), %eax
movq 0x18(%rsp), %r12
addq %rax, %r12
addq %rax, %r13
movq 0x20(%rsp), %rcx
subq %rax, %rcx
jne 0x1e506
movq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x1e98f
movq %rax, %rbp
movb $0x1, %r14b
testq %rax, %rax
leaq 0x74ac(%rip), %r12      # 0x25adc
jne 0x1e499
leaq 0x74c8(%rip), %rdi      # 0x25b05
movl $0xc, %esi
movl $0x1, %edx
movq %rbx, %rcx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5270