// File: /workspace/github_c_makefile_star2_O2/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 0xc2c0
xorl %r12d, %r12d
xorl %r13d, %r13d
cmpq $0x3, %r12
je 0x1c492
movq (%rsp,%r12,8), %r15
testq %r15, %r15
je 0x1c48d
addq $0xb0, %r15
movq (%r15), %r15
cmpq $0x0, (%r15)
je 0x1c45a
movq %r14, %rdi
movq %r15, %rsi
callq 0xc408
testl %eax, %eax
jne 0x1c42c
movq 0x20(%r15), %rdi
callq 0x50e0
cmpq $0x9, %rax
sbbl $-0x1, %r13d
incl %r13d
jmp 0x1c42c
cmpl $0x0, 0x54(%r14)
je 0x1c48d
movq (%rsp,%r12,8), %rax
movq 0x98(%rax), %rax
movq (%rax), %r15
testq %r15, %r15
je 0x1c48d
movq 0x10(%rax), %rdi
callq 0x50e0
cmpq $0x9, %rax
sbbl $-0x1, %r13d
incl %r13d
movq %r15, %rax
jmp 0x1c46c
incq %r12
jmp 0x1c416
movq %rsp, %r15
movq %r15, %rdi
callq 0xc3b1
movq (%r15), %rax
xorl %edx, %edx
movl $0x0, %r15d
testq %rax, %rax
je 0x1c4b5
movl 0x58(%rax), %r15d
addl 0x48(%rax), %r15d
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1c4c2
movl 0x50(%rax), %edx
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0x1c4d2
movq 0x48(%rcx), %rcx
jmp 0x1c4d4
xorl %ecx, %ecx
testq %rax, %rax
movl %edx, 0x28(%rsp)
je 0x1c4e3
movq 0x58(%rax), %r12
jmp 0x1c4e6
xorl %r12d, %r12d
addl %ecx, %r12d
imull $0xe, %r13d, %ebp
movl 0x108(%r14), %eax
movl %eax, 0x24(%rsp)
leaq 0x2c(%rsp), %rdi
movl $0x601a, %esi           # imm = 0x601A
callq 0x6613
leaq 0x2e(%rsp), %rdi
movl %r15d, %esi
callq 0x661b
leaq 0x32(%rsp), %rdi
movl 0x28(%rsp), %esi
callq 0x661b
leaq 0x36(%rsp), %rdi
movl %r12d, %esi
callq 0x661b
leaq 0x3a(%rsp), %rdi
movl %ebp, %esi
callq 0x661b
leaq 0x3e(%rsp), %rdi
xorl %r15d, %r15d
xorl %esi, %esi
callq 0x661b
leaq 0x42(%rsp), %rdi
movl 0x24(%rsp), %esi
callq 0x661b
leaq 0x46(%rsp), %rdi
xorl %esi, %esi
callq 0x6613
pushq $0x1c
popq %rdx
movq %rbx, %rdi
leaq 0x2c(%rsp), %rsi
callq 0x6817
cmpq $0x3, %r15
je 0x1c58b
movq (%rsp,%r15,8), %rsi
movq %r14, %rdi
callq 0xb170
incq %r15
jmp 0x1c574
movq (%rsp), %rax
testq %rax, %rax
je 0x1c5a8
movq 0x58(%rax), %rdx
movq 0x78(%rax), %rsi
addq 0x48(%rax), %rdx
movq %rbx, %rdi
callq 0x6817
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x1c5c2
movq 0x50(%rax), %rdx
movq 0x78(%rax), %rsi
movq %rbx, %rdi
callq 0x6817
testl %r13d, %r13d
je 0x1c6bf
xorl %r15d, %r15d
cmpq $0x3, %r15
je 0x1c6bf
movq (%rsp,%r15,8), %r12
testq %r12, %r12
je 0x1c6b7
addq $0xb0, %r12
movl %r15d, %ecx
shll $0x4, %ecx
movabsq $0x10004000200, %r13    # imm = 0x10004000200
shrq %cl, %r13
movq (%r12), %r12
cmpq $0x0, (%r12)
je 0x1c679
movq %r14, %rdi
movq %r12, %rsi
callq 0xc408
testl %eax, %eax
jne 0x1c5ff
movzbl 0x40(%r12), %eax
cmpl $0x1, %eax
je 0x1c63e
cmpl $0x3, %eax
jne 0x1c644
movq 0x20(%r12), %rsi
leaq 0x6daf(%rip), %rdi      # 0x233e4
xorl %eax, %eax
callq 0x6b2c
jmp 0x1c64c
movw $0x4000, %bp            # imm = 0x4000
jmp 0x1c64c
cmpq $0x3, %r15
cmovbl %r13d, %ebp
xorl %eax, %eax
cmpb $0x2, 0x43(%r12)
setae %al
shll $0xd, %eax
orl %eax, %ebp
orl $0x8000, %ebp           # imm = 0x8000
movq 0x20(%r12), %rsi
movl 0x30(%r12), %ecx
movzwl %bp, %edx
movq %rbx, %rdi
callq 0x1c873
jmp 0x1c5ff
cmpl $0x0, 0x54(%r14)
je 0x1c6b7
movq (%rsp,%r15,8), %r12
movl $0x98, %eax
addq %rax, %r12
movq (%r12), %r12
cmpq $0x0, (%r12)
je 0x1c6b7
movq 0x10(%r12), %rsi
movq (%rsp,%r15,8), %rax
movl 0x20(%r12), %ecx
addl 0x40(%rax), %ecx
movq %rbx, %rdi
movl $0x800, %edx            # imm = 0x800
callq 0x1c873
jmp 0x1c68c
incq %r15
jmp 0x1c5ce
movq %rsp, %rdx
movq %rbx, %rsi
callq 0x1c6d9
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq