// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/simulation.c
// Function: Change_kin
void Change_kin(int *first_kin, int *last_kin, struct axe *axes,
		int naxes, int natoms1, struct Reference Ref1)
{
  int refatom[natoms1], i; for(i=0; i<natoms1; i++)refatom[i]=-1;
  for(i=0; i<Ref1.N_ref; i++)refatom[Ref1.atom_num[i]]=i;
  int *first=first_kin, *last=last_kin;
  struct axe *axe=axes;
  //printf("#first_atom first_kin last_atom last_kin\n");
  printf("Changing reference atoms of axes\n");
  for(int a=0; a<naxes; a++){
    *first=axe->first_kin; axe->first_kin=-1;
    for(i=axe->first_atom; i<=axe->last_atom; i++){
      if((axe->first_kin<0)&&(refatom[i]>=0)){
	axe->first_kin=refatom[i]; break;
      }
    }
    *last=axe->last_kin; axe->last_kin=-1;
    for(i=axe->last_atom; i>=axe->first_atom; i--){
      if((axe->last_kin<0)&&(refatom[i]>=0)){
	axe->last_kin=refatom[i]; break;
      }
    }
    if((axe->first_kin<0)||(axe->last_kin<0)||(axe->first_kin>axe->last_kin)){
      printf("ERROR, axe %d out of %d\n", a+1, naxes);
      printf("first_kin= %d last_kin= %d first_atom= %d last_atom= %d\n",
	     axe->first_kin, axe->last_kin, axe->first_atom, axe->last_atom);
      printf("Last atom of axe: %s %d %c\n",
	     axe->bond->atom->name, axe->bond->atom->res, axe->bond->atom->aa);
      exit(8);
    }
    axe++; first++; last++;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r14d
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
leaq 0x10(%rbp), %rax
movl %r8d, %ecx
movq %rsp, %r13
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
subq %rcx, %r13
movq %r13, %rsp
xorl %ecx, %ecx
testl %r8d, %r8d
cmovlel %ecx, %r8d
cmpq %rcx, %r8
je 0x340b1
orl $-0x1, (%r13,%rcx,4)
incq %rcx
jmp 0x340a1
movl (%rax), %ecx
movq 0x28(%rax), %rax
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
cmpq %rdx, %rcx
je 0x340d1
movslq (%rax,%rdx,4), %rsi
movl %edx, (%r13,%rsi,4)
incq %rdx
jmp 0x340be
leaq 0x21be1(%rip), %rdi     # 0x55cb9
callq 0x2090
xorl %esi, %esi
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
pushq $-0x1
popq %rcx
cmpl %eax, %esi
je 0x34163
movl 0x18(%rbx), %edx
movl %edx, (%r12)
orl $-0x1, 0x18(%rbx)
movslq 0x10(%rbx), %rdx
movslq 0x14(%rbx), %rdi
cmpq %rdi, %rdx
jg 0x3411b
movl (%r13,%rdx,4), %r8d
incq %rdx
testl %r8d, %r8d
js 0x34105
movl %r8d, 0x18(%rbx)
movl 0x1c(%rbx), %edx
movl %edx, (%r15)
orl $-0x1, 0x1c(%rbx)
movslq 0x14(%rbx), %rdi
movslq 0x10(%rbx), %r8
cmpq %r8, %rdi
jl 0x34143
movl (%r13,%rdi,4), %edx
decq %rdi
testl %edx, %edx
js 0x3412d
movl %edx, 0x1c(%rbx)
jmp 0x34145
movl %ecx, %edx
movl 0x18(%rbx), %edi
testl %edi, %edi
js 0x34172
cmpl %edx, %edi
jg 0x34172
addq $0x158, %rbx            # imm = 0x158
addq $0x4, %r12
addq $0x4, %r15
incl %esi
jmp 0x340ee
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl %esi
leaq 0x214b0(%rip), %rdi     # 0x5562b
movl %r14d, %edx
xorl %eax, %eax
callq 0x20f0
movl 0x18(%rbx), %esi
movl 0x1c(%rbx), %edx
movl 0x10(%rbx), %ecx
movl 0x14(%rbx), %r8d
leaq 0x214ab(%rip), %rdi     # 0x55644
xorl %eax, %eax
callq 0x20f0
movq 0x8(%rbx), %rax
movq (%rax), %rax
leaq 0x18(%rax), %rsi
movl 0x64(%rax), %edx
movsbl 0x68(%rax), %ecx
leaq 0x214c4(%rip), %rdi     # 0x5567d
xorl %eax, %eax
callq 0x20f0
pushq $0x8
popq %rdi
callq 0x2270