// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]vlink/t_ataritos.c
// Function: writeexec
static void writeexec(struct GlobalVars *gv,FILE *f)
/* creates a TOS executable file (which is relocatable) */
{
  struct LinkedSection *sections[3];
  int nsyms = tos_initwrite(gv,sections);
  int i;

  tos_header(f,sections[0] ? sections[0]->size+sections[0]->gapsize : 0,
             sections[1] ? sections[1]->filesize : 0,
             (sections[2] ? sections[2]->size : 0) +
             (sections[1] ? sections[1]->gapsize : 0),
             (unsigned long)nsyms*sizeof(struct DRIsym),gv->tosflags);

  for (i=0; i<3; i++)
    calc_relocs(gv,sections[i]);

  if (sections[0])
    fwritex(f,sections[0]->data,sections[0]->size+sections[0]->gapsize);

  if (sections[1])
    fwritex(f,sections[1]->data,sections[1]->filesize);

  if (nsyms)
    tos_symboltable(gv,f,sections);

  tos_writerelocs(gv,f,sections);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %rsi
callq 0xcaa8
xorl %r12d, %r12d
xorl %r13d, %r13d
movq (%rsp,%r12,8), %rax
testq %rax, %rax
je 0x1df57
movq 0xb0(%rax), %r15
cmpq $0x0, (%r15)
je 0x1df26
movq %r14, %rdi
movq %r15, %rsi
callq 0xcbff
testl %eax, %eax
jne 0x1df21
movq 0x20(%r15), %rdi
callq 0x50e0
cmpq $0x9, %rax
sbbl $-0x1, %r13d
incl %r13d
movq (%r15), %r15
jmp 0x1def8
cmpl $0x0, 0x54(%r14)
je 0x1df57
movq (%rsp,%r12,8), %rax
movq 0x98(%rax), %r15
cmpq $0x0, (%r15)
je 0x1df57
movq 0x10(%r15), %rdi
callq 0x50e0
cmpq $0x9, %rax
sbbl $-0x1, %r13d
incl %r13d
movq (%r15), %r15
jmp 0x1df38
incq %r12
cmpq $0x3, %r12
jne 0x1dee8
movq %rsp, %r15
movq %r15, %rdi
callq 0xcba3
movq (%r15), %rax
xorl %edx, %edx
movl $0x0, %r15d
testq %rax, %rax
je 0x1df83
movl 0x58(%rax), %r15d
addl 0x48(%rax), %r15d
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1df90
movl 0x50(%rax), %edx
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0x1dfa0
movq 0x48(%rcx), %rcx
jmp 0x1dfa2
xorl %ecx, %ecx
testq %rax, %rax
movl %edx, 0x28(%rsp)
je 0x1dfb1
movq 0x58(%rax), %r12
jmp 0x1dfb4
xorl %r12d, %r12d
addl %ecx, %r12d
movl %r13d, %ebp
shll $0x4, %ebp
subl %r13d, %ebp
subl %r13d, %ebp
movl 0x108(%r14), %eax
movl %eax, 0x24(%rsp)
leaq 0x2c(%rsp), %rdi
movl $0x601a, %esi           # imm = 0x601A
callq 0x6969
leaq 0x2e(%rsp), %rdi
movl %r15d, %esi
callq 0x6971
leaq 0x32(%rsp), %rdi
movl 0x28(%rsp), %esi
callq 0x6971
leaq 0x36(%rsp), %rdi
movl %r12d, %esi
callq 0x6971
leaq 0x3a(%rsp), %rdi
movl %ebp, %esi
callq 0x6971
leaq 0x3e(%rsp), %rdi
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x6971
leaq 0x42(%rsp), %rdi
movl 0x24(%rsp), %esi
callq 0x6971
leaq 0x46(%rsp), %rdi
xorl %esi, %esi
callq 0x6969
movl $0x1c, %edx
movq %rbx, %rdi
leaq 0x2c(%rsp), %rsi
callq 0x6c1a
movq (%rsp,%r15,8), %rsi
movq %r14, %rdi
callq 0xb7c8
incq %r15
cmpq $0x3, %r15
jne 0x1e04c
movq (%rsp), %rax
testq %rax, %rax
je 0x1e07e
movq 0x58(%rax), %rdx
movq 0x78(%rax), %rsi
addq 0x48(%rax), %rdx
movq %rbx, %rdi
callq 0x6c1a
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1e098
movq 0x50(%rax), %rdx
movq 0x78(%rax), %rsi
movq %rbx, %rdi
callq 0x6c1a
testl %r13d, %r13d
je 0x1e1a8
xorl %ebp, %ebp
movq (%rsp,%rbp,8), %rax
testq %rax, %rax
je 0x1e19b
movq 0xb0(%rax), %r12
cmpq $0x0, (%r12)
je 0x1e15e
movl %ebp, %r13d
movq %r14, %rdi
movq %r12, %rsi
callq 0xcbff
testl %eax, %eax
jne 0x1e12c
movzbl 0x40(%r12), %eax
cmpl $0x1, %eax
je 0x1e0f9
cmpl $0x3, %eax
jne 0x1e139
movq 0x20(%r12), %rsi
leaq 0x7927(%rip), %rdi      # 0x25a17
xorl %eax, %eax
callq 0x52b0
jmp 0x1e0fe
movw $0x4000, %r15w          # imm = 0x4000
xorl %eax, %eax
cmpb $0x2, 0x43(%r12)
setae %al
shll $0xd, %eax
orl %eax, %r15d
orl $0x8000, %r15d          # imm = 0x8000
movq 0x20(%r12), %rsi
movl 0x30(%r12), %ecx
movzwl %r15w, %edx
movq %rbx, %rdi
callq 0x1e348
movq (%r12), %r12
cmpq $0x0, (%r12)
jne 0x1e0c5
jmp 0x1e15e
leaq 0x75e0(%rip), %rcx      # 0x25720
movslq (%rcx,%r13,4), %rax
addq %rcx, %rax
jmpq *%rax
movw $0x200, %r15w           # imm = 0x200
jmp 0x1e0fe
movw $0x400, %r15w           # imm = 0x400
jmp 0x1e0fe
movw $0x100, %r15w           # imm = 0x100
jmp 0x1e0fe
cmpl $0x0, 0x54(%r14)
je 0x1e19b
movq (%rsp,%rbp,8), %rax
movq 0x98(%rax), %r12
cmpq $0x0, (%r12)
je 0x1e19b
movq 0x10(%r12), %rsi
movq (%rsp,%rbp,8), %rax
movl 0x20(%r12), %ecx
addl 0x40(%rax), %ecx
movq %rbx, %rdi
movl $0x800, %edx            # imm = 0x800
callq 0x1e348
movq (%r12), %r12
jmp 0x1e170
incq %rbp
cmpq $0x3, %rbp
jne 0x1e0a3
movq %rsp, %rdx
movq %rbx, %rsi
callq 0x1e1c2
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq