// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0xffffffff, (%rcx)     # imm = 0xFFFFFFFF
movsd 0x210(%rsi), %xmm0
addsd 0x1d9ea(%rip), %xmm0    # 0x32008
cvttsd2si %xmm0, %r14d
movq %rdx, %rsi
movl %r14d, %edx
callq 0xa930
testl %eax, %eax
je 0x1469d
movl %eax, %r12d
movq 0x2c924(%rip), %rbx     # 0x40f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x14d5b
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x202c2(%rip), %rsi     # 0x34929
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%rbx), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0x14d5b
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 0x14740
movsd 0x278(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x146ec
movsd 0x600(%rbx), %xmm0
addsd 0xd678(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2c86d(%rip), %rax     # 0x40f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x14716
movb %cl, %al
leaq 0x1f881(%rip), %rcx     # 0x33f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x1471e
movsd 0x1f7aa(%rip), %xmm0    # 0x33ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x8(%r15,%rcx)
cmpb $0x1, 0x280(%r13)
jne 0x147c9
movsd 0x288(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x14775
movsd 0x608(%rbx), %xmm0
addsd 0xd680(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2c7e4(%rip), %rax     # 0x40f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x1479f
movb %cl, %al
leaq 0x1f7f8(%rip), %rcx     # 0x33f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x147a7
movsd 0x1f721(%rip), %xmm0    # 0x33ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x10(%r15,%rcx)
cmpb $0x1, 0x290(%r13)
jne 0x14852
movsd 0x298(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x147fe
movsd 0x610(%rbx), %xmm0
addsd 0xd688(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2c75b(%rip), %rax     # 0x40f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x14828
movb %cl, %al
leaq 0x1f76f(%rip), %rcx     # 0x33f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x14830
movsd 0x1f698(%rip), %xmm0    # 0x33ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x18(%r15,%rcx)
cmpb $0x1, (%r13)
jne 0x1489f
movsd 0x8(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x14881
movsd 0x8(%rbx), %xmm0
addsd 0xd690(%rbx), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x14886
movsd %xmm1, -0x38(%rbp)
callq 0xaf60
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x20(%r15,%rcx)
cmpb $0x1, 0x10(%r13)
jne 0x148ec
movsd 0x18(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x148ce
movsd 0x20(%rbx), %xmm0
addsd 0xd698(%rbx), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x148d3
movsd %xmm1, -0x38(%rbp)
callq 0xaf60
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x28(%r15,%rcx)
cmpb $0x1, 0x20(%r13)
jne 0x14939
movsd 0x28(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x1491b
movsd 0x38(%rbx), %xmm0
addsd 0xd6a0(%rbx), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x14920
movsd %xmm1, -0x38(%rbp)
callq 0xaf60
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x30(%r15,%rcx)
cmpb $0x1, 0x244(%r13)
jne 0x149bf
movsd 0x248(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x1496b
movsd 0x50(%rbx), %xmm0
addsd 0xd6a8(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2c5ee(%rip), %rax     # 0x40f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x14995
movb %cl, %al
leaq 0x1f602(%rip), %rcx     # 0x33f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x1499d
movsd 0x1f52b(%rip), %xmm0    # 0x33ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x38(%r15,%rcx)
cmpb $0x1, 0x250(%r13)
jne 0x14a45
movsd 0x258(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x149f1
movsd 0x68(%rbx), %xmm0
addsd 0xd6b0(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2c568(%rip), %rax     # 0x40f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x14a1b
movb %cl, %al
leaq 0x1f57c(%rip), %rcx     # 0x33f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x14a23
movsd 0x1f4a5(%rip), %xmm0    # 0x33ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x40(%r15,%rcx)
cmpb $0x1, 0x260(%r13)
jne 0x14ace
movsd 0x268(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x14a7a
movsd 0x80(%rbx), %xmm0
addsd 0xd6b8(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2c4df(%rip), %rax     # 0x40f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x14aa4
movb %cl, %al
leaq 0x1f4f3(%rip), %rcx     # 0x33f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x14aac
movsd 0x1f41c(%rip), %xmm0    # 0x33ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rcx
movsd %xmm0, 0x48(%r15,%rcx)
cmpb $0x1, 0x229(%r13)
jne 0x14b35
movq 0x2c481(%rip), %rax     # 0x40f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x14b02
movb %cl, %al
leaq 0x1f495(%rip), %rcx     # 0x33f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x14b0a
movsd 0x1f3be(%rip), %xmm0    # 0x33ec8
mulsd 0x230(%r13), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0xa990
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 0x14b56
movsd 0x1a0(%r13), %xmm0
movslq %eax, %rcx
imulq $0x70, %rcx, %rcx
movsd %xmm0, 0x58(%r15,%rcx)
cmpb $0x1, 0x1a8(%r13)
jne 0x14b77
movsd 0x1b0(%r13), %xmm0
movslq %eax, %rcx
imulq $0x70, %rcx, %rcx
movsd %xmm0, 0x60(%r15,%rcx)
movsd 0x220(%r13), %xmm1
ucomisd 0x1ece8(%rip), %xmm1    # 0x33870
jne 0x14b8c
jnp 0x14bc3
movsd 0x1d474(%rip), %xmm0    # 0x32008
addsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm2
cvtdq2pd %xmm2, %xmm2
subsd %xmm1, %xmm2
andpd 0x1d474(%rip), %xmm2    # 0x32020
movsd 0x1ecac(%rip), %xmm1    # 0x33860
ucomisd %xmm2, %xmm1
ja 0x14bd1
leaq 0x2152e(%rip), %rsi     # 0x360ef
jmp 0x14be1
movslq %eax, %rcx
imulq $0x70, %rcx, %rdx
movl 0x68(%r15,%rdx), %edx
jmp 0x14c34
cvttsd2si %xmm0, %edx
cmpl $0xa, %edx
jl 0x14c28
leaq 0x21530(%rip), %rsi     # 0x36111
movq %r12, %rdi
xorl %eax, %eax
callq 0xa850
movq 0x2c36e(%rip), %rbx     # 0x40f60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1fd29(%rip), %rsi     # 0x34929
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r12d
jmp 0x14d5b
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
movl $0x9, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %eax, %edi
movl %r8d, %esi
callq 0xb580
movslq 0x5fc(%rbx), %rdx
movslq -0x2c(%rbp), %rax
cmpl %eax, %edx
jne 0x14c89
imulq $0x70, %rdx, %rsi
addq %r15, %rsi
movl $0xe, %ecx
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl 0xd6c8(%rbx), %ecx
xorl %r12d, %r12d
testl %ecx, %ecx
cmovlel %r12d, %ecx
xorps %xmm0, %xmm0
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)
xorps %xmm0, %xmm0
cvtsi2sdl 0xd730(%rbx), %xmm0
movsd %xmm0, 0xc0e8(%rbx)
cmpl %r14d, %edx
jne 0x14d5b
movq 0x2c246(%rip), %rcx     # 0x40f60
cmpl $0x0, 0xc6ac(%rcx)
jne 0x14d5b
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
movl $0x9, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
xorl %r12d, %r12d
xorl %edi, %edi
movl %eax, %esi
callq 0xb580
movl %r12d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop