// File: /workspace/github_c_makefile_star2_O0/jeff-1amstudios[P]carmageddon-1-cheat-code-disassembly/src/utility.c
// Function: DecodeLine2
void DecodeLine2(char *pS)
{
  int len;
  int seed;
  int i;
  int count;
  unsigned char c;
  char *key;

  len = strlen(pS);
  count = 0;
  key = gLong_key;
  while ( len > 0 && (pS[len - 1] == 13 || pS[len - 1] == 10))
  {
    --len;
    pS[len] = 0;
  }
  seed = len % 16;
  for ( i = 0; i < len; i++)
  {
    c = pS[i];
    if (i >= 2) {
      if (pS[i - 1] == '/' && pS[i - 2] == '/') {
        key = gOther_long_key;
      }
    }
    if (gEncryption_method == 1) 
    { 
      if ( c == '\t' ) {
        c = 0x80;
      }
      c -= 0x20;
      if (!(c & 0x80)) {
        c = (c ^ key[seed]) & 0x7f;
        c += 0x20;
      }
      seed += 7;
      seed = seed % 16;
      
      if ( c == 0x80 ) {
        c = '\t';
      }
    }
    else {
      if (c == '\t') {
        c = 0x9f;
      }
      c -= 0x20;
      c = (c ^ key[seed]) & 0x7f;
      c += 0x20;

      seed += 7;
      seed = seed % 16;
      
      if ( c == 0x9f ) {
        c = '\t';
      }
    }
    pS[i] = c;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x20d0
movl %eax, -0xc(%rbp)
movl $0x0, -0x18(%rbp)
leaq 0xa8fa(%rip), %rax      # 0xdae0
movq %rax, -0x28(%rbp)
xorl %eax, %eax
cmpl $0x0, -0xc(%rbp)
movb %al, -0x29(%rbp)
jle 0x3230
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %ecx
movb $0x1, %al
cmpl $0xd, %ecx
movb %al, -0x2a(%rbp)
je 0x322a
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
sete %al
movb %al, -0x2a(%rbp)
movb -0x2a(%rbp), %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
testb $0x1, %al
jne 0x3239
jmp 0x3250
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x31ea
movl -0xc(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x33b3
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x19(%rbp)
cmpl $0x2, -0x14(%rbp)
jl 0x32be
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x32bc
movq -0x8(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x32bc
leaq 0xa838(%rip), %rax      # 0xdaf0
movq %rax, -0x28(%rbp)
jmp 0x32be
cmpl $0x1, 0xa80b(%rip)      # 0xdad0
jne 0x3336
movzbl -0x19(%rbp), %eax
cmpl $0x9, %eax
jne 0x32d4
movb $-0x80, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
subl $0x20, %eax
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x330e
movzbl -0x19(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq -0x10(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
andl $0x7f, %eax
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
addl $0x20, %eax
movb %al, -0x19(%rbp)
movl -0x10(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x10(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x80, %eax
jne 0x3334
movb $0x9, -0x19(%rbp)
jmp 0x3397
movzbl -0x19(%rbp), %eax
cmpl $0x9, %eax
jne 0x3343
movb $-0x61, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
subl $0x20, %eax
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
movq -0x28(%rbp), %rcx
movslq -0x10(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
andl $0x7f, %eax
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
addl $0x20, %eax
movb %al, -0x19(%rbp)
movl -0x10(%rbp), %eax
addl $0x7, %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x10(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x9f, %eax
jne 0x3395
movb $0x9, -0x19(%rbp)
jmp 0x3397
movb -0x19(%rbp), %dl
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x3265
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)