// File: /workspace/github_cpp_makefile_star2_O2/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_setup_tool(block_struct*, setup_struct*)
int Interp::convert_setup_tool(block_pointer block, setup_pointer settings) {
    int pocket = -1, toolno;
    int q;

    is_near_int(&toolno, block->p_number);

    CHP((find_tool_pocket(settings, toolno, &pocket)));

    settings->tool_table[pocket].toolno = toolno;

    if(block->x_flag) {
        double x = block->x_number;
        if (block->l_number == 10) x = settings->current_x + settings->tool_offset.tran.x - x;
        settings->tool_table[pocket].offset.tran.x = PROGRAM_TO_USER_LEN(x);
    }
    if(block->y_flag) {
        double y = block->y_number;
        if (block->l_number == 10) y = settings->current_y + settings->tool_offset.tran.y - y;
        settings->tool_table[pocket].offset.tran.y = PROGRAM_TO_USER_LEN(y);
    }
    if(block->z_flag) {
        double z = block->z_number;
        if (block->l_number == 10) z = settings->current_z + settings->tool_offset.tran.z - z;
        settings->tool_table[pocket].offset.tran.z = PROGRAM_TO_USER_LEN(z);
    }
    if(block->a_flag) {
        double a = block->a_number;
        if (block->l_number == 10) a = settings->AA_current + settings->tool_offset.a - a;
        settings->tool_table[pocket].offset.a = PROGRAM_TO_USER_ANG(a);
    }
    if(block->b_flag) {
        double b = block->b_number;
        if (block->l_number == 10) b = settings->BB_current + settings->tool_offset.b - b;
        settings->tool_table[pocket].offset.b = PROGRAM_TO_USER_ANG(b);
    }
    if(block->c_flag) {
        double c = block->c_number;
        if (block->l_number == 10) c = settings->CC_current + settings->tool_offset.c - c;
        settings->tool_table[pocket].offset.c = PROGRAM_TO_USER_ANG(c);
    }
    if(block->u_flag) {
        double u = block->u_number;
        if (block->l_number == 10) u = settings->u_current + settings->tool_offset.u - u;
        settings->tool_table[pocket].offset.u = PROGRAM_TO_USER_LEN(u);
    }
    if(block->v_flag) {
        double v = block->v_number;
        if (block->l_number == 10) v = settings->v_current + settings->tool_offset.v - v;
        settings->tool_table[pocket].offset.v = PROGRAM_TO_USER_LEN(v);
    }
    if(block->w_flag) {
        double w = block->w_number;
        if (block->l_number == 10) w = settings->w_current + settings->tool_offset.w - w;
        settings->tool_table[pocket].offset.w = PROGRAM_TO_USER_LEN(w);
    }

    if(block->r_flag) settings->tool_table[pocket].diameter = PROGRAM_TO_USER_LEN(block->r_number) * 2.;
    if(block->i_flag) settings->tool_table[pocket].frontangle = block->i_number;
    if(block->j_flag) settings->tool_table[pocket].backangle = block->j_number;
    if(block->q_number != -1.0) {
        CHKS((!is_near_int(&q, block->q_number)), "Q number in G10 is not an integer");
        CHKS((q > 9), "Invalid tool orientation");
        settings->tool_table[pocket].orientation = q;
    }

    SET_TOOL_TABLE_ENTRY(pocket,
                             settings->tool_table[pocket].toolno,
                             settings->tool_table[pocket].offset,
                             settings->tool_table[pocket].diameter,
                             settings->tool_table[pocket].frontangle,
                             settings->tool_table[pocket].backangle,
                             settings->tool_table[pocket].orientation);

    if(settings->current_pocket == pocket) {
       settings->tool_table[0] = settings->tool_table[pocket];
    }

    if (settings->tool_table[0].toolno < 0) {
      settings->parameters[5400] = 0; // -1 ==> notool
    } else {
      settings->parameters[5400] = settings->tool_table[0].toolno;
    }
    settings->parameters[5401] = settings->tool_table[0].offset.tran.x;
    settings->parameters[5402] = settings->tool_table[0].offset.tran.y;
    settings->parameters[5403] = settings->tool_table[0].offset.tran.z;
    settings->parameters[5404] = settings->tool_table[0].offset.a;
    settings->parameters[5405] = settings->tool_table[0].offset.b;
    settings->parameters[5406] = settings->tool_table[0].offset.c;
    settings->parameters[5407] = settings->tool_table[0].offset.u;
    settings->parameters[5408] = settings->tool_table[0].offset.v;
    settings->parameters[5409] = settings->tool_table[0].offset.w;
    settings->parameters[5410] = settings->tool_table[0].diameter;
    settings->parameters[5411] = settings->tool_table[0].frontangle;
    settings->parameters[5412] = settings->tool_table[0].backangle;
    settings->parameters[5413] = settings->tool_table[0].orientation;

    //persuade axis-gui to update parameters widget for current tool:
    if (   !_setup.random_toolchanger
        && toolno == settings->current_pocket) {
        SET_TOOL_TABLE_ENTRY(0,
                             settings->tool_table[pocket].toolno,
                             settings->tool_table[pocket].offset,
                             settings->tool_table[pocket].diameter,
                             settings->tool_table[pocket].frontangle,
                             settings->tool_table[pocket].backangle,
                             settings->tool_table[pocket].orientation);
    }

    return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r15
leaq -0x2c(%rbp), %rcx
orl $-0x1, (%rcx)
movsd 0x210(%rsi), %xmm0
addsd 0x18ec1(%rip), %xmm0    # 0x2e008
cvttsd2si %xmm0, %r14d
movq %rdx, %rsi
movl %r14d, %edx
callq 0xb9d0
testl %eax, %eax
je 0x151bc
movl %eax, %r12d
movq 0x27dfb(%rip), %rbx     # 0x3cf60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x15869
imulq $0x50, %rax, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x1b79d(%rip), %rsi     # 0x30929
pushq $0x50
popq %rdx
callq 0xb940
movslq 0xd670(%rbx), %rax
imulq $0x50, %rax, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0x15869
movq %r15, %r12
leaq 0xd6c8(%rbx), %r15
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movl %r14d, 0xd6c8(%rbx,%rcx)
cmpb $0x1, 0x270(%r13)
jne 0x1525f
movsd 0x278(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x1520b
movsd 0x600(%rbx), %xmm0
addsd 0xd678(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x27d4e(%rip), %rax     # 0x3cf60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x15235
movb %cl, %al
leaq 0x1ad62(%rip), %rcx     # 0x2ff90
movsd (%rcx,%rax,8), %xmm0
jmp 0x1523d
movsd 0x1ac8b(%rip), %xmm0    # 0x2fec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xba40
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x8(%r15,%rcx)
cmpb $0x1, 0x280(%r13)
jne 0x152e8
movsd 0x288(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x15294
movsd 0x608(%rbx), %xmm0
addsd 0xd680(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x27cc5(%rip), %rax     # 0x3cf60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x152be
movb %cl, %al
leaq 0x1acd9(%rip), %rcx     # 0x2ff90
movsd (%rcx,%rax,8), %xmm0
jmp 0x152c6
movsd 0x1ac02(%rip), %xmm0    # 0x2fec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xba40
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x10(%r15,%rcx)
cmpb $0x1, 0x290(%r13)
jne 0x15371
movsd 0x298(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x1531d
movsd 0x610(%rbx), %xmm0
addsd 0xd688(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x27c3c(%rip), %rax     # 0x3cf60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x15347
movb %cl, %al
leaq 0x1ac50(%rip), %rcx     # 0x2ff90
movsd (%rcx,%rax,8), %xmm0
jmp 0x1534f
movsd 0x1ab79(%rip), %xmm0    # 0x2fec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xba40
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x18(%r15,%rcx)
cmpb $0x1, (%r13)
jne 0x153be
movsd 0x8(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x153a0
movsd 0x8(%rbx), %xmm0
addsd 0xd690(%rbx), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x153a5
movsd %xmm1, -0x38(%rbp)
callq 0xc090
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x20(%r15,%rcx)
cmpb $0x1, 0x10(%r13)
jne 0x1540b
movsd 0x18(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x153ed
movsd 0x20(%rbx), %xmm0
addsd 0xd698(%rbx), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x153f2
movsd %xmm1, -0x38(%rbp)
callq 0xc090
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x28(%r15,%rcx)
cmpb $0x1, 0x20(%r13)
jne 0x15458
movsd 0x28(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x1543a
movsd 0x38(%rbx), %xmm0
addsd 0xd6a0(%rbx), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x1543f
movsd %xmm1, -0x38(%rbp)
callq 0xc090
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x30(%r15,%rcx)
cmpb $0x1, 0x244(%r13)
jne 0x154de
movsd 0x248(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x1548a
movsd 0x50(%rbx), %xmm0
addsd 0xd6a8(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x27acf(%rip), %rax     # 0x3cf60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x154b4
movb %cl, %al
leaq 0x1aae3(%rip), %rcx     # 0x2ff90
movsd (%rcx,%rax,8), %xmm0
jmp 0x154bc
movsd 0x1aa0c(%rip), %xmm0    # 0x2fec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xba40
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x38(%r15,%rcx)
cmpb $0x1, 0x250(%r13)
jne 0x15564
movsd 0x258(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x15510
movsd 0x68(%rbx), %xmm0
addsd 0xd6b0(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x27a49(%rip), %rax     # 0x3cf60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x1553a
movb %cl, %al
leaq 0x1aa5d(%rip), %rcx     # 0x2ff90
movsd (%rcx,%rax,8), %xmm0
jmp 0x15542
movsd 0x1a986(%rip), %xmm0    # 0x2fec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xba40
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x40(%r15,%rcx)
cmpb $0x1, 0x260(%r13)
jne 0x155ed
movsd 0x268(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x15599
movsd 0x80(%rbx), %xmm0
addsd 0xd6b8(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x279c0(%rip), %rax     # 0x3cf60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x155c3
movb %cl, %al
leaq 0x1a9d4(%rip), %rcx     # 0x2ff90
movsd (%rcx,%rax,8), %xmm0
jmp 0x155cb
movsd 0x1a8fd(%rip), %xmm0    # 0x2fec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xba40
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x48(%r15,%rcx)
cmpb $0x1, 0x229(%r13)
jne 0x15654
movq 0x27962(%rip), %rax     # 0x3cf60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x15621
movb %cl, %al
leaq 0x1a976(%rip), %rcx     # 0x2ff90
movsd (%rcx,%rax,8), %xmm0
jmp 0x15629
movsd 0x1a89f(%rip), %xmm0    # 0x2fec8
mulsd 0x230(%r13), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0xba40
mulsd -0x38(%rbp), %xmm0
addsd %xmm0, %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x50(%r15,%rcx)
cmpb $0x1, 0x198(%r13)
jne 0x15675
movsd 0x1a0(%r13), %xmm0
movslq %eax, %rcx
imulq $0x70, %rcx, %rcx
movsd %xmm0, 0x58(%r15,%rcx)
cmpb $0x1, 0x1a8(%r13)
jne 0x15696
movsd 0x1b0(%r13), %xmm0
movslq %eax, %rcx
imulq $0x70, %rcx, %rcx
movsd %xmm0, 0x60(%r15,%rcx)
movsd 0x220(%r13), %xmm1
ucomisd 0x1a1c9(%rip), %xmm1    # 0x2f870
jne 0x156ab
jnp 0x156e2
movsd 0x18955(%rip), %xmm0    # 0x2e008
addsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm2
cvtdq2pd %xmm2, %xmm2
subsd %xmm1, %xmm2
andpd 0x18955(%rip), %xmm2    # 0x2e020
movsd 0x1a18d(%rip), %xmm1    # 0x2f860
ucomisd %xmm2, %xmm1
ja 0x156f0
leaq 0x1ca19(%rip), %rsi     # 0x320f9
jmp 0x15700
movslq %eax, %rcx
imulq $0x70, %rcx, %rdx
movl 0x68(%r15,%rdx), %edx
jmp 0x1574e
cvttsd2si %xmm0, %edx
cmpl $0xa, %edx
jl 0x15742
leaq 0x1ca1b(%rip), %rsi     # 0x3211b
movq %r12, %rdi
xorl %eax, %eax
callq 0xb8e0
movq 0x2784f(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1b20a(%rip), %rsi     # 0x30929
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %r12
jmp 0x15869
movslq %eax, %rcx
imulq $0x70, %rcx, %rsi
movl %edx, 0x68(%r15,%rsi)
imulq $0x70, %rcx, %rcx
leaq (%r15,%rcx), %rsi
addq $0x8, %rsi
movl -0x8(%rsi), %r8d
movsd 0x48(%rsi), %xmm0
movsd 0x50(%rsi), %xmm1
movsd 0x58(%rsi), %xmm2
pushq $0x9
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %eax, %edi
movl %r8d, %esi
callq 0xc6f0
movslq 0x5fc(%rbx), %rdx
movslq -0x2c(%rbp), %rax
cmpl %eax, %edx
jne 0x1579f
imulq $0x70, %rdx, %rsi
addq %r15, %rsi
pushq $0xe
popq %rcx
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl 0xd6c8(%rbx), %ecx
xorl %r12d, %r12d
testl %ecx, %ecx
cmovlel %r12d, %ecx
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0xc080(%rbx)
movups 0xd6d0(%rbx), %xmm0
movups %xmm0, 0xc088(%rbx)
movups 0xd6e0(%rbx), %xmm0
movups %xmm0, 0xc098(%rbx)
movups 0xd6f0(%rbx), %xmm0
movups %xmm0, 0xc0a8(%rbx)
movups 0xd700(%rbx), %xmm0
movups %xmm0, 0xc0b8(%rbx)
movups 0xd710(%rbx), %xmm0
movups %xmm0, 0xc0c8(%rbx)
movups 0xd720(%rbx), %xmm0
movups %xmm0, 0xc0d8(%rbx)
cvtsi2sdl 0xd730(%rbx), %xmm0
movsd %xmm0, 0xc0e8(%rbx)
cmpl %r14d, %edx
jne 0x15869
movq 0x27736(%rip), %rcx     # 0x3cf60
cmpl $0x0, 0xc6ac(%rcx)
jne 0x15869
imulq $0x70, %rax, %rax
leaq (%r15,%rax), %rsi
addq $0x8, %rsi
movl -0x8(%rsi), %eax
movsd 0x48(%rsi), %xmm0
movsd 0x50(%rsi), %xmm1
movsd 0x58(%rsi), %xmm2
movl 0x60(%rsi), %edx
pushq $0x9
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
xorl %r12d, %r12d
xorl %edi, %edi
movl %eax, %esi
callq 0xc6f0
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop