// File: /workspace/github_cpp_makefile_star2_O3/yuroitaki[P]enigma_machine/rotor.cpp
// Function: Rotor::shift_ground(int)
void Rotor::shift_ground(int signal){              
  int len = forward_encryption.size();
  int len_n = notch.size();
  int initial_pos = 0;
  
  if(signal== SETUP){           //signal to differentiate btwn the rotation during initial setup or mapping
    initial_pos = ground_position;
  }
  if(signal== RUN){
    initial_pos = 1;       //the position of the element that is going to be shifted to be the '0th' element
  }
  int shift_space = len - initial_pos;
  vector<int> buffer_forward_encryption = forward_encryption;     
  vector<int> buffer_backward_encryption = backward_encryption;
   
  for(int i=0;i<len;i++){                 //shuffle/shift function
    if(i<initial_pos){           
      forward_encryption[i+shift_space]=buffer_forward_encryption[i];
      backward_encryption[i+shift_space]=buffer_backward_encryption[i];
    }
    else{
      forward_encryption[i-initial_pos] = buffer_forward_encryption[i];
      backward_encryption[i-initial_pos] = buffer_backward_encryption[i];
    } 
  }
  if (signal==RUN){               //to check if notch is reached during mapping
    for(int i=0;i<len_n;i++){
      if(notch[i]==backward_encryption[0]){
	set_notch_stat(true);
      }
      else{
	if(notch_reached != true){ //to prevent the overwriting of notch status by subsequent notch position 
	  set_notch_stat(false);
	}
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x8(%rdi), %rsi
movq 0x10(%rdi), %r13
movq 0x40(%rdi), %r12
xorl %eax, %eax
cmpl $-0x1, %ebp
jne 0x41e1
movl 0x50(%rbx), %eax
subq 0x8(%rbx), %r13
subq 0x38(%rbx), %r12
cmpl $-0x2, %ebp
movl $0x1, %r14d
cmovnel %eax, %r14d
leaq 0x8(%rsp), %rdi
movq %rsi, (%rsp)
callq 0x4388
leaq 0x20(%rbx), %r15
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x4388
shrq $0x2, %r13
testl %r13d, %r13d
jle 0x4273
movl %r13d, %r8d
subl %r14d, %r8d
movq 0x8(%rsp), %rax
movq (%rsp), %rcx
movq (%rcx), %rcx
movq 0x20(%rsp), %rdx
movq (%r15), %rsi
movslq %r14d, %rdi
movslq %r8d, %r8
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movq %rdi, %r9
negq %r9
xorl %r10d, %r10d
cmpq %rdi, %r10
movl (%rax,%r10,4), %r11d
movq %r9, %r14
cmovlq %r8, %r14
addq %r10, %r14
movl %r11d, (%rcx,%r14,4)
movl (%rdx,%r10,4), %r11d
movl %r11d, (%rsi,%r14,4)
incq %r10
cmpq %r10, %r13
jne 0x424e
cmpl $-0x2, %ebp
jne 0x42b5
shrq $0x2, %r12
testl %r12d, %r12d
jle 0x42b5
movq 0x20(%rbx), %rcx
movq 0x38(%rbx), %rax
movl (%rcx), %ecx
movb 0x58(%rbx), %sil
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %edx, %edx
movb $0x1, %dil
cmpl %ecx, (%rax,%rdx,4)
je 0x42a7
testb %sil, %sil
jne 0x42ad
xorl %edi, %edi
movb %dil, 0x58(%rbx)
movl %edi, %esi
incq %rdx
cmpq %rdx, %r12
jne 0x4298
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x42cc
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x42e3
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x430c
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21d0