// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/eps.c
// Function: save_legend
void save_legend(FILE* myfile)
{
 /*!Last Changed 20.09.2006*/
 char st[100], st2[100];
 int posx = 0, posy = 0, direction = 0, i, legendy, legendheight, legendwidth, maxlength = 0;
 for (i = 0; i < img.imagelegend.legendcount; i++)
   if (strlen(img.imagelegend.names[i]) > maxlength)
     maxlength = strlen(img.imagelegend.names[i]);
 legendheight = img.imagelegend.fnt.fontsize;
 legendwidth = 1.1 * img.imagelegend.fnt.fontsize * maxlength;
 if (img.imagelegend.legendcount != 0 && img.imagelegend.position != NONE)
  {
   switch (img.imagelegend.position)
    {
     case DOWN_RIGHT:posx = epsaxis + MARGIN - legendwidth - 10;
                     posy = MARGIN + 20;
                     direction = 1;
                     break;
     case DOWN_LEFT :posx = MARGIN + 10;
                     posy = MARGIN + 20;
                     direction = 1;
                     break;
     case UP_RIGHT  :posx = epsaxis + MARGIN - legendwidth - 10;
                     posy = epsaxis + MARGIN - 20;
                     direction = -1;
                     break;
     case UP_LEFT   :posx = MARGIN + 10;
                     posy = epsaxis + MARGIN - 20;
                     direction = -1;
                     break;
     default        :break;
    }
   write_rectangle(myfile, posx, posy, posx + legendwidth, posy + direction * (img.imagelegend.legendcount + 1) * legendheight, FILL_NONE, BLACK);
   setfont(myfile, img.imagelegend.fnt);   
   for (i = 0; i < img.imagelegend.legendcount; i++)
    {
     setcolor(myfile, img.imagelegend.colors[i]);
     if (direction == 1)      
       legendy = posy + (img.imagelegend.legendcount - i) * legendheight;
     else
       legendy = posy - (i + 1) * legendheight;
     sprintf(st, "%s", img.imagelegend.names[i]);
     if (between(img.imagelegend.types[i], '0', '0' + MAX_FILL_TYPE - 1))
       write_rectangle(myfile, posx + 5, legendy, posx + 20, legendy + 10, img.imagelegend.types[i] - '0', BLACK);
     else
       if (between(img.imagelegend.types[i], 'a', 'z'))
        {
         setcolor(myfile, (img.imagelegend.types[i] - 'a') % COLORCOUNT);
         write_dashed_line(myfile, posx + 5, legendy, posx + 20, legendy, (img.imagelegend.types[i] - 'a') % MAX_LINE_TYPE);
         setcolor(myfile, BLACK);
        }
       else
         if (between(img.imagelegend.types[i], 'A', 'Z'))
          {
           setcolor(myfile, img.imagelegend.types[i] - 'A');
           write_line(myfile, posx + 5, legendy, posx + 20, legendy);
           setcolor(myfile, BLACK);
          } 
         else
          {
           sprintf(st2, "%c   %s", img.imagelegend.types[i], st);
           strcpy(st, st2);
          }
     write_string(myfile, posx + 25, legendy, st, ALIGN_LEFT);
    }  
  }    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
leaq 0x38f0a2(%rip), %r12    # 0x3b20b8
movslq 0xec(%r12), %r15
testq %r15, %r15
jle 0x23050
movq 0x100(%r12), %r14
xorl %r13d, %r13d
xorl %ebp, %ebp
movq (%r14,%r13,8), %rdi
callq 0x4190
movslq %ebp, %rbp
cmpq %rbp, %rax
cmoval %eax, %ebp
incq %r13
cmpq %r13, %r15
jne 0x23030
cvtsi2sd %ebp, %xmm0
jmp 0x23054
xorpd %xmm0, %xmm0
testl %r15d, %r15d
setne %cl
movl 0xe8(%r12), %eax
cmpl $0x4, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x23402
movsd 0x110(%r12), %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, 0x30(%rsp)
mulsd 0x84d43(%rip), %xmm1    # 0xa7dd0
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r8d
cmpl $0x3, %eax
ja 0x230f2
movl %eax, %eax
leaq 0x84db0(%rip), %rcx     # 0xa7e54
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x23a, %edx            # imm = 0x23A
subl %r8d, %edx
jmp 0x230df
movl $0x23a, %edx            # imm = 0x23A
subl %r8d, %edx
jmp 0x230c6
movl $0x5a, %edx
movl $0x230, %ecx            # imm = 0x230
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x0, 0x24(%rsp)
jmp 0x23100
movl $0x5a, %edx
movl $0x64, %ecx
movl $0x1, %eax
movb $0x1, %sil
movl %esi, 0x24(%rsp)
jmp 0x23100
movl $0x0, 0x24(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
addl %edx, %r8d
incl %r15d
imull %eax, %r15d
imull 0x30(%rsp), %r15d
addl %ecx, %r15d
leaq 0x84f84(%rip), %rsi     # 0xa809e
movq %rbx, %rdi
movq %rdx, %r14
movl %ecx, 0x34(%rsp)
movl %r15d, %r9d
xorl %eax, %eax
callq 0x42e0
movq 0x118(%r12), %rax
movq %rax, 0x10(%rsp)
movupd 0x108(%r12), %xmm0
movupd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x234a7
cmpl $0x0, 0xec(%r12)
jle 0x23402
leal 0x5(%r14), %eax
movl %eax, 0x2c(%rsp)
leal 0x14(%r14), %eax
movl %eax, 0x28(%rsp)
addl $0x19, %r14d
movq %r14, 0x38(%rsp)
leaq 0xb1a3f(%rip), %r15     # 0xd4bc0
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0xf0(%r12), %rax
movl (%rax,%r13,4), %eax
leaq (%rax,%rax,2), %rax
movsd (%r15,%rax,8), %xmm0
movsd 0x8(%r15,%rax,8), %xmm1
movsd 0x10(%r15,%rax,8), %xmm2
movq %rbx, %rdi
leaq 0x84d60(%rip), %rsi     # 0xa7f15
movb $0x3, %al
callq 0x42e0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x0, 0x24(%rsp)
je 0x231d0
movl 0xec(%r12), %ebp
addl %r14d, %ebp
imull 0x30(%rsp), %ebp
addl 0x34(%rsp), %ebp
movq 0x100(%r12), %rax
movq (%rax,%r13,8), %rsi
leaq 0x40(%rsp), %rdi
callq 0x4270
movq 0xf8(%r12), %rax
movsbl (%rax,%r13), %edi
movl $0x30, %esi
movl $0x36, %edx
callq 0x39a78
testl %eax, %eax
je 0x23245
leal 0xa(%rbp), %r8d
movq 0xf8(%r12), %rax
movsbl (%rax,%r13), %r9d
addl $-0x30, %r9d
movl $0x0, (%rsp)
movq %rbx, %rdi
movl 0x2c(%rsp), %esi
movl %ebp, %edx
movl 0x28(%rsp), %ecx
callq 0x235c0
jmp 0x233a3
movq 0xf8(%r12), %rax
movsbl (%rax,%r13), %edi
movl $0x61, %esi
movl $0x7a, %edx
callq 0x39a78
movq 0xf8(%r12), %rcx
movsbl (%rcx,%r13), %ecx
movswl %cx, %edi
testl %eax, %eax
je 0x2330b
addl $-0x61, %edi
imull $0x2aab, %edi, %eax     # imm = 0x2AAB
movl %eax, %ecx
shrl $0x1f, %ecx
shrl $0x11, %eax
addl %ecx, %eax
shll $0x2, %eax
leal (%rax,%rax,2), %eax
subl %eax, %edi
movswq %di, %rax
movl %eax, %eax
leaq (%rax,%rax,2), %rax
movsd (%r15,%rax,8), %xmm0
movsd 0x8(%r15,%rax,8), %xmm1
movsd 0x10(%r15,%rax,8), %xmm2
movq %rbx, %rdi
leaq 0x84c59(%rip), %rsi     # 0xa7f15
movb $0x3, %al
callq 0x42e0
movq 0xf8(%r12), %rax
movsbl (%rax,%r13), %eax
leal -0x61(%rax), %ecx
imull $0x6667, %ecx, %ecx     # imm = 0x6667
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x11, %ecx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
negl %ecx
addl %ecx, %eax
addl $-0x61, %eax
movswl %ax, %edx
movl %ebp, (%rsp)
movq %rbx, %rdi
leaq 0x84d23(%rip), %rsi     # 0xa8020
movl 0x2c(%rsp), %ecx
movl %ebp, %r8d
movl 0x28(%rsp), %r9d
jmp 0x23373
movl $0x41, %esi
movl $0x5a, %edx
callq 0x39a78
movq 0xf8(%r12), %rcx
movsbq (%rcx,%r13), %rdx
testl %eax, %eax
je 0x233d3
addl $-0x41, %edx
leaq (%rdx,%rdx,2), %rax
movsd (%r15,%rax,8), %xmm0
movsd 0x8(%r15,%rax,8), %xmm1
movsd 0x10(%r15,%rax,8), %xmm2
movq %rbx, %rdi
leaq 0x84bc1(%rip), %rsi     # 0xa7f15
movb $0x3, %al
callq 0x42e0
movq %rbx, %rdi
leaq 0x84cf5(%rip), %rsi     # 0xa805a
movl 0x2c(%rsp), %edx
movl %ebp, %ecx
movl 0x28(%rsp), %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x42e0
movsd 0xb183e(%rip), %xmm0    # 0xd4bc0
movsd 0xb183e(%rip), %xmm1    # 0xd4bc8
movsd 0xb183e(%rip), %xmm2    # 0xd4bd0
movq %rbx, %rdi
leaq 0x84b79(%rip), %rsi     # 0xa7f15
movb $0x3, %al
callq 0x42e0
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movl %ebp, %edx
leaq 0x40(%rsp), %rcx
xorl %r8d, %r8d
callq 0x23500
incq %r13
movslq 0xec(%r12), %rax
decl %r14d
cmpq %rax, %r13
jl 0x23187
jmp 0x23402
leaq 0xb0(%rsp), %rdi
leaq 0x84b69(%rip), %rsi     # 0xa7f4b
leaq 0x40(%rsp), %rcx
xorl %eax, %eax
callq 0x41b0
leaq 0x40(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x4270
jmp 0x233a3
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq