// File: /workspace/github_c_makefile_star2_O2/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 0x389b78(%rip), %r14    # 0x3aa0b8
movl 0xec(%r14), %eax
movq 0x100(%r14), %r12
xorl %r13d, %r13d
testl %eax, %eax
movl $0x0, %ebp
movl %eax, 0x30(%rsp)
cmovgl %eax, %ebp
xorl %r15d, %r15d
cmpq %r13, %rbp
je 0x20582
movq (%r12,%r13,8), %rdi
callq 0x4190
movslq %r15d, %rcx
cmpq %rcx, %rax
cmovbel %r15d, %eax
incq %r13
movl %eax, %r15d
jmp 0x20562
movl 0x30(%rsp), %r9d
testl %r9d, %r9d
setne %cl
movl 0xe8(%r14), %eax
cmpl $0x4, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x20846
movsd 0x110(%r14), %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, 0x2c(%rsp)
mulsd 0x77792(%rip), %xmm0    # 0x97d50
cvtsi2sd %r15d, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r8d
pushq $-0x1
popq %r15
cmpl $0x3, %eax
ja 0x20625
movl %eax, %eax
leaq 0x777f6(%rip), %rcx     # 0x97dd4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x23a, %r12d           # imm = 0x23A
subl %r8d, %r12d
jmp 0x20617
movl $0x23a, %r12d           # imm = 0x23A
subl %r8d, %r12d
jmp 0x20601
pushq $0x5a
popq %r12
movl $0x230, %ecx            # imm = 0x230
movl $0x0, 0x20(%rsp)
movl %r15d, %eax
jmp 0x20634
pushq $0x5a
popq %r12
pushq $0x64
popq %rcx
pushq $0x1
popq %rax
movb $0x1, %dl
movl %edx, 0x20(%rsp)
jmp 0x20634
movl $0x0, 0x20(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r12d, %r12d
addl %r12d, %r8d
incl %r9d
imull %eax, %r9d
imull 0x2c(%rsp), %r9d
addl %ecx, %r9d
leaq 0x779d0(%rip), %rsi     # 0x9801e
movq %rbx, %rdi
movl %r12d, %edx
movl %ecx, 0x3c(%rsp)
xorl %eax, %eax
callq 0x42e0
movq 0x118(%r14), %rax
movq %rax, 0x10(%rsp)
movups 0x108(%r14), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x208eb
leal 0x5(%r12), %eax
movl %eax, 0x28(%rsp)
leal 0x14(%r12), %eax
movl %eax, 0x24(%rsp)
addl $0x19, %r12d
movq %r12, 0x30(%rsp)
leaq 0xb0(%rsp), %r13
xorl %r12d, %r12d
movslq 0xec(%r14), %rax
cmpq %rax, %r12
jge 0x20846
movq 0xf0(%r14), %rax
movl (%rax,%r12,4), %esi
movq %rbx, %rdi
callq 0x2004b
movl 0xec(%r14), %eax
leal (%r15,%rax), %ebp
incl %ebp
cmpb $0x0, 0x20(%rsp)
cmovel %r15d, %ebp
imull 0x2c(%rsp), %ebp
addl 0x3c(%rsp), %ebp
movq 0x100(%r14), %rax
movq (%rax,%r12,8), %rsi
movq %r13, %rdi
callq 0x4270
movq 0xf8(%r14), %rax
movsbl (%rax,%r12), %edi
pushq $0x30
popq %rsi
pushq $0x36
popq %rdx
callq 0x34c00
testl %eax, %eax
je 0x20744
leal 0xa(%rbp), %r8d
movq 0xf8(%r14), %rax
movsbl (%rax,%r12), %r9d
addl $-0x30, %r9d
andl $0x0, (%rsp)
movq %rbx, %rdi
movl 0x28(%rsp), %esi
movl %ebp, %edx
movl 0x24(%rsp), %ecx
callq 0x209ea
jmp 0x20801
movq 0xf8(%r14), %rax
movsbl (%rax,%r12), %edi
pushq $0x61
popq %rsi
pushq $0x7a
popq %rdx
callq 0x34c00
movl %eax, %ecx
movq 0xf8(%r14), %rax
movsbl (%rax,%r12), %eax
cwtl
testl %ecx, %ecx
je 0x207b8
addl $-0x61, %eax
cwtd
movw $0xc, %cx
idivw %cx
movswl %dx, %esi
movq %rbx, %rdi
callq 0x2004b
movq 0xf8(%r14), %rax
movsbl (%rax,%r12), %eax
addl $-0x61, %eax
cwtd
movw $0x5, %cx
idivw %cx
movswl %dx, %r9d
movq %rbx, %rdi
movl 0x28(%rsp), %esi
movl %ebp, %edx
movl 0x24(%rsp), %ecx
movl %ebp, %r8d
callq 0x2087e
jmp 0x207f7
movl %eax, %edi
pushq $0x41
popq %rsi
pushq $0x5a
popq %rdx
callq 0x34c00
movq 0xf8(%r14), %rcx
movsbl (%rcx,%r12), %edx
testl %eax, %eax
je 0x20821
addl $-0x41, %edx
movq %rbx, %rdi
movl %edx, %esi
callq 0x2004b
movq %rbx, %rdi
movl 0x28(%rsp), %esi
movl %ebp, %edx
movl 0x24(%rsp), %ecx
movl %ebp, %r8d
callq 0x20866
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2004b
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
movl %ebp, %edx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x20944
incq %r12
decl %r15d
jmp 0x206a5
leaq 0x40(%rsp), %rdi
leaq 0x7769e(%rip), %rsi     # 0x97ecb
movq %r13, %rcx
xorl %eax, %eax
callq 0x41b0
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
callq 0x4270
jmp 0x20801
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq