// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
addq $0x8, %rdi
callq 0x5940
movq -0x70(%rbp), %rdi
movl %eax, -0x10(%rbp)
addq $0x38, %rdi
callq 0x5940
movl %eax, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $-0x1, -0xc(%rbp)
jne 0x6f3d
movq -0x70(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x18(%rbp)
cmpl $-0x2, -0xc(%rbp)
jne 0x6f4a
movl $0x1, -0x18(%rbp)
movq -0x70(%rbp), %rsi
movl -0x10(%rbp), %eax
movl -0x18(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
addq $0x8, %rsi
leaq -0x38(%rbp), %rdi
callq 0x72a0
movq -0x70(%rbp), %rsi
addq $0x20, %rsi
leaq -0x50(%rbp), %rdi
callq 0x72a0
jmp 0x6f79
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x706b
movl -0x60(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x7001
movslq -0x60(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x5960
movq -0x70(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x78(%rbp)
addq $0x8, %rdi
movl -0x60(%rbp), %eax
addl -0x1c(%rbp), %eax
movslq %eax, %rsi
callq 0x5960
movl -0x78(%rbp), %ecx
movl %ecx, (%rax)
movslq -0x60(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x5960
movq -0x70(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x74(%rbp)
addq $0x20, %rdi
movl -0x60(%rbp), %eax
addl -0x1c(%rbp), %eax
movslq %eax, %rsi
callq 0x5960
movl -0x74(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x705b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x7137
movslq -0x60(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x5960
movq -0x70(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x80(%rbp)
addq $0x8, %rdi
movl -0x60(%rbp), %eax
subl -0x18(%rbp), %eax
movslq %eax, %rsi
callq 0x5960
movl -0x80(%rbp), %ecx
movl %ecx, (%rax)
movslq -0x60(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x5960
movq -0x70(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x7c(%rbp)
addq $0x20, %rdi
movl -0x60(%rbp), %eax
subl -0x18(%rbp), %eax
movslq %eax, %rsi
callq 0x5960
movl -0x7c(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x705d
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x6f80
cmpl $-0x2, -0xc(%rbp)
jne 0x711c
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x711a
movq -0x70(%rbp), %rdi
addq $0x38, %rdi
movslq -0x64(%rbp), %rsi
callq 0x5960
movq -0x70(%rbp), %rdi
movl (%rax), %eax
movl %eax, -0x84(%rbp)
addq $0x20, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x5960
movq %rax, %rcx
movl -0x84(%rbp), %eax
cmpl (%rcx), %eax
jne 0x70e8
movq -0x70(%rbp), %rdi
movl $0x1, %esi
callq 0x7150
jmp 0x70cf
jmp 0x710a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x30b0
jmp 0x7137
movq -0x70(%rbp), %rax
movb 0x58(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
je 0x7108
movq -0x70(%rbp), %rdi
xorl %esi, %esi
callq 0x7150
jmp 0x7106
jmp 0x7108
jmp 0x710a
jmp 0x710c
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x707c
jmp 0x711c
leaq -0x50(%rbp), %rdi
callq 0x30b0
leaq -0x38(%rbp), %rdi
callq 0x30b0
addq $0x90, %rsp
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x30b0
movq -0x58(%rbp), %rdi
callq 0x21f0
nopl (%rax)