// File: /workspace/github_c_makefile_star2_O3/mishun[P]plantri/fullgen.c
// Function: minspiralcode
BOOL minspiralcode(PLANMAP map, FLAECHENTYP code[12])

/* berechnet den minimalen Spiralcode von map und schreibt ihn in code.
   Gibt 1 zurueck, wenn der gefunden wurde und 0 sonst. versucht zuerst
   einen Code zu finden, der an einem 5-Eck startet. */

{ int i,j, zaehler, mark, sixgons;
  BOOL gefunden=0, hexgefunden=0;
  FLAECHENTYP codeF[2*(81+8*S)];
  FILE *fil2;
  FLAECHENTYP dummycode[12];
  FLAECHENTYP *dummy;
  static int write_nopentaheader=1, write_nohexaheader=1;


/*schreibemap(map);*/

sixgons= (map[0][0].name - 20)/2;

for (i=1; i<=map[0][0].name; i++)
  for (j=0; j<3; j++) { map[i][j].dummy=map[i][j].mininame=0; }
for (i=0; i<12; i++) code[i]=FL_MAX;



for (i=0; (i<60); i++) 
  { if (get_spiralcode ( F_eck_kanten[i], i, code, sixgons)) gefunden=1;
    (F_eck_kanten[i])->mininame=1; }

mark=61;

for (i=0; (i<60); i++) 
  { if (get_spiralcode_inv ( F_eck_kanten[i], mark, code, sixgons)) gefunden=1;
    mark++; }


if (!gefunden) { no_penta_spiral++;
		 zaehler=longcode(map,codeF);
		fil2=fopen(no_penta_spiral_filename,"ab");
		if (fil2==NULL) { fprintf(stderr,"Can't open %s\n",no_penta_spiral_filename);
		                  exit(1); }
		if (write_nopentaheader)
		  { write_nopentaheader=0;
		  fprintf(fil2,">>planar_code %ce<<", my_endianness);
		  }
		fwrite(codeF,sizeof(FLAECHENTYP),zaehler,fil2);
		fclose(fil2);
	       }


if (!gefunden || hexspi) /* sonst waeren die neuen codes eh alle groesser */
{
if (!gefunden) dummy=code; else
  { for (i=0; i<12; i++) dummycode[i]=FL_MAX; dummy=dummycode; }
for (i=1; (i<=map[0][0].name); i++) 
  for (j=0; j<3 ; j++)
    if (!map[i][j].mininame) 
      { if (get_spiralcode ( map[i]+j, mark, dummy, sixgons)) hexgefunden=1; mark++; 
	if (get_spiralcode_inv ( map[i]+j, mark, dummy, sixgons)) hexgefunden=1; mark++; 
      }
}

if (hexspi && !hexgefunden) { no_hexa_spiral++;
		 zaehler=longcode(map,codeF);
		fil2=fopen(no_hexa_spiral_filename,"ab");
		if (fil2==NULL) { fprintf(stderr,"Can't open %s\n",no_hexa_spiral_filename);
		                  exit(1); }
		if (write_nohexaheader)
		  { write_nohexaheader=0;
		  fprintf(fil2,">>planar_code %ce<<", my_endianness);
		  }
		fwrite(codeF,sizeof(FLAECHENTYP),zaehler,fil2);
		fclose(fil2);
	       }


return(gefunden || hexgefunden);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x9a8, %rsp            # imm = 0x9A8
movq %rsi, %r12
movzwl 0x2(%rdi), %eax
leal -0x14(%rax), %ecx
shrl $0x1f, %ecx
leal (%rax,%rcx), %ebp
addl $-0x14, %ebp
testl %eax, %eax
je 0x386e
incq %rax
leaq 0xa4(%rdi), %rcx
movl $0x1, %edx
xorl %esi, %esi
movw $0x0, (%rcx,%rsi)
movq $0x0, -0xc(%rcx,%rsi)
addq $0x30, %rsi
cmpq $0x90, %rsi
jne 0x3843
incq %rdx
addq $0x90, %rcx
cmpq %rax, %rdx
jne 0x3841
movq %rdi, (%rsp)
sarl %ebp
movl $0xffffffff, 0x8(%r12)  # imm = 0xFFFFFFFF
movq $-0x1, (%r12)
leaq 0x119e4(%rip), %r14     # 0x15270
xorl %r15d, %r15d
movl $0x1, %r13d
xorl %ebx, %ebx
movq (%r14), %rdi
movl %r15d, %esi
movq %r12, %rdx
movl %ebp, %ecx
callq 0x2c42
testb %al, %al
movzbl %bl, %ebx
cmovnel %r13d, %ebx
movq (%r14), %rax
movw $0x1, 0x14(%rax)
incq %r15
addq $0x8, %r14
cmpq $0x3c, %r15
jne 0x3897
movl $0x3d, %r15d
xorl %r14d, %r14d
movq %r12, %r13
movl $0x1, %r12d
leaq 0x11991(%rip), %rax     # 0x15270
movq (%r14,%rax), %rdi
movl %r15d, %esi
movq %r13, %rdx
movl %ebp, %ecx
callq 0x2d87
testb %al, %al
movzbl %bl, %ebx
cmovnel %r12d, %ebx
incl %r15d
addq $0x8, %r14
cmpq $0x1e0, %r14            # imm = 0x1E0
jne 0x38d8
movl %ebp, 0x10(%rsp)
movl %ebx, 0xc(%rsp)
testb %bl, %bl
je 0x393e
cmpb $0x0, 0x11877(%rip)     # 0x15193
movq (%rsp), %r13
je 0x3a7f
leaq 0x30(%rsp), %rbx
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
movq $-0x1, (%rbx)
jmp 0x39c0
movq %r13, %r14
incl 0x11841(%rip)           # 0x15188
leaq 0x40(%rsp), %rsi
movq (%rsp), %r13
movq %r13, %rdi
callq 0x33bc
movl %eax, %r12d
leaq 0x11aee(%rip), %rdi     # 0x15450
leaq 0xc9a1(%rip), %rsi      # 0x1030a
callq 0x1120
testq %rax, %rax
je 0x3b27
movq %rax, %r15
cmpb $0x0, 0x11c67(%rip)     # 0x155e8
jne 0x39a0
movb $0x1, 0x11c5e(%rip)     # 0x155e8
leaq 0xc965(%rip), %rsi      # 0x102f6
movq %r15, %rdi
movl $0x6c, %edx
xorl %eax, %eax
callq 0x10b0
movslq %r12d, %rdx
leaq 0x40(%rsp), %rdi
movl $0x1, %esi
movq %r15, %rcx
callq 0x1180
movq %r15, %rdi
callq 0x1050
movq %r14, %rbx
cmpw $0x0, 0x2(%r13)
je 0x3a7f
movq %rbx, 0x28(%rsp)
leaq 0x90(%r13), %r12
movl $0x79, %r15d
movl $0x1, %eax
xorl %edx, %edx
movq 0x28(%rsp), %rbx
movl 0x10(%rsp), %r14d
movq %rax, 0x18(%rsp)
movl $0x3, %ebp
movq %r12, 0x20(%rsp)
cmpw $0x0, 0x14(%r12)
jne 0x3a47
movq %r12, %rdi
movl %r15d, %esi
movl %edx, 0x14(%rsp)
movq %rbx, %rdx
movl %r14d, %ecx
callq 0x2c42
movl %eax, %r13d
leal 0x1(%r15), %esi
movq %r12, %rdi
movq %rbx, %rdx
movl %r14d, %ecx
callq 0x2d87
movl 0x14(%rsp), %edx
orb %r13b, %al
movzbl %dl, %edx
movl $0x1, %eax
cmovnel %eax, %edx
addl $0x2, %r15d
addq $0x30, %r12
decq %rbp
jne 0x39fe
movq 0x18(%rsp), %rsi
leaq 0x1(%rsi), %rax
movq (%rsp), %r13
movzwl 0x2(%r13), %ecx
movq 0x20(%rsp), %r12
addq $0x90, %r12
cmpq %rcx, %rsi
jb 0x39ef
testb %dl, %dl
setne %r15b
jmp 0x3a82
xorl %r15d, %r15d
cmpb $0x0, 0x1170a(%rip)     # 0x15193
je 0x3b03
testb %r15b, %r15b
jne 0x3b03
incl 0x116f6(%rip)           # 0x1518c
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
callq 0x33bc
movl %eax, %ebp
leaq 0x11a74(%rip), %rdi     # 0x15520
leaq 0xc857(%rip), %rsi      # 0x1030a
callq 0x1120
testq %rax, %rax
je 0x3b22
movq %rax, %r14
cmpb $0x0, 0x11b25(%rip)     # 0x155ec
jne 0x3ae6
movb $0x1, 0x11b1c(%rip)     # 0x155ec
leaq 0xc81f(%rip), %rsi      # 0x102f6
movq %r14, %rdi
movl $0x6c, %edx
xorl %eax, %eax
callq 0x10b0
movslq %ebp, %rdx
leaq 0x40(%rsp), %rdi
movl $0x1, %esi
movq %r14, %rcx
callq 0x1180
movq %r14, %rdi
callq 0x1050
cmpb $0x0, 0xc(%rsp)
setne %al
orb %r15b, %al
andb $0x1, %al
addq $0x9a8, %rsp            # imm = 0x9A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x129a
callq 0x12c2