// File: /workspace/github_c_makefile_star2_O1/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, %r13
movzwl 0x2(%rdi), %eax
leal -0x14(%rax), %ecx
shrl $0x1f, %ecx
leal (%rax,%rcx), %r12d
addl $-0x14, %r12d
testl %eax, %eax
je 0x384a
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 0x381f
incq %rdx
addq $0x90, %rcx
cmpq %rax, %rdx
jne 0x381d
movq %rdi, 0x10(%rsp)
sarl %r12d
movl $0xffffffff, 0x8(%r13)  # imm = 0xFFFFFFFF
movq $-0x1, (%r13)
leaq 0x11a07(%rip), %r14     # 0x15270
xorl %r15d, %r15d
movl $0x1, %ebp
xorl %ebx, %ebx
movq (%r14), %rdi
movl %r15d, %esi
movq %r13, %rdx
movl %r12d, %ecx
callq 0x2c92
testb %al, %al
movzbl %bl, %ebx
cmovnel %ebp, %ebx
movq (%r14), %rax
movw $0x1, 0x14(%rax)
incq %r15
addq $0x8, %r14
cmpq $0x3c, %r15
jne 0x3873
movl $0x3d, %r15d
xorl %r14d, %r14d
movl %ebx, %ebp
movl $0x1, %ebx
leaq 0x119b7(%rip), %rax     # 0x15270
movq (%r14,%rax), %rdi
movl %r15d, %esi
movq %r13, %rdx
movl %r12d, %ecx
callq 0x2dd0
testb %al, %al
movzbl %bpl, %ebp
cmovnel %ebx, %ebp
incl %r15d
addq $0x8, %r14
cmpq $0x1e0, %r14            # imm = 0x1E0
jne 0x38b2
movl %r12d, 0x8(%rsp)
movq %r13, %rbx
testb %bpl, %bpl
movq 0x10(%rsp), %r13
jne 0x396e
incl 0x1188c(%rip)           # 0x15188
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
callq 0x339d
movl %eax, %r12d
leaq 0x11b3d(%rip), %rdi     # 0x15450
leaq 0xc984(%rip), %rsi      # 0x1029e
callq 0x1120
testq %rax, %rax
je 0x3b06
movq %rax, %r15
cmpb $0x0, 0x11cb6(%rip)     # 0x155e8
jne 0x3951
movb $0x1, 0x11cad(%rip)     # 0x155e8
leaq 0xc948(%rip), %rsi      # 0x1028a
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
movl %ebp, 0x4(%rsp)
testb %bpl, %bpl
je 0x3984
cmpb $0x0, 0x11815(%rip)     # 0x15193
je 0x3a5e
cmpb $0x0, 0x4(%rsp)
je 0x399e
leaq 0x30(%rsp), %rbx
movl $0xffffffff, 0x8(%rbx)  # imm = 0xFFFFFFFF
movq $-0x1, (%rbx)
cmpw $0x0, 0x2(%r13)
je 0x3a5e
movq %rbx, 0x28(%rsp)
leaq 0x90(%r13), %r12
movl $0x79, %r15d
movl $0x1, %eax
xorl %edx, %edx
movq 0x28(%rsp), %rbx
movl 0x8(%rsp), %r14d
movq %rax, 0x18(%rsp)
movl $0x3, %ebp
movq %r12, 0x20(%rsp)
cmpw $0x0, 0x14(%r12)
jne 0x3a25
movq %r12, %rdi
movl %r15d, %esi
movl %edx, 0xc(%rsp)
movq %rbx, %rdx
movl %r14d, %ecx
callq 0x2c92
movl %eax, %r13d
leal 0x1(%r15), %esi
movq %r12, %rdi
movq %rbx, %rdx
movl %r14d, %ecx
callq 0x2dd0
movl 0xc(%rsp), %edx
orb %r13b, %al
movzbl %dl, %edx
movl $0x1, %eax
cmovnel %eax, %edx
addl $0x2, %r15d
addq $0x30, %r12
decq %rbp
jne 0x39dc
movq 0x18(%rsp), %rsi
leaq 0x1(%rsi), %rax
movq 0x10(%rsp), %r13
movzwl 0x2(%r13), %ecx
movq 0x20(%rsp), %r12
addq $0x90, %r12
cmpq %rcx, %rsi
jb 0x39cd
testb %dl, %dl
setne %r15b
jmp 0x3a61
xorl %r15d, %r15d
cmpb $0x0, 0x1172b(%rip)     # 0x15193
je 0x3ae2
testb %r15b, %r15b
jne 0x3ae2
incl 0x11717(%rip)           # 0x1518c
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
callq 0x339d
movl %eax, %ebp
leaq 0x11a95(%rip), %rdi     # 0x15520
leaq 0xc80c(%rip), %rsi      # 0x1029e
callq 0x1120
testq %rax, %rax
je 0x3b01
movq %rax, %r14
cmpb $0x0, 0x11b46(%rip)     # 0x155ec
jne 0x3ac5
movb $0x1, 0x11b3d(%rip)     # 0x155ec
leaq 0xc7d4(%rip), %rsi      # 0x1028a
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, 0x4(%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