// File: /workspace/github_c_makefile_star2_O1/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 0x38c892(%rip), %r12    # 0x3af0b8
movslq 0xec(%r12), %r15
testq %r15, %r15
jle 0x22860
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 0x22840
cvtsi2sd %ebp, %xmm0
jmp 0x22864
xorpd %xmm0, %xmm0
testl %r15d, %r15d
setne %cl
movl 0xe8(%r12), %eax
cmpl $0x4, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x22c15
movsd 0x110(%r12), %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, 0x30(%rsp)
mulsd 0x824ab(%rip), %xmm1    # 0xa4d48
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %r8d
cmpl $0x3, %eax
ja 0x22902
movl %eax, %eax
leaq 0x82538(%rip), %rcx     # 0xa4dec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x23a, %edx            # imm = 0x23A
subl %r8d, %edx
jmp 0x228ef
movl $0x23a, %edx            # imm = 0x23A
subl %r8d, %edx
jmp 0x228d6
movl $0x5a, %edx
movl $0x230, %ecx            # imm = 0x230
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x0, 0x24(%rsp)
jmp 0x22910
movl $0x5a, %edx
movl $0x64, %ecx
movl $0x1, %eax
movb $0x1, %sil
movl %esi, 0x24(%rsp)
jmp 0x22910
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 0x8271c(%rip), %rsi     # 0xa5046
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 0x22cba
cmpl $0x0, 0xec(%r12)
jle 0x22c15
leal 0x5(%r14), %eax
movl %eax, 0x2c(%rsp)
leal 0x14(%r14), %eax
movl %eax, 0x28(%rsp)
addl $0x19, %r14d
movq %r14, 0x38(%rsp)
leaq 0xaf22f(%rip), %r15     # 0xd1bc0
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 0x824f8(%rip), %rsi     # 0xa4ebd
movb $0x3, %al
callq 0x42e0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x0, 0x24(%rsp)
je 0x229e0
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 0x38d18
testl %eax, %eax
je 0x22a55
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 0x22dd3
jmp 0x22bb6
movq 0xf8(%r12), %rax
movsbl (%rax,%r13), %edi
movl $0x61, %esi
movl $0x7a, %edx
callq 0x38d18
movq 0xf8(%r12), %rcx
movsbl (%rcx,%r13), %edi
testl %eax, %eax
je 0x22b1e
addl $-0x61, %edi
movslq %edi, %rax
imulq $0x2aaaaaab, %rax, %rcx # imm = 0x2AAAAAAB
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x21, %rcx
addl %edx, %ecx
shll $0x2, %ecx
leal (%rcx,%rcx,2), %ecx
subl %ecx, %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 0x823f3(%rip), %rsi     # 0xa4ebd
movb $0x3, %al
callq 0x42e0
movq 0xf8(%r12), %rax
movsbl (%rax,%r13), %eax
leal -0x61(%rax), %ecx
movslq %ecx, %rcx
imulq $0x66666667, %rcx, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x21, %rcx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
negl %ecx
leal (%rax,%rcx), %edx
addl $-0x61, %edx
movl %ebp, (%rsp)
movq %rbx, %rdi
leaq 0x824b8(%rip), %rsi     # 0xa4fc8
movl 0x2c(%rsp), %ecx
movl %ebp, %r8d
movl 0x28(%rsp), %r9d
jmp 0x22b86
movl $0x41, %esi
movl $0x5a, %edx
callq 0x38d18
movq 0xf8(%r12), %rcx
movsbq (%rcx,%r13), %rdx
testl %eax, %eax
je 0x22be6
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 0x82356(%rip), %rsi     # 0xa4ebd
movb $0x3, %al
callq 0x42e0
movq %rbx, %rdi
leaq 0x8248a(%rip), %rsi     # 0xa5002
movl 0x2c(%rsp), %edx
movl %ebp, %ecx
movl 0x28(%rsp), %r8d
movl %ebp, %r9d
xorl %eax, %eax
callq 0x42e0
movsd 0xaf02b(%rip), %xmm0    # 0xd1bc0
movsd 0xaf02b(%rip), %xmm1    # 0xd1bc8
movsd 0xaf02b(%rip), %xmm2    # 0xd1bd0
movq %rbx, %rdi
leaq 0x8230e(%rip), %rsi     # 0xa4ebd
movb $0x3, %al
callq 0x42e0
movq %rbx, %rdi
movq 0x38(%rsp), %rsi
movl %ebp, %edx
leaq 0x40(%rsp), %rcx
xorl %r8d, %r8d
callq 0x22d13
incq %r13
movslq 0xec(%r12), %rax
decl %r14d
cmpq %rax, %r13
jl 0x22997
jmp 0x22c15
leaq 0xb0(%rsp), %rdi
leaq 0x822fe(%rip), %rsi     # 0xa4ef3
leaq 0x40(%rsp), %rcx
xorl %eax, %eax
callq 0x41b0
leaq 0x40(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x4270
jmp 0x22bb6
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq