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

/* berechnet irgendeinen 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 zaehler, i,j, 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) && !gefunden; i++) 
  { gefunden= get_spiralcode ( F_eck_kanten[i], i, code, sixgons);
    (F_eck_kanten[i])->mininame=1; }

mark=61;

for (i=0; (i<60) && !gefunden; i++) 
  { gefunden= get_spiralcode_inv ( F_eck_kanten[i], mark, code, sixgons);
    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)
{
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) && !hexgefunden; i++) 
  for (j=0; j<3 && !hexgefunden; j++)
    if (!map[i][j].mininame) 
      { hexgefunden= get_spiralcode ( map[i]+j, mark, dummy, sixgons); mark++;
        if (!hexgefunden) 
	  { hexgefunden= get_spiralcode_inv ( map[i]+j, mark, dummy, sixgons); 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 $0x998, %rsp            # imm = 0x998
movq %rsi, %r14
movq %rdi, %r13
movzwl 0x2(%rdi), %eax
leal -0x14(%rax), %ecx
shrl $0x1f, %ecx
leal (%rax,%rcx), %ebp
addl $-0x14, %ebp
testl %eax, %eax
je 0x353a
incq %rax
leaq 0xa4(%r13), %rcx
movl $0x1, %edx
xorl %esi, %esi
movw $0x0, (%rcx,%rsi)
movq $0x0, -0xc(%rcx,%rsi)
addq $0x30, %rsi
cmpq $0x90, %rsi
jne 0x350f
incq %rdx
addq $0x90, %rcx
cmpq %rax, %rdx
jne 0x350d
sarl %ebp
movl $0xffffffff, 0x8(%r14)  # imm = 0xFFFFFFFF
movq $-0x1, (%r14)
leaq 0x11d1e(%rip), %rbx     # 0x15270
xorl %r15d, %r15d
movq (%rbx), %rdi
movl %r15d, %esi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x2c92
movq (%rbx), %rcx
movw $0x1, 0x14(%rcx)
cmpq $0x3a, %r15
ja 0x357f
incq %r15
addq $0x8, %rbx
testb %al, %al
je 0x3555
testb %al, %al
sete %r15b
movq %r13, 0x10(%rsp)
je 0x3596
movb $0x1, %bl
movl $0x3d, %r12d
jmp 0x35da
leaq 0x11cd3(%rip), %rbx     # 0x15270
xorl %r12d, %r12d
movq %r12, %r13
leal 0x3d(%r12), %esi
movq (%rbx), %rdi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x2dd0
incq %r12
testb %al, %al
sete %r15b
cmpq $0x3a, %r13
ja 0x35cc
addq $0x8, %rbx
testb %al, %al
je 0x35a0
testb %al, %al
setne %bl
addl $0x3d, %r12d
movq 0x10(%rsp), %r13
testb %r15b, %r15b
je 0x3663
incl 0x11b9f(%rip)           # 0x15188
leaq 0x30(%rsp), %rsi
movq %r13, %rdi
callq 0x339d
movl %eax, 0x18(%rsp)
leaq 0x11e4f(%rip), %rdi     # 0x15450
leaq 0xcc96(%rip), %rsi      # 0x1029e
callq 0x1120
testq %rax, %rax
je 0x37da
movq %rax, %r13
cmpb $0x0, 0x11c3c(%rip)     # 0x1525c
jne 0x363f
movb $0x1, 0x11c33(%rip)     # 0x1525c
leaq 0xcc5a(%rip), %rsi      # 0x1028a
movq %r13, %rdi
movl $0x6c, %edx
xorl %eax, %eax
callq 0x10b0
movslq 0x18(%rsp), %rdx
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
movq %r13, %rcx
callq 0x1180
movq %r13, %rdi
callq 0x1050
movq 0x10(%rsp), %r13
cmpb $0x0, 0x11b29(%rip)     # 0x15193
setne %al
orb %r15b, %al
cmpb $0x1, %al
jne 0x3736
testb %r15b, %r15b
jne 0x3691
leaq 0x20(%rsp), %r14
movl $0xffffffff, 0x8(%r14)  # imm = 0xFFFFFFFF
movq $-0x1, (%r14)
cmpw $0x0, 0x2(%r13)
je 0x3736
movb %bl, 0xf(%rsp)
leaq 0x90(%r13), %r15
movl $0x1, %ecx
xorl %eax, %eax
movq %rcx, 0x18(%rsp)
movq %r15, %r13
xorl %ebx, %ebx
cmpw $0x0, 0x14(%r13)
jne 0x36f4
movq %r13, %rdi
movl %r12d, %esi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x2c92
movl %eax, %ecx
leal 0x1(%r12), %esi
movb $0x1, %al
testb %cl, %cl
je 0x36e3
movl %esi, %r12d
jmp 0x36f4
movq %r13, %rdi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x2dd0
addl $0x2, %r12d
cmpq $0x1, %rbx
ja 0x3705
incq %rbx
addq $0x30, %r13
testb %al, %al
je 0x36b9
movq 0x10(%rsp), %r13
movzwl 0x2(%r13), %ecx
movq 0x18(%rsp), %rdx
cmpq %rcx, %rdx
jae 0x372a
movq %rdx, %rcx
incq %rcx
addq $0x90, %r15
testb %al, %al
je 0x36af
testb %al, %al
setne %r14b
movb 0xf(%rsp), %bl
jmp 0x3739
xorl %r14d, %r14d
cmpb $0x0, 0x11a53(%rip)     # 0x15193
je 0x37c0
testb %r14b, %r14b
jne 0x37c0
movl %ebx, %r15d
incl 0x11a3c(%rip)           # 0x1518c
leaq 0x30(%rsp), %rsi
movq %r13, %rdi
callq 0x339d
movl %eax, %ebp
leaq 0x11dba(%rip), %rdi     # 0x15520
leaq 0xcb31(%rip), %rsi      # 0x1029e
callq 0x1120
testq %rax, %rax
je 0x37df
movq %rax, %rbx
cmpb $0x0, 0x11adf(%rip)     # 0x15260
jne 0x37a0
movb $0x1, 0x11ad6(%rip)     # 0x15260
leaq 0xcaf9(%rip), %rsi      # 0x1028a
movq %rbx, %rdi
movl $0x6c, %edx
xorl %eax, %eax
callq 0x10b0
movslq %ebp, %rdx
leaq 0x30(%rsp), %rdi
movl $0x1, %esi
movq %rbx, %rcx
callq 0x1180
movq %rbx, %rdi
callq 0x1050
movl %r15d, %ebx
orb %r14b, %bl
andb $0x1, %bl
movl %ebx, %eax
addq $0x998, %rsp            # imm = 0x998
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1272
callq 0x124a