// File: sundale[P]gcode/tool_parse.cc
// Function: scan_old_style(char*, CANON_TOOL_TABLE*, int*, char**, int, int&)
static bool scan_old_style(
	char *buffer,
	CANON_TOOL_TABLE toolTable[],
	int fms[],
	char *ttcomments[],
	int random_toolchanger,
	int &fakepocket) {
    int scanned, toolno, pocket, orientation;
    double zoffset, xoffset, diameter, frontangle, backangle;
    char comment[CANON_TOOL_ENTRY_LEN];

    if((scanned = sscanf(buffer, "%d %d %lf %lf %lf %lf %lf %d %[^\n]",
			 &toolno, &pocket, &zoffset, &xoffset, &diameter,
			 &frontangle, &backangle, &orientation, comment)) &&
       (scanned == 8 || scanned == 9)) {
	if(!random_toolchanger) {
	    fakepocket++;
	    if(fakepocket >= CANON_POCKETS_MAX) {
		printf("too many tools. skipping tool %d\n", toolno);
		return true;
	    }
	    if(fms) fms[fakepocket] = pocket;
	    pocket = fakepocket;
	}
	if (pocket < 0 || pocket >= CANON_POCKETS_MAX) {
	    printf("max pocket number is %d. skipping tool %d\n", CANON_POCKETS_MAX-1, toolno);
	    return true;
	} else {
	    /* lathe tool */
	    toolTable[pocket].toolno = toolno;
	    toolTable[pocket].offset.tran.z = zoffset;
	    toolTable[pocket].offset.tran.x = xoffset;
	    toolTable[pocket].diameter = diameter;

	    toolTable[pocket].frontangle = frontangle;
	    toolTable[pocket].backangle = backangle;
	    toolTable[pocket].orientation = orientation;
	    if(ttcomments && scanned == 9) strcpy(ttcomments[pocket], comment);
	    return true;
	}
    } else if ((scanned = sscanf(buffer, "%d %d %lf %lf %[^\n]",
				 &toolno, &pocket, &zoffset, &diameter, comment)) &&
	       (scanned == 4 || scanned == 5)) {
	if(!random_toolchanger) {
	    fakepocket++;
	    if(fakepocket >= CANON_POCKETS_MAX) {
		printf("too many tools. skipping tool %d\n", toolno);
		return true;
	    }
	    if(fms) fms[fakepocket] = pocket;
	    pocket = fakepocket;
	}
	if (pocket < 0 || pocket >= CANON_POCKETS_MAX) {
	    printf("max pocket number is %d. skipping tool %d\n", CANON_POCKETS_MAX-1, toolno);
	    return true;
	} else {
	    /* mill tool */
	    toolTable[pocket].toolno = toolno;
	    toolTable[pocket].offset.tran.z = zoffset;
	    toolTable[pocket].diameter = diameter;

	    // these aren't used on a mill
	    toolTable[pocket].frontangle = toolTable[pocket].backangle = 0.0;
	    toolTable[pocket].offset.tran.x = 0.0;
	    toolTable[pocket].orientation = 0;
	    if(ttcomments && scanned == 5) strcpy(ttcomments[pocket], comment);
	    return true;
	}
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movl %r8d, -0x3c(%rbp)
movq %r9, -0x48(%rbp)
movq -0x20(%rbp), %rdi
leaq -0x180(%rbp), %rax
leaq 0x19b4(%rip), %rsi      # 0xbb0c
leaq -0x50(%rbp), %rdx
leaq -0x54(%rbp), %rcx
leaq -0x60(%rbp), %r8
leaq -0x68(%rbp), %r9
leaq -0x70(%rbp), %r14
leaq -0x78(%rbp), %rbx
leaq -0x80(%rbp), %r11
leaq -0x58(%rbp), %r10
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, %al
callq 0x4180
movl %eax, -0x4c(%rbp)
cmpl $0x0, %eax
je 0xa307
cmpl $0x8, -0x4c(%rbp)
je 0xa1b3
cmpl $0x9, -0x4c(%rbp)
jne 0xa307
cmpl $0x0, -0x3c(%rbp)
jne 0xa208
movq -0x48(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
cmpl $0x38, (%rax)
jl 0xa1e7
movl -0x50(%rbp), %esi
leaq 0x18ca(%rip), %rdi      # 0xbaa1
movb $0x0, %al
callq 0x4030
movb $0x1, -0x11(%rbp)
jmp 0xa4a2
cmpq $0x0, -0x30(%rbp)
je 0xa1ff
movl -0x54(%rbp), %edx
movq -0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq (%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x48(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jl 0xa214
cmpl $0x38, -0x54(%rbp)
jl 0xa233
movl -0x50(%rbp), %edx
leaq 0x18a5(%rip), %rdi      # 0xbac3
movl $0x37, %esi
movb $0x0, %al
callq 0x4030
movb $0x1, -0x11(%rbp)
jmp 0xa4a2
movl -0x50(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movsd -0x60(%rbp), %xmm0
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x18(%rax)
movsd -0x68(%rbp), %xmm0
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movsd -0x70(%rbp), %xmm0
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x50(%rax)
movsd -0x78(%rbp), %xmm0
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x58(%rax)
movsd -0x80(%rbp), %xmm0
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x60(%rax)
movl -0x58(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x68(%rax)
cmpq $0x0, -0x38(%rbp)
je 0xa2fe
cmpl $0x9, -0x4c(%rbp)
jne 0xa2fe
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x180(%rbp), %rsi
callq 0x4170
movb $0x1, -0x11(%rbp)
jmp 0xa4a2
movq -0x20(%rbp), %rdi
leaq -0x180(%rbp), %rax
leaq 0x1816(%rip), %rsi      # 0xbb2f
leaq -0x50(%rbp), %rdx
leaq -0x54(%rbp), %rcx
leaq -0x60(%rbp), %r8
leaq -0x70(%rbp), %r9
movq %rax, (%rsp)
movb $0x0, %al
callq 0x4180
movl %eax, -0x4c(%rbp)
cmpl $0x0, %eax
je 0xa49c
cmpl $0x4, -0x4c(%rbp)
je 0xa350
cmpl $0x5, -0x4c(%rbp)
jne 0xa49c
cmpl $0x0, -0x3c(%rbp)
jne 0xa3a5
movq -0x48(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
cmpl $0x38, (%rax)
jl 0xa384
movl -0x50(%rbp), %esi
leaq 0x172d(%rip), %rdi      # 0xbaa1
movb $0x0, %al
callq 0x4030
movb $0x1, -0x11(%rbp)
jmp 0xa4a2
cmpq $0x0, -0x30(%rbp)
je 0xa39c
movl -0x54(%rbp), %edx
movq -0x30(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq (%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x48(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jl 0xa3b1
cmpl $0x38, -0x54(%rbp)
jl 0xa3d0
movl -0x50(%rbp), %edx
leaq 0x1708(%rip), %rdi      # 0xbac3
movl $0x37, %esi
movb $0x0, %al
callq 0x4030
movb $0x1, -0x11(%rbp)
jmp 0xa4a2
movl -0x50(%rbp), %ecx
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rdx
imulq $0x70, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movsd -0x60(%rbp), %xmm0
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x18(%rax)
movsd -0x70(%rbp), %xmm0
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x50(%rax)
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x60(%rax)
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x58(%rax)
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rax)
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x70, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x68(%rax)
cmpq $0x0, -0x38(%rbp)
je 0xa496
cmpl $0x5, -0x4c(%rbp)
jne 0xa496
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x180(%rbp), %rsi
callq 0x4170
movb $0x1, -0x11(%rbp)
jmp 0xa4a2
jmp 0xa49e
movb $0x0, -0x11(%rbp)
movb -0x11(%rbp), %al
andb $0x1, %al
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbx
popq %r14
popq %rbp
retq