// File: /workspace/github_c_makefile_star2_O3/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), %rcx
movl %r8d, %edx
movq %rsp, %r13
leaq 0xf(,%rdx,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
testl %r8d, %r8d
jle 0x387fc
shlq $0x2, %rdx
movq %r13, %rdi
movl $0xff, %esi
callq 0x2110
leaq 0x10(%rbp), %rcx
movslq (%rcx), %rax
testq %rax, %rax
jle 0x3881b
movq 0x28(%rcx), %rcx
xorl %edx, %edx
movslq (%rcx,%rdx,4), %rsi
movl %edx, (%r13,%rsi,4)
incq %rdx
cmpq %rdx, %rax
jne 0x3880a
leaq 0x23537(%rip), %rdi     # 0x5bd59
callq 0x2090
testl %r14d, %r14d
jle 0x388cb
xorl %esi, %esi
movl 0x18(%rbx), %eax
movl %eax, (%r12)
movl $0xffffffff, 0x18(%rbx) # imm = 0xFFFFFFFF
movslq 0x10(%rbx), %rdx
movl 0x14(%rbx), %eax
cmpl %eax, %edx
jg 0x3886f
leaq (,%rdx,4), %rcx
addq %r13, %rcx
subl %edx, %eax
incl %eax
xorl %edx, %edx
movl (%rcx,%rdx,4), %edi
testl %edi, %edi
jns 0x3886c
incq %rdx
cmpl %edx, %eax
jne 0x3885c
jmp 0x3886f
movl %edi, 0x18(%rbx)
movl 0x1c(%rbx), %eax
movl %eax, (%r15)
movl $0xffffffff, 0x1c(%rbx) # imm = 0xFFFFFFFF
movslq 0x14(%rbx), %rax
movslq 0x10(%rbx), %rcx
cmpl %ecx, %eax
jl 0x3889c
incq %rax
movl -0x4(%r13,%rax,4), %edx
testl %edx, %edx
jns 0x388a3
decq %rax
cmpq %rcx, %rax
jg 0x3888b
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x388a6
movl %edx, 0x1c(%rbx)
movl 0x18(%rbx), %eax
testl %eax, %eax
js 0x388da
cmpl %edx, %eax
jg 0x388da
addq $0x158, %rbx            # imm = 0x158
addq $0x4, %r12
addq $0x4, %r15
incl %esi
cmpl %r14d, %esi
jne 0x38832
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl %esi
leaq 0x22de8(%rip), %rdi     # 0x5b6cb
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 0x22de3(%rip), %rdi     # 0x5b6e4
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 0x22dfc(%rip), %rdi     # 0x5b71d
xorl %eax, %eax
callq 0x20f0
movl $0x8, %edi
callq 0x2280