// File: /workspace/github_cpp_makefile_star2_O1/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 0x42b1
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 0x446a
leaq 0x20(%rbx), %r15
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x446a
shrq $0x2, %r13
testl %r13d, %r13d
jle 0x4343
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 0x431e
cmpl $-0x2, %ebp
jne 0x4386
shrq $0x2, %r12
testl %r12d, %r12d
jle 0x4386
movq 0x20(%rbx), %rcx
movq 0x38(%rbx), %rax
movl (%rcx), %ecx
movb 0x58(%rbx), %dl
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %esi, %esi
cmpl %ecx, (%rax,%rsi,4)
jne 0x4374
movb $0x1, 0x58(%rbx)
movb $0x1, %dl
jmp 0x437e
testb %dl, %dl
jne 0x437e
movb $0x0, 0x58(%rbx)
xorl %edx, %edx
incq %rsi
cmpq %rsi, %r12
jne 0x4367
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x439d
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x43b4
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 0x43dd
movq 0x18(%rsp), %rsi
subq %rdi, %rsi
callq 0x2120
movq %rbx, %rdi
callq 0x21d0
nop