// File: /workspace/github_c_makefile_star2_O3/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 0xca27
xorl %r12d, %r12d
xorl %r13d, %r13d
movq (%rsp,%r12,8), %rax
testq %rax, %rax
je 0x1ddc3
movq 0xb0(%rax), %r15
cmpq $0x0, (%r15)
je 0x1dd8a
movq %r14, %rdi
movq %r15, %rsi
callq 0xcb79
testl %eax, %eax
jne 0x1dd85
movq 0x20(%r15), %rdi
callq 0x50e0
cmpq $0x9, %rax
sbbl $-0x1, %r13d
incl %r13d
movq (%r15), %r15
jmp 0x1dd5c
cmpl $0x0, 0x54(%r14)
je 0x1ddc3
movq (%rsp,%r12,8), %rax
movq 0x98(%rax), %rcx
movq (%rcx), %rax
testq %rax, %rax
je 0x1ddc3
movq %rax, %r15
movq 0x10(%rcx), %rdi
callq 0x50e0
cmpq $0x9, %rax
sbbl $-0x1, %r13d
incl %r13d
movq (%r15), %rax
movq %r15, %rcx
jmp 0x1dd9f
incq %r12
cmpq $0x3, %r12
jne 0x1dd4c
movq %rsp, %r15
movq %r15, %rdi
callq 0xcb22
movq (%r15), %rax
xorl %edx, %edx
movl $0x0, %r15d
testq %rax, %rax
je 0x1ddef
movl 0x58(%rax), %r15d
addl 0x48(%rax), %r15d
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1ddfc
movl 0x50(%rax), %edx
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0x1de0c
movq 0x48(%rcx), %rcx
jmp 0x1de0e
xorl %ecx, %ecx
testq %rax, %rax
movl %edx, 0x28(%rsp)
je 0x1de1d
movq 0x58(%rax), %r12
jmp 0x1de20
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 0x6935
leaq 0x2e(%rsp), %rdi
movl %r15d, %esi
callq 0x693d
leaq 0x32(%rsp), %rdi
movl 0x28(%rsp), %esi
callq 0x693d
leaq 0x36(%rsp), %rdi
movl %r12d, %esi
callq 0x693d
leaq 0x3a(%rsp), %rdi
movl %ebp, %esi
callq 0x693d
leaq 0x3e(%rsp), %rdi
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x693d
leaq 0x42(%rsp), %rdi
movl 0x24(%rsp), %esi
callq 0x693d
leaq 0x46(%rsp), %rdi
xorl %esi, %esi
callq 0x6935
movl $0x1c, %edx
movq %rbx, %rdi
leaq 0x2c(%rsp), %rsi
callq 0x6ba5
movq (%rsp,%r15,8), %rsi
movq %r14, %rdi
callq 0xb6e6
incq %r15
cmpq $0x3, %r15
jne 0x1deb8
movq (%rsp), %rax
testq %rax, %rax
je 0x1deea
movq 0x58(%rax), %rdx
movq 0x78(%rax), %rsi
addq 0x48(%rax), %rdx
movq %rbx, %rdi
callq 0x6ba5
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1df04
movq 0x50(%rax), %rdx
movq 0x78(%rax), %rsi
movq %rbx, %rdi
callq 0x6ba5
testl %r13d, %r13d
je 0x1e014
xorl %ebp, %ebp
movq (%rsp,%rbp,8), %rax
testq %rax, %rax
je 0x1e007
movq 0xb0(%rax), %r12
cmpq $0x0, (%r12)
je 0x1dfca
movl %ebp, %r13d
movq %r14, %rdi
movq %r12, %rsi
callq 0xcb79
testl %eax, %eax
jne 0x1df98
movzbl 0x40(%r12), %eax
cmpl $0x1, %eax
je 0x1df65
cmpl $0x3, %eax
jne 0x1dfa5
movq 0x20(%r12), %rsi
leaq 0x7a9b(%rip), %rdi      # 0x259f7
xorl %eax, %eax
callq 0x52b0
jmp 0x1df6a
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 0x1e1c4
movq (%r12), %r12
cmpq $0x0, (%r12)
jne 0x1df31
jmp 0x1dfca
leaq 0x7754(%rip), %rcx      # 0x25700
movslq (%rcx,%r13,4), %rax
addq %rcx, %rax
jmpq *%rax
movw $0x200, %r15w           # imm = 0x200
jmp 0x1df6a
movw $0x400, %r15w           # imm = 0x400
jmp 0x1df6a
movw $0x100, %r15w           # imm = 0x100
jmp 0x1df6a
cmpl $0x0, 0x54(%r14)
je 0x1e007
movq (%rsp,%rbp,8), %rax
movq 0x98(%rax), %r12
cmpq $0x0, (%r12)
je 0x1e007
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 0x1e1c4
movq (%r12), %r12
jmp 0x1dfdc
incq %rbp
cmpq $0x3, %rbp
jne 0x1df0f
movq %rsp, %rdx
movq %rbx, %rsi
callq 0x1e02e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq