// File: /workspace/github_cpp_makefile_star2_O1/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 0x1fec6(%rip), %xmm0    # 0x35008
cvttsd2si %xmm0, %r14d
movq %rdx, %rsi
movl %r14d, %edx
callq 0xa930
testl %eax, %eax
je 0x151c1
movl %eax, %r12d
movq 0x2ee00(%rip), %rbx     # 0x43f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x15888
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x2279e(%rip), %rsi     # 0x37929
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 0x15888
movq %r15, %r12
leaq 0xd6c8(%rbx), %r15
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movl %r14d, 0xd6c8(%rbx,%rax)
cmpb $0x1, 0x270(%r13)
jne 0x15264
movsd 0x278(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x15210
movsd 0x600(%rbx), %xmm0
addsd 0xd678(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2ed49(%rip), %rax     # 0x43f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x1523a
movb %cl, %al
leaq 0x21d5d(%rip), %rcx     # 0x36f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x15242
movsd 0x21c86(%rip), %xmm0    # 0x36ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x8(%r15,%rax)
cmpb $0x1, 0x280(%r13)
jne 0x152ed
movsd 0x288(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x15299
movsd 0x608(%rbx), %xmm0
addsd 0xd680(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2ecc0(%rip), %rax     # 0x43f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x152c3
movb %cl, %al
leaq 0x21cd4(%rip), %rcx     # 0x36f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x152cb
movsd 0x21bfd(%rip), %xmm0    # 0x36ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x10(%r15,%rax)
cmpb $0x1, 0x290(%r13)
jne 0x15376
movsd 0x298(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x15322
movsd 0x610(%rbx), %xmm0
addsd 0xd688(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2ec37(%rip), %rax     # 0x43f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x1534c
movb %cl, %al
leaq 0x21c4b(%rip), %rcx     # 0x36f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x15354
movsd 0x21b74(%rip), %xmm0    # 0x36ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x18(%r15,%rax)
cmpb $0x1, (%r13)
jne 0x153c3
movsd 0x8(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x153a5
movsd 0x8(%rbx), %xmm0
addsd 0xd690(%rbx), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x153aa
movsd %xmm1, -0x38(%rbp)
callq 0xaf60
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x20(%r15,%rax)
cmpb $0x1, 0x10(%r13)
jne 0x15410
movsd 0x18(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x153f2
movsd 0x20(%rbx), %xmm0
addsd 0xd698(%rbx), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x153f7
movsd %xmm1, -0x38(%rbp)
callq 0xaf60
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x28(%r15,%rax)
cmpb $0x1, 0x20(%r13)
jne 0x1545d
movsd 0x28(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x1543f
movsd 0x38(%rbx), %xmm0
addsd 0xd6a0(%rbx), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x15444
movsd %xmm1, -0x38(%rbp)
callq 0xaf60
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x30(%r15,%rax)
cmpb $0x1, 0x244(%r13)
jne 0x154e3
movsd 0x248(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x1548f
movsd 0x50(%rbx), %xmm0
addsd 0xd6a8(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2eaca(%rip), %rax     # 0x43f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x154b9
movb %cl, %al
leaq 0x21ade(%rip), %rcx     # 0x36f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x154c1
movsd 0x21a07(%rip), %xmm0    # 0x36ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x38(%r15,%rax)
cmpb $0x1, 0x250(%r13)
jne 0x15569
movsd 0x258(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x15515
movsd 0x68(%rbx), %xmm0
addsd 0xd6b0(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2ea44(%rip), %rax     # 0x43f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x1553f
movb %cl, %al
leaq 0x21a58(%rip), %rcx     # 0x36f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x15547
movsd 0x21981(%rip), %xmm0    # 0x36ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x40(%r15,%rax)
cmpb $0x1, 0x260(%r13)
jne 0x155f2
movsd 0x268(%r13), %xmm1
cmpl $0xa, 0x1c8(%r13)
jne 0x1559e
movsd 0x80(%rbx), %xmm0
addsd 0xd6b8(%rbx), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
movq 0x2e9bb(%rip), %rax     # 0x43f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x155c8
movb %cl, %al
leaq 0x219cf(%rip), %rcx     # 0x36f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x155d0
movsd 0x218f8(%rip), %xmm0    # 0x36ec8
mulsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x48(%r15,%rax)
cmpb $0x1, 0x229(%r13)
jne 0x15659
movq 0x2e95d(%rip), %rax     # 0x43f60
movl 0x1690(%rax), %edx
xorl %eax, %eax
cmpl $0x3, %edx
sete %cl
cmpl $0x1, %edx
je 0x15626
movb %cl, %al
leaq 0x21971(%rip), %rcx     # 0x36f90
movsd (%rcx,%rax,8), %xmm0
jmp 0x1562e
movsd 0x2189a(%rip), %xmm0    # 0x36ec8
mulsd 0x230(%r13), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0xa990
mulsd -0x38(%rbp), %xmm0
addsd %xmm0, %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x50(%r15,%rax)
cmpb $0x1, 0x198(%r13)
jne 0x1567b
movsd 0x1a0(%r13), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x58(%r15,%rax)
cmpb $0x1, 0x1a8(%r13)
jne 0x1569d
movsd 0x1b0(%r13), %xmm0
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %rax
movsd %xmm0, 0x60(%r15,%rax)
movsd 0x220(%r13), %xmm1
ucomisd 0x211c2(%rip), %xmm1    # 0x36870
jne 0x156b6
jnp 0x1575b
movsd 0x1f94a(%rip), %xmm0    # 0x35008
addsd %xmm1, %xmm0
cvttpd2dq %xmm0, %xmm2
cvtdq2pd %xmm2, %xmm2
subsd %xmm1, %xmm2
andpd 0x1f94a(%rip), %xmm2    # 0x35020
movsd 0x21182(%rip), %xmm1    # 0x36860
ucomisd %xmm2, %xmm1
ja 0x156ed
leaq 0x23a04(%rip), %rsi     # 0x390ef
jmp 0x156fd
cvttsd2si %xmm0, %eax
cmpl $0xa, %eax
jl 0x1574e
leaq 0x23a14(%rip), %rsi     # 0x39111
movq %r12, %rdi
xorl %eax, %eax
callq 0xa850
movq 0x2e852(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x22203(%rip), %rsi     # 0x37929
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r12d
jmp 0x15888
movslq -0x2c(%rbp), %rcx
imulq $0x70, %rcx, %rcx
movl %eax, 0x68(%r15,%rcx)
movslq -0x2c(%rbp), %rax
imulq $0x70, %rax, %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 0x60(%rsi), %edx
movl $0x9, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %eax, %edi
movl %r8d, %esi
callq 0xb580
movl 0x5fc(%rbx), %edx
movslq -0x2c(%rbp), %rax
cmpl %eax, %edx
jne 0x157b6
imulq $0x70, %rax, %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 0x15888
movq 0x2e719(%rip), %rcx     # 0x43f60
cmpl $0x0, 0xc6ac(%rcx)
jne 0x15888
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