#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ Rotate_Left(char *, int);
int /*<<< orphan*/ Rotate_Right(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, ...);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  FILE *inFile;
  char line[40];
  char *password;
  char letter1, letter2, temp;
  int index1, index2, i, p, pwLen;
  if (argc != 3) {
    fprintf(stderr, "Usage:\n\tDay21 <input filename> <password>\n\n");
    return EXIT_FAILURE;
  }
  inFile = fopen(argv[1], "r");
  if (inFile == NULL) {
    fprintf(stderr, "Error opening file: %s\n\n", strerror(errno));
    return EXIT_FAILURE;
  }
  password = argv[2];
  pwLen = strlen(password);
  while (fgets(line, 40, inFile) != NULL) {
    if (strncmp(line, "swap", sizeof("swap") - 1) == 0) {
      if (strncmp(line + 5, "position", sizeof("position") - 1) == 0) {
        sscanf(line, "swap position %d with position %d", &index1, &index2);
        temp = password[index1];
        password[index1] = password[index2];
        password[index2] = temp;
      } else {
        sscanf(line, "swap letter %c with letter %c", &letter1, &letter2);
        for (i = 0; i < pwLen; i++) {
          if (password[i] == letter1)
            password[i] = letter2;
          else if (password[i] == letter2)
            password[i] = letter1;
        }
      }
    } else if (strncmp(line, "rotate", sizeof("rotate") - 1) == 0) {
      if (strncmp(line + 7, "based", sizeof("based") - 1) == 0) {
        sscanf(line, "rotate based on position of letter %c", &letter1);
        index1 = strchr(password, letter1) - password;
        if (index1 >= 4)
          index1 += 2;
        else
          index1 += 1;
        for (p = 0; p < index1; p++) {
          Rotate_Right(password, pwLen);
        }
      } else {
        if (strncmp(line + 7, "left", sizeof("left") - 1) == 0) {
          sscanf(line, "rotate left %d", &index1);
          for (p = 0; p < index1; p++) {
            Rotate_Left(password, pwLen);
          }
        } else {
          sscanf(line, "rotate right %d", &index1);
          for (p = 0; p < index1; p++) {
            Rotate_Right(password, pwLen);
          }
        }
      }
    } else if (strncmp(line, "reverse", sizeof("reverse") - 1) == 0) {
      sscanf(line, "reverse positions %d through %d", &index1, &index2);
      p = index2 - index1;
      for (i = 0; i <= p / 2; i++) {
        temp = password[index1 + i];
        password[index1 + i] = password[index2 - i];
        password[index2 - i] = temp;
      }
    } else if (strncmp(line, "move", sizeof("move") - 1) == 0) {
      sscanf(line, "move position %d to position %d", &index1, &index2);
      if (index1 > index2) {
        Rotate_Right(password + index2, index1 - index2 + 1);
      } else {
        Rotate_Left(password + index1, index2 - index1 + 1);
      }
    } else {
      fprintf(stderr, "Invalid instruction: %s\n", line);
      fclose(inFile);
      return EXIT_FAILURE;
    }
  }
  fclose(inFile);
  printf("Scrambled password: %s\n", password);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1208 <main+0x48>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    16ff <main+0x53f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe15(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    126a <main+0xaa>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    16ff <main+0x53f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x60(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x28,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     16da <main+0x51a>
lea    -0x40(%rbp),%rdi
lea    0xd9e(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    13d1 <main+0x211>
lea    -0x40(%rbp),%rdi
add    $0x5,%rdi
lea    0xd80(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1331 <main+0x171>
lea    -0x40(%rbp),%rdi
lea    0xd6a(%rip),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x54(%rbp),%rcx
mov    $0x0,%al
call   10a0 <sscanf@plt>
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x4b(%rbp)
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x48(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4b(%rbp),%dl
mov    -0x48(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    13cc <main+0x20c>
lea    -0x40(%rbp),%rdi
lea    0xd3b(%rip),%rsi
lea    -0x49(%rbp),%rdx
lea    -0x4a(%rbp),%rcx
mov    $0x0,%al
call   10a0 <sscanf@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x60(%rbp),%eax
jge    13c7 <main+0x207>
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x49(%rbp),%ecx
cmp    %ecx,%eax
jne    1389 <main+0x1c9>
mov    -0x4a(%rbp),%dl
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    13b4 <main+0x1f4>
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x4a(%rbp),%ecx
cmp    %ecx,%eax
jne    13af <main+0x1ef>
mov    -0x49(%rbp),%dl
mov    -0x48(%rbp),%rax
movslq -0x58(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    13b4 <main+0x1f4>
jmp    13b9 <main+0x1f9>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1352 <main+0x192>
jmp    13cc <main+0x20c>
jmp    16d5 <main+0x515>
lea    -0x40(%rbp),%rdi
lea    0xcb9(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1550 <main+0x390>
lea    -0x40(%rbp),%rdi
add    $0x7,%rdi
lea    0xc9d(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1493 <main+0x2d3>
lea    -0x40(%rbp),%rdi
lea    0xc84(%rip),%rsi
lea    -0x49(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
mov    -0x48(%rbp),%rdi
movsbl -0x49(%rbp),%esi
call   1060 <strchr@plt>
mov    -0x48(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x50(%rbp)
cmpl   $0x4,-0x50(%rbp)
jl     1458 <main+0x298>
mov    -0x50(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x50(%rbp)
jmp    1461 <main+0x2a1>
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    148e <main+0x2ce>
mov    -0x48(%rbp),%rdi
mov    -0x60(%rbp),%esi
call   10c0 <Rotate_Right@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1468 <main+0x2a8>
jmp    154b <main+0x38b>
lea    -0x40(%rbp),%rdi
add    $0x7,%rdi
lea    0xc26(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    14fe <main+0x33e>
lea    -0x40(%rbp),%rdi
lea    0xc0c(%rip),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    14f9 <main+0x339>
mov    -0x48(%rbp),%rdi
mov    -0x60(%rbp),%esi
call   10b0 <Rotate_Left@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    14d3 <main+0x313>
jmp    1546 <main+0x386>
lea    -0x40(%rbp),%rdi
lea    0xbd3(%rip),%rsi
lea    -0x50(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    1541 <main+0x381>
mov    -0x48(%rbp),%rdi
mov    -0x60(%rbp),%esi
call   10c0 <Rotate_Right@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    151b <main+0x35b>
jmp    1546 <main+0x386>
jmp    154b <main+0x38b>
jmp    16d0 <main+0x510>
lea    -0x40(%rbp),%rdi
lea    0xb91(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1610 <main+0x450>
lea    -0x40(%rbp),%rdi
lea    0xb7a(%rip),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x54(%rbp),%rcx
mov    $0x0,%al
call   10a0 <sscanf@plt>
mov    -0x54(%rbp),%eax
sub    -0x50(%rbp),%eax
mov    %eax,-0x5c(%rbp)
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x5c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
cmp    %ecx,%eax
jg     160b <main+0x44b>
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%ecx
add    -0x58(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x4b(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    -0x58(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x48(%rbp),%rax
mov    -0x50(%rbp),%ecx
add    -0x58(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4b(%rbp),%dl
mov    -0x48(%rbp),%rax
mov    -0x54(%rbp),%ecx
sub    -0x58(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    1599 <main+0x3d9>
jmp    16cb <main+0x50b>
lea    -0x40(%rbp),%rdi
lea    0xaf9(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1691 <main+0x4d1>
lea    -0x40(%rbp),%rdi
lea    0xadf(%rip),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x54(%rbp),%rcx
mov    $0x0,%al
call   10a0 <sscanf@plt>
mov    -0x50(%rbp),%eax
cmp    -0x54(%rbp),%eax
jle    1673 <main+0x4b3>
mov    -0x48(%rbp),%rdi
movslq -0x54(%rbp),%rax
add    %rax,%rdi
mov    -0x50(%rbp),%esi
sub    -0x54(%rbp),%esi
add    $0x1,%esi
call   10c0 <Rotate_Right@plt>
jmp    168c <main+0x4cc>
mov    -0x48(%rbp),%rdi
movslq -0x50(%rbp),%rax
add    %rax,%rdi
mov    -0x54(%rbp),%esi
sub    -0x50(%rbp),%esi
add    $0x1,%esi
call   10b0 <Rotate_Left@plt>
jmp    16c6 <main+0x506>
mov    0x2948(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rdx
lea    0xa94(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2914(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    16ff <main+0x53f>
jmp    16cb <main+0x50b>
jmp    16d0 <main+0x510>
jmp    16d5 <main+0x515>
jmp    1282 <main+0xc2>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x48(%rbp),%rsi
lea    0xa64(%rip),%rdi
call   1070 <printf@plt>
mov    0x28ce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
cmp    $0x3,%edi
jne    17b2 <main+0x5f2>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe47(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     17ed <main+0x62d>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
mov    %rdi,0x18(%rsp)
call   1050 <strlen@plt>
mov    %eax,%r12d
lea    0x40(%rsp),%rdi
mov    $0x28,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     17cb <main+0x60b>
mov    %r12d,%edi
mov    0x18(%rsp),%rbp
lea    (%rdi,%rbp,1),%rax
lea    0xb(%rsp),%rcx
lea    0xc(%rsp),%rsi
cmp    %rcx,%rbp
setb   %cl
lea    0xa(%rsp),%rdx
cmp    %rax,%rdx
setb   %dl
and    %cl,%dl
cmp    %rsi,%rbp
setb   %cl
lea    0xb(%rsp),%rsi
cmp    %rax,%rsi
setb   %al
and    %cl,%al
or     %dl,%al
mov    %al,0x17(%rsp)
mov    %edi,%r15d
and    $0xfffffff8,%r15d
mov    %rdi,0x20(%rsp)
neg    %rdi
mov    %rdi,0x30(%rsp)
lea    0x1(%rbp),%r14
lea    -0x1(%rbp),%rax
mov    %rax,0x28(%rsp)
lea    0x40(%rsp),%rbp
mov    %rbx,0x38(%rsp)
jmp    12f3 <main+0x133>
lea    0xdbd(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   10a0 <sscanf@plt>
movslq 0xc(%rsp),%rax
mov    0x18(%rsp),%rsi
mov    (%rsi,%rax,1),%cl
movslq 0x10(%rsp),%rdx
mov    (%rsi,%rdx,1),%dl
mov    %dl,(%rsi,%rax,1)
movslq 0x10(%rsp),%rax
mov    %cl,(%rsi,%rax,1)
nopl   0x0(%rax)
lea    0x40(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x28,%esi
mov    0x38(%rsp),%rbx
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     17cb <main+0x60b>
mov    %rbp,%rdi
lea    0xd4a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     13b0 <main+0x1f0>
mov    %rbp,%rdi
lea    0xd7b(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1410 <main+0x250>
mov    %rbp,%rdi
lea    0xdb5(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1499 <main+0x2d9>
mov    %rbp,%rdi
lea    0xdc0(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    182f <main+0x66f>
mov    %rbp,%rdi
lea    0xda8(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   10a0 <sscanf@plt>
movslq 0xc(%rsp),%rsi
movslq 0x10(%rsp),%rax
cmp    %eax,%esi
jle    1531 <main+0x371>
mov    %rax,%rdi
add    0x18(%rsp),%rdi
sub    %eax,%esi
add    $0x1,%esi
call   10c0 <Rotate_Right@plt>
jmp    12d0 <main+0x110>
nopl   0x0(%rax,%rax,1)
lea    0x45(%rsp),%rdi
lea    0xc90(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
mov    %rbp,%rdi
test   %rax,%rax
je     1291 <main+0xd1>
lea    0xc9e(%rip),%rsi
lea    0xa(%rsp),%rdx
lea    0xb(%rsp),%rcx
xor    %eax,%eax
call   10a0 <sscanf@plt>
test   %r12d,%r12d
mov    0x18(%rsp),%rsi
jle    12d0 <main+0x110>
cmp    $0x8,%r12d
setb   %al
or     0x17(%rsp),%al
je     15ab <main+0x3eb>
xor    %ecx,%ecx
jmp    16d0 <main+0x510>
lea    0x47(%rsp),%rbx
mov    %rbx,%rdi
lea    0xc7d(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     154a <main+0x38a>
mov    %rbx,%rdi
lea    0xc8c(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    %rbp,%rdi
test   %rax,%rax
je     16ed <main+0x52d>
lea    0xc83(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
cmpl   $0x0,0xc(%rsp)
mov    0x18(%rsp),%rbp
jle    12d0 <main+0x110>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r12d,%esi
call   10c0 <Rotate_Right@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jl     1480 <main+0x2c0>
jmp    12d0 <main+0x110>
mov    %rbp,%rdi
lea    0xc51(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
xor    %eax,%eax
call   10a0 <sscanf@plt>
movslq 0x10(%rsp),%rax
movslq 0xc(%rsp),%rdx
mov    %eax,%ecx
sub    %edx,%ecx
cmp    $0xffffffff,%ecx
mov    0x18(%rsp),%rsi
jl     12d0 <main+0x110>
mov    (%rsi,%rdx,1),%bl
mov    (%rsi,%rax,1),%al
mov    %al,(%rsi,%rdx,1)
movslq 0x10(%rsp),%rax
mov    %bl,(%rsi,%rax,1)
lea    0x1(%rcx),%eax
cmp    $0x3,%eax
jb     12d0 <main+0x110>
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
sar    %eax
mov    0x28(%rsp),%rcx
mov    %r14,%rdx
xchg   %ax,%ax
movslq 0xc(%rsp),%rsi
movslq 0x10(%rsp),%rdi
movzbl (%rdx,%rsi,1),%r8d
movzbl (%rcx,%rdi,1),%ebx
mov    %bl,(%rdx,%rsi,1)
movslq 0x10(%rsp),%rsi
mov    %r8b,(%rcx,%rsi,1)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rcx
add    $0xffffffff,%eax
jne    1500 <main+0x340>
jmp    12d0 <main+0x110>
mov    %rsi,%rdi
add    0x18(%rsp),%rdi
sub    %esi,%eax
add    $0x1,%eax
mov    %eax,%esi
call   10b0 <Rotate_Left@plt>
jmp    12d0 <main+0x110>
mov    %rbp,%rdi
lea    0xb4e(%rip),%rsi
lea    0xa(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
movsbl 0xa(%rsp),%esi
mov    0x18(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strchr@plt>
sub    %ebx,%eax
xor    %ecx,%ecx
cmp    $0x4,%eax
setge  %cl
add    %ecx,%eax
add    $0x1,%eax
mov    %eax,0xc(%rsp)
test   %eax,%eax
jle    12d0 <main+0x110>
xor    %r13d,%r13d
mov    %rbx,%rdi
mov    %r12d,%esi
call   10c0 <Rotate_Right@plt>
add    $0x1,%r13d
cmp    0xc(%rsp),%r13d
jl     1590 <main+0x3d0>
jmp    12d0 <main+0x110>
movzbl 0xa(%rsp),%eax
movd   %eax,%xmm0
punpcklbw %xmm0,%xmm0
pshuflw $0x0,%xmm0,%xmm0
movzbl 0xb(%rsp),%eax
movd   %eax,%xmm1
punpcklbw %xmm1,%xmm1
pshuflw $0x0,%xmm1,%xmm1
xor    %eax,%eax
jmp    15ed <main+0x42d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x8,%rax
cmp    %rax,%r15
je     16c2 <main+0x502>
movq   (%rsi,%rax,1),%xmm4
movdqa %xmm4,%xmm2
pcmpeqb %xmm0,%xmm2
punpcklbw %xmm2,%xmm5
pcmpeqb %xmm1,%xmm4
punpcklbw %xmm4,%xmm3
por    %xmm5,%xmm3
pandn  %xmm4,%xmm2
movdqa %xmm0,%xmm4
pand   %xmm2,%xmm4
pandn  %xmm1,%xmm2
por    %xmm4,%xmm2
psraw  $0x8,%xmm3
movd   %xmm3,%ecx
test   $0x1,%cl
je     1633 <main+0x473>
movd   %xmm2,%edx
mov    %dl,(%rsi,%rax,1)
shr    $0x10,%ecx
test   $0x1,%cl
je     1643 <main+0x483>
movd   %xmm2,%ecx
mov    %ch,0x1(%rsi,%rax,1)
pextrw $0x2,%xmm3,%ecx
test   $0x1,%cl
je     1658 <main+0x498>
movd   %xmm2,%ecx
shr    $0x10,%ecx
mov    %cl,0x2(%rsi,%rax,1)
pextrw $0x3,%xmm3,%ecx
test   $0x1,%cl
je     166d <main+0x4ad>
movd   %xmm2,%ecx
shr    $0x18,%ecx
mov    %cl,0x3(%rsi,%rax,1)
pextrw $0x4,%xmm3,%ecx
test   $0x1,%cl
je     1680 <main+0x4c0>
pextrw $0x2,%xmm2,%ecx
mov    %cl,0x4(%rsi,%rax,1)
pextrw $0x5,%xmm3,%ecx
test   $0x1,%cl
je     1693 <main+0x4d3>
pextrw $0x2,%xmm2,%ecx
mov    %ch,0x5(%rsi,%rax,1)
pextrw $0x6,%xmm3,%ecx
test   $0x1,%cl
je     16a6 <main+0x4e6>
pextrw $0x3,%xmm2,%ecx
mov    %cl,0x6(%rsi,%rax,1)
pextrw $0x7,%xmm3,%ecx
test   $0x1,%cl
je     15e0 <main+0x420>
pextrw $0x3,%xmm2,%ecx
mov    %ch,0x7(%rsi,%rax,1)
jmp    15e0 <main+0x420>
mov    %r15,%rcx
cmp    0x20(%rsp),%r15
je     12d0 <main+0x110>
mov    %rcx,%rax
testb  $0x1,0x20(%rsp)
je     1747 <main+0x587>
mov    (%rsi,%rcx,1),%dl
mov    0xa(%rsp),%al
mov    0xb(%rsp),%bl
cmp    %al,%dl
jne    1739 <main+0x579>
mov    %ebx,%eax
jmp    173d <main+0x57d>
lea    0x9d9(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
cmpl   $0x0,0xc(%rsp)
mov    0x18(%rsp),%rbp
jle    12d0 <main+0x110>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r12d,%esi
call   10b0 <Rotate_Left@plt>
add    $0x1,%ebx
cmp    0xc(%rsp),%ebx
jl     1720 <main+0x560>
jmp    12d0 <main+0x110>
cmp    %bl,%dl
jne    1740 <main+0x580>
mov    %al,(%rsi,%rcx,1)
mov    %rcx,%rax
or     $0x1,%rax
not    %rcx
cmp    0x30(%rsp),%rcx
jne    1775 <main+0x5b5>
jmp    12d0 <main+0x110>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%ecx
mov    %cl,(%r14,%rax,1)
add    $0x2,%rax
cmp    %rax,0x20(%rsp)
je     12d0 <main+0x110>
movzbl -0x1(%r14,%rax,1),%edx
movzbl 0xa(%rsp),%ecx
movzbl 0xb(%rsp),%ebx
cmp    %cl,%dl
jne    1790 <main+0x5d0>
mov    %ebx,%ecx
jmp    1794 <main+0x5d4>
nopl   (%rax)
cmp    %bl,%dl
jne    1799 <main+0x5d9>
mov    %cl,-0x1(%r14,%rax,1)
movzbl (%r14,%rax,1),%edx
movzbl 0xa(%rsp),%ecx
movzbl 0xb(%rsp),%ebx
cmp    %cl,%dl
je     1760 <main+0x5a0>
cmp    %bl,%dl
je     1762 <main+0x5a2>
jmp    1766 <main+0x5a6>
mov    0x2827(%rip),%rax
mov    (%rax),%edi
lea    0x83e(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1817 <main+0x657>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0x978(%rip),%rdi
mov    0x18(%rsp),%rsi
call   1070 <printf@plt>
mov    0x27dd(%rip),%rax
jmp    181e <main+0x65e>
mov    0x27ec(%rip),%rax
mov    (%rax),%ebx
mov    0x27db(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0x823(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x27b2(%rip),%rax
mov    (%rax),%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x27aa(%rip),%rax
mov    (%rax),%edi
lea    0x8fa(%rip),%rsi
lea    0x40(%rsp),%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1817 <main+0x657>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Usage:\0A\09Day21 <input filename> <password>\0A\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Error opening file: %s\0A\0A\00"
@errno = global i32 0
@.str.3 = [5 x i8] c"swap\00"
@.str.4 = [9 x i8] c"position\00"
@.str.5 = [34 x i8] c"swap position %d with position %d\00"
@.str.6 = [30 x i8] c"swap letter %c with letter %c\00"
@.str.7 = [7 x i8] c"rotate\00"
@.str.8 = [6 x i8] c"based\00"
@.str.9 = [38 x i8] c"rotate based on position of letter %c\00"
@.str.10 = [5 x i8] c"left\00"
@.str.11 = [15 x i8] c"rotate left %d\00"
@.str.12 = [16 x i8] c"rotate right %d\00"
@.str.13 = [8 x i8] c"reverse\00"
@.str.14 = [32 x i8] c"reverse positions %d through %d\00"
@.str.15 = [5 x i8] c"move\00"
@.str.16 = [32 x i8] c"move position %d to position %d\00"
@.str.17 = [25 x i8] c"Invalid instruction: %s\0A\00"
@.str.18 = [24 x i8] c"Scrambled password: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [40 x i8]
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %297
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %6
%28 = load i32*, i32** %6
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %36
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %3
br label %297
36: ; preds = %23
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
store i8* %39, i8** %8
%40 = load i8*, i8** %8
%41 = call i32 @strlen(i8* %40)
store i32 %41, i32* %16
br label %42
42: ; preds = %290, %36
%43 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%44 = load i32*, i32** %6
%45 = call i32* @fgets(i8* %43, i32 40, i32* %44)
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %291
47: ; preds = %42
%48 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%49 = call i64 @strncmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %124
51: ; preds = %47
%52 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%53 = getelementptr inbounds i8, i8* %52, i64 5
%54 = call i64 @strncmp(i8* %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %78
56: ; preds = %51
%57 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%58 = call i32 (i8*, i8*, ...) @sscanf(i8* %57, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32* %12, i32* %13)
%59 = load i8*, i8** %8
%60 = load i32, i32* %12
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
store i8 %63, i8* %11
%64 = load i8*, i8** %8
%65 = load i32, i32* %13
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = load i8, i8* %67
%69 = load i8*, i8** %8
%70 = load i32, i32* %12
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 %68, i8* %72
%73 = load i8, i8* %11
%74 = load i8*, i8** %8
%75 = load i32, i32* %13
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
store i8 %73, i8* %77
br label %123
78: ; preds = %51
%79 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%80 = call i32 (i8*, i8*, ...) @sscanf(i8* %79, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %9, i8* %10)
store i32 0, i32* %14
br label %81
81: ; preds = %119, %78
%82 = load i32, i32* %14
%83 = load i32, i32* %16
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %122
85: ; preds = %81
%86 = load i8*, i8** %8
%87 = load i32, i32* %14
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
%90 = load i8, i8* %89
%91 = sext i8 %90 to i32
%92 = load i8, i8* %9
%93 = sext i8 %92 to i32
%94 = icmp eq i32 %91, %93
br i1 %94, label %95, label %101
95: ; preds = %85
%96 = load i8, i8* %10
%97 = load i8*, i8** %8
%98 = load i32, i32* %14
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i8, i8* %97, i64 %99
store i8 %96, i8* %100
br label %118
101: ; preds = %85
%102 = load i8*, i8** %8
%103 = load i32, i32* %14
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i8, i8* %102, i64 %104
%106 = load i8, i8* %105
%107 = sext i8 %106 to i32
%108 = load i8, i8* %10
%109 = sext i8 %108 to i32
%110 = icmp eq i32 %107, %109
br i1 %110, label %111, label %117
111: ; preds = %101
%112 = load i8, i8* %9
%113 = load i8*, i8** %8
%114 = load i32, i32* %14
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i8, i8* %113, i64 %115
store i8 %112, i8* %116
br label %117
117: ; preds = %111, %101
br label %118
118: ; preds = %117, %95
br label %119
119: ; preds = %118
%120 = load i32, i32* %14
%121 = add nsw i32 %120, 1
store i32 %121, i32* %14
br label %81
122: ; preds = %81
br label %123
123: ; preds = %122, %56
br label %290
124: ; preds = %47
%125 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%126 = call i64 @strncmp(i8* %125, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
%127 = icmp eq i64 %126, 0
br i1 %127, label %128, label %202
128: ; preds = %124
%129 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%130 = getelementptr inbounds i8, i8* %129, i64 7
%131 = call i64 @strncmp(i8* %130, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5)
%132 = icmp eq i64 %131, 0
br i1 %132, label %133, label %165
133: ; preds = %128
%134 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%135 = call i32 (i8*, i8*, ...) @sscanf(i8* %134, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0), i8* %9)
%136 = load i8*, i8** %8
%137 = load i8, i8* %9
%138 = call i8* @strchr(i8* %136, i8 signext %137)
%139 = load i8*, i8** %8
%140 = ptrtoint i8* %138 to i64
%141 = ptrtoint i8* %139 to i64
%142 = sub i64 %140, %141
%143 = trunc i64 %142 to i32
store i32 %143, i32* %12
%144 = load i32, i32* %12
%145 = icmp sge i32 %144, 4
br i1 %145, label %146, label %149
146: ; preds = %133
%147 = load i32, i32* %12
%148 = add nsw i32 %147, 2
store i32 %148, i32* %12
br label %152
149: ; preds = %133
%150 = load i32, i32* %12
%151 = add nsw i32 %150, 1
store i32 %151, i32* %12
br label %152
152: ; preds = %149, %146
store i32 0, i32* %15
br label %153
153: ; preds = %161, %152
%154 = load i32, i32* %15
%155 = load i32, i32* %12
%156 = icmp slt i32 %154, %155
br i1 %156, label %157, label %164
157: ; preds = %153
%158 = load i8*, i8** %8
%159 = load i32, i32* %16
%160 = call i32 @Rotate_Right(i8* %158, i32 %159)
br label %161
161: ; preds = %157
%162 = load i32, i32* %15
%163 = add nsw i32 %162, 1
store i32 %163, i32* %15
br label %153
164: ; preds = %153
br label %201
165: ; preds = %128
%166 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%167 = getelementptr inbounds i8, i8* %166, i64 7
%168 = call i64 @strncmp(i8* %167, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4)
%169 = icmp eq i64 %168, 0
br i1 %169, label %170, label %185
170: ; preds = %165
%171 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%172 = call i32 (i8*, i8*, ...) @sscanf(i8* %171, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i32* %12)
store i32 0, i32* %15
br label %173
173: ; preds = %181, %170
%174 = load i32, i32* %15
%175 = load i32, i32* %12
%176 = icmp slt i32 %174, %175
br i1 %176, label %177, label %184
177: ; preds = %173
%178 = load i8*, i8** %8
%179 = load i32, i32* %16
%180 = call i32 @Rotate_Left(i8* %178, i32 %179)
br label %181
181: ; preds = %177
%182 = load i32, i32* %15
%183 = add nsw i32 %182, 1
store i32 %183, i32* %15
br label %173
184: ; preds = %173
br label %200
185: ; preds = %165
%186 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%187 = call i32 (i8*, i8*, ...) @sscanf(i8* %186, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0), i32* %12)
store i32 0, i32* %15
br label %188
188: ; preds = %196, %185
%189 = load i32, i32* %15
%190 = load i32, i32* %12
%191 = icmp slt i32 %189, %190
br i1 %191, label %192, label %199
192: ; preds = %188
%193 = load i8*, i8** %8
%194 = load i32, i32* %16
%195 = call i32 @Rotate_Right(i8* %193, i32 %194)
br label %196
196: ; preds = %192
%197 = load i32, i32* %15
%198 = add nsw i32 %197, 1
store i32 %198, i32* %15
br label %188
199: ; preds = %188
br label %200
200: ; preds = %199, %184
br label %201
201: ; preds = %200, %164
br label %289
202: ; preds = %124
%203 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%204 = call i64 @strncmp(i8* %203, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0), i32 7)
%205 = icmp eq i64 %204, 0
br i1 %205, label %206, label %249
206: ; preds = %202
%207 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%208 = call i32 (i8*, i8*, ...) @sscanf(i8* %207, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0), i32* %12, i32* %13)
%209 = load i32, i32* %13
%210 = load i32, i32* %12
%211 = sub nsw i32 %209, %210
store i32 %211, i32* %15
store i32 0, i32* %14
br label %212
212: ; preds = %245, %206
%213 = load i32, i32* %14
%214 = load i32, i32* %15
%215 = sdiv i32 %214, 2
%216 = icmp sle i32 %213, %215
br i1 %216, label %217, label %248
217: ; preds = %212
%218 = load i8*, i8** %8
%219 = load i32, i32* %12
%220 = load i32, i32* %14
%221 = add nsw i32 %219, %220
%222 = sext i32 %221 to i64
%223 = getelementptr inbounds i8, i8* %218, i64 %222
%224 = load i8, i8* %223
store i8 %224, i8* %11
%225 = load i8*, i8** %8
%226 = load i32, i32* %13
%227 = load i32, i32* %14
%228 = sub nsw i32 %226, %227
%229 = sext i32 %228 to i64
%230 = getelementptr inbounds i8, i8* %225, i64 %229
%231 = load i8, i8* %230
%232 = load i8*, i8** %8
%233 = load i32, i32* %12
%234 = load i32, i32* %14
%235 = add nsw i32 %233, %234
%236 = sext i32 %235 to i64
%237 = getelementptr inbounds i8, i8* %232, i64 %236
store i8 %231, i8* %237
%238 = load i8, i8* %11
%239 = load i8*, i8** %8
%240 = load i32, i32* %13
%241 = load i32, i32* %14
%242 = sub nsw i32 %240, %241
%243 = sext i32 %242 to i64
%244 = getelementptr inbounds i8, i8* %239, i64 %243
store i8 %238, i8* %244
br label %245
245: ; preds = %217
%246 = load i32, i32* %14
%247 = add nsw i32 %246, 1
store i32 %247, i32* %14
br label %212
248: ; preds = %212
br label %288
249: ; preds = %202
%250 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%251 = call i64 @strncmp(i8* %250, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0), i32 4)
%252 = icmp eq i64 %251, 0
br i1 %252, label %253, label %280
253: ; preds = %249
%254 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%255 = call i32 (i8*, i8*, ...) @sscanf(i8* %254, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0), i32* %12, i32* %13)
%256 = load i32, i32* %12
%257 = load i32, i32* %13
%258 = icmp sgt i32 %256, %257
br i1 %258, label %259, label %269
259: ; preds = %253
%260 = load i8*, i8** %8
%261 = load i32, i32* %13
%262 = sext i32 %261 to i64
%263 = getelementptr inbounds i8, i8* %260, i64 %262
%264 = load i32, i32* %12
%265 = load i32, i32* %13
%266 = sub nsw i32 %264, %265
%267 = add nsw i32 %266, 1
%268 = call i32 @Rotate_Right(i8* %263, i32 %267)
br label %279
269: ; preds = %253
%270 = load i8*, i8** %8
%271 = load i32, i32* %12
%272 = sext i32 %271 to i64
%273 = getelementptr inbounds i8, i8* %270, i64 %272
%274 = load i32, i32* %13
%275 = load i32, i32* %12
%276 = sub nsw i32 %274, %275
%277 = add nsw i32 %276, 1
%278 = call i32 @Rotate_Left(i8* %273, i32 %277)
br label %279
279: ; preds = %269, %259
br label %287
280: ; preds = %249
%281 = load i32, i32* @stderr
%282 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%283 = call i32 (i32, i8*, ...) @fprintf(i32 %281, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.17, i64 0, i64 0), i8* %282)
%284 = load i32*, i32** %6
%285 = call i32 @fclose(i32* %284)
%286 = load i32, i32* @EXIT_FAILURE
store i32 %286, i32* %3
br label %297
287: ; preds = %279
br label %288
288: ; preds = %287, %248
br label %289
289: ; preds = %288, %201
br label %290
290: ; preds = %289, %123
br label %42
291: ; preds = %42
%292 = load i32*, i32** %6
%293 = call i32 @fclose(i32* %292)
%294 = load i8*, i8** %8
%295 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.18, i64 0, i64 0), i8* %294)
%296 = load i32, i32* @EXIT_SUCCESS
store i32 %296, i32* %3
br label %297
297: ; preds = %291, %280, %30, %19
%298 = load i32, i32* %3
ret i32 %298
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Usage:\0A\09Day21 <input filename> <password>\0A\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Error opening file: %s\0A\0A\00"
@errno = global i32 0
@.str.3 = [5 x i8] c"swap\00"
@.str.4 = [9 x i8] c"position\00"
@.str.5 = [34 x i8] c"swap position %d with position %d\00"
@.str.6 = [30 x i8] c"swap letter %c with letter %c\00"
@.str.7 = [7 x i8] c"rotate\00"
@.str.8 = [6 x i8] c"based\00"
@.str.9 = [38 x i8] c"rotate based on position of letter %c\00"
@.str.10 = [5 x i8] c"left\00"
@.str.11 = [15 x i8] c"rotate left %d\00"
@.str.12 = [16 x i8] c"rotate right %d\00"
@.str.13 = [8 x i8] c"reverse\00"
@.str.14 = [32 x i8] c"reverse positions %d through %d\00"
@.str.15 = [5 x i8] c"move\00"
@.str.16 = [32 x i8] c"move position %d to position %d\00"
@.str.17 = [25 x i8] c"Invalid instruction: %s\0A\00"
@.str.18 = [24 x i8] c"Scrambled password: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [40 x i8]
%4 = alloca i8
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %303
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %23)
br label %303
25: ; preds = %15
%26 = getelementptr inbounds i8*, i8** %1, i64 2
%27 = load i8*, i8** %26
%28 = tail call i32 @strlen(i8* %27)
%29 = call i32* @fgets(i8* %8, i32 40, i32* %18)
%30 = icmp eq i32* %29, null
br i1 %30, label %300, label %31
31: ; preds = %25
%32 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 7
%33 = ptrtoint i8* %27 to i64
%34 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 5
%35 = icmp sgt i32 %28, 0
%36 = zext i32 %28 to i64
%37 = getelementptr i8, i8* %27, i64 %36
%38 = getelementptr inbounds i8, i8* %4, i64 1
%39 = getelementptr inbounds i8, i8* %5, i64 1
%40 = icmp ult i32 %28, 8
%41 = icmp ult i8* %27, %38
%42 = icmp ult i8* %4, %37
%43 = and i1 %41, %42
%44 = icmp ult i8* %27, %39
%45 = icmp ult i8* %5, %37
%46 = and i1 %44, %45
%47 = or i1 %43, %46
%48 = and i64 %36, 4294967288
%49 = icmp eq i64 %48, %36
%50 = and i64 %36, 1
%51 = icmp eq i64 %50, 0
%52 = sub nsw i64 0, %36
br label %53
53: ; preds = %31, %297
%54 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %187
56: ; preds = %53
%57 = call i64 @strncmp(i8* %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 8)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %72
59: ; preds = %56
%60 = call i32 (i8*, i8*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32* %6, i32* %7)
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %27, i64 %62
%64 = load i8, i8* %63
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %27, i64 %66
%68 = load i8, i8* %67
store i8 %68, i8* %63
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %27, i64 %70
store i8 %64, i8* %71
br label %297
72: ; preds = %56
%73 = call i32 (i8*, i8*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0), i8* %4, i8* %5)
br i1 %35, label %74, label %297
74: ; preds = %72
%75 = select i1 %40, i1 true, i1 %47
br i1 %75, label %144, label %76
76: ; preds = %74
%77 = load i8, i8* %4
%78 = insertelement <8 x i8> poison, i8 %77, i64 0
%79 = shufflevector <8 x i8> %78, <8 x i8> poison, <8 x i32> zeroinitializer
%80 = load i8, i8* %5
%81 = insertelement <8 x i8> poison, i8 %80, i64 0
%82 = shufflevector <8 x i8> %81, <8 x i8> poison, <8 x i32> zeroinitializer
br label %83
83: ; preds = %140, %76
%84 = phi i64 [ 0, %76 ], [ %141, %140 ]
%85 = getelementptr inbounds i8, i8* %27, i64 %84
%86 = bitcast i8* %85 to <8 x i8>*
%87 = load <8 x i8>, <8 x i8>* %86
%88 = icmp eq <8 x i8> %87, %79
%89 = icmp eq <8 x i8> %87, %82
%90 = xor <8 x i1> %88, <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>
%91 = select <8 x i1> %90, <8 x i1> %89, <8 x i1> zeroinitializer
%92 = select <8 x i1> %91, <8 x i8> %79, <8 x i8> %82
%93 = or <8 x i1> %91, %88
%94 = extractelement <8 x i1> %93, i64 0
br i1 %94, label %95, label %98
95: ; preds = %83
%96 = getelementptr inbounds i8, i8* %27, i64 %84
%97 = extractelement <8 x i8> %92, i64 0
store i8 %97, i8* %96
br label %98
98: ; preds = %95, %83
%99 = extractelement <8 x i1> %93, i64 1
br i1 %99, label %100, label %104
100: ; preds = %98
%101 = or i64 %84, 1
%102 = getelementptr inbounds i8, i8* %27, i64 %101
%103 = extractelement <8 x i8> %92, i64 1
store i8 %103, i8* %102
br label %104
104: ; preds = %100, %98
%105 = extractelement <8 x i1> %93, i64 2
br i1 %105, label %106, label %110
106: ; preds = %104
%107 = or i64 %84, 2
%108 = getelementptr inbounds i8, i8* %27, i64 %107
%109 = extractelement <8 x i8> %92, i64 2
store i8 %109, i8* %108
br label %110
110: ; preds = %106, %104
%111 = extractelement <8 x i1> %93, i64 3
br i1 %111, label %112, label %116
112: ; preds = %110
%113 = or i64 %84, 3
%114 = getelementptr inbounds i8, i8* %27, i64 %113
%115 = extractelement <8 x i8> %92, i64 3
store i8 %115, i8* %114
br label %116
116: ; preds = %112, %110
%117 = extractelement <8 x i1> %93, i64 4
br i1 %117, label %118, label %122
118: ; preds = %116
%119 = or i64 %84, 4
%120 = getelementptr inbounds i8, i8* %27, i64 %119
%121 = extractelement <8 x i8> %92, i64 4
store i8 %121, i8* %120
br label %122
122: ; preds = %118, %116
%123 = extractelement <8 x i1> %93, i64 5
br i1 %123, label %124, label %128
124: ; preds = %122
%125 = or i64 %84, 5
%126 = getelementptr inbounds i8, i8* %27, i64 %125
%127 = extractelement <8 x i8> %92, i64 5
store i8 %127, i8* %126
br label %128
128: ; preds = %124, %122
%129 = extractelement <8 x i1> %93, i64 6
br i1 %129, label %130, label %134
130: ; preds = %128
%131 = or i64 %84, 6
%132 = getelementptr inbounds i8, i8* %27, i64 %131
%133 = extractelement <8 x i8> %92, i64 6
store i8 %133, i8* %132
br label %134
134: ; preds = %130, %128
%135 = extractelement <8 x i1> %93, i64 7
br i1 %135, label %136, label %140
136: ; preds = %134
%137 = or i64 %84, 7
%138 = getelementptr inbounds i8, i8* %27, i64 %137
%139 = extractelement <8 x i8> %92, i64 7
store i8 %139, i8* %138
br label %140
140: ; preds = %136, %134
%141 = add nuw i64 %84, 8
%142 = icmp eq i64 %141, %48
br i1 %142, label %143, label %83
143: ; preds = %140
br i1 %49, label %297, label %144
144: ; preds = %74, %143
%145 = phi i64 [ 0, %74 ], [ %48, %143 ]
%146 = xor i64 %145, -1
br i1 %51, label %159, label %147
147: ; preds = %144
%148 = getelementptr inbounds i8, i8* %27, i64 %145
%149 = load i8, i8* %148
%150 = load i8, i8* %4
%151 = icmp eq i8 %149, %150
%152 = load i8, i8* %5
br i1 %151, label %155, label %153
153: ; preds = %147
%154 = icmp eq i8 %149, %152
br i1 %154, label %155, label %157
155: ; preds = %153, %147
%156 = phi i8 [ %152, %147 ], [ %150, %153 ]
store i8 %156, i8* %148
br label %157
157: ; preds = %155, %153
%158 = or i64 %145, 1
br label %159
159: ; preds = %157, %144
%160 = phi i64 [ %145, %144 ], [ %158, %157 ]
%161 = icmp eq i64 %146, %52
br i1 %161, label %297, label %162
162: ; preds = %159, %184
%163 = phi i64 [ %185, %184 ], [ %160, %159 ]
%164 = getelementptr inbounds i8, i8* %27, i64 %163
%165 = load i8, i8* %164
%166 = load i8, i8* %4
%167 = icmp eq i8 %165, %166
%168 = load i8, i8* %5
br i1 %167, label %171, label %169
169: ; preds = %162
%170 = icmp eq i8 %165, %168
br i1 %170, label %171, label %173
171: ; preds = %169, %162
%172 = phi i8 [ %168, %162 ], [ %166, %169 ]
store i8 %172, i8* %164
br label %173
173: ; preds = %171, %169
%174 = add nuw nsw i64 %163, 1
%175 = getelementptr inbounds i8, i8* %27, i64 %174
%176 = load i8, i8* %175
%177 = load i8, i8* %4
%178 = icmp eq i8 %176, %177
%179 = load i8, i8* %5
br i1 %178, label %182, label %180
180: ; preds = %173
%181 = icmp eq i8 %176, %179
br i1 %181, label %182, label %184
182: ; preds = %180, %173
%183 = phi i8 [ %179, %173 ], [ %177, %180 ]
store i8 %183, i8* %175
br label %184
184: ; preds = %182, %180
%185 = add nuw nsw i64 %163, 2
%186 = icmp eq i64 %185, %36
br i1 %186, label %297, label %162
187: ; preds = %53
%188 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 6)
%189 = icmp eq i64 %188, 0
br i1 %189, label %190, label %233
190: ; preds = %187
%191 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5)
%192 = icmp eq i64 %191, 0
br i1 %192, label %193, label %210
193: ; preds = %190
%194 = call i32 (i8*, i8*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0), i8* %4)
%195 = load i8, i8* %4
%196 = call i8* @strchr(i8* dereferenceable(1) %27, i8 signext %195)
%197 = ptrtoint i8* %196 to i64
%198 = sub i64 %197, %33
%199 = trunc i64 %198 to i32
%200 = icmp sgt i32 %199, 3
%201 = select i1 %200, i32 2, i32 1
%202 = add nsw i32 %201, %199
store i32 %202, i32* %6
%203 = icmp sgt i32 %202, 0
br i1 %203, label %204, label %297
204: ; preds = %193, %204
%205 = phi i32 [ %207, %204 ], [ 0, %193 ]
%206 = call i32 @Rotate_Right(i8* %27, i32 %28)
%207 = add nuw nsw i32 %205, 1
%208 = load i32, i32* %6
%209 = icmp slt i32 %207, %208
br i1 %209, label %204, label %297
210: ; preds = %190
%211 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 4)
%212 = icmp eq i64 %211, 0
br i1 %212, label %213, label %223
213: ; preds = %210
%214 = call i32 (i8*, i8*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i32* %6)
%215 = load i32, i32* %6
%216 = icmp sgt i32 %215, 0
br i1 %216, label %217, label %297
217: ; preds = %213, %217
%218 = phi i32 [ %220, %217 ], [ 0, %213 ]
%219 = call i32 @Rotate_Left(i8* %27, i32 %28)
%220 = add nuw nsw i32 %218, 1
%221 = load i32, i32* %6
%222 = icmp slt i32 %220, %221
br i1 %222, label %217, label %297
223: ; preds = %210
%224 = call i32 (i8*, i8*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0), i32* %6)
%225 = load i32, i32* %6
%226 = icmp sgt i32 %225, 0
br i1 %226, label %227, label %297
227: ; preds = %223, %227
%228 = phi i32 [ %230, %227 ], [ 0, %223 ]
%229 = call i32 @Rotate_Right(i8* %27, i32 %28)
%230 = add nuw nsw i32 %228, 1
%231 = load i32, i32* %6
%232 = icmp slt i32 %230, %231
br i1 %232, label %227, label %297
233: ; preds = %187
%234 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i64 0, i64 0), i32 7)
%235 = icmp eq i64 %234, 0
br i1 %235, label %236, label %273
236: ; preds = %233
%237 = call i32 (i8*, i8*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.14, i64 0, i64 0), i32* %6, i32* %7)
%238 = load i32, i32* %7
%239 = load i32, i32* %6
%240 = sub nsw i32 %238, %239
%241 = icmp slt i32 %240, -1
br i1 %241, label %297, label %242
242: ; preds = %236
%243 = sdiv i32 %240, 2
%244 = sext i32 %239 to i64
%245 = getelementptr inbounds i8, i8* %27, i64 %244
%246 = load i8, i8* %245
%247 = sext i32 %238 to i64
%248 = getelementptr inbounds i8, i8* %27, i64 %247
%249 = load i8, i8* %248
store i8 %249, i8* %245
%250 = load i32, i32* %7
%251 = sext i32 %250 to i64
%252 = getelementptr inbounds i8, i8* %27, i64 %251
store i8 %246, i8* %252
%253 = add i32 %240, 1
%254 = icmp ult i32 %253, 3
br i1 %254, label %297, label %255
255: ; preds = %242, %255
%256 = phi i32 [ %257, %255 ], [ 0, %242 ]
%257 = add nuw nsw i32 %256, 1
%258 = load i32, i32* %6
%259 = load i32, i32* %7
%260 = add nsw i32 %258, %257
%261 = sext i32 %260 to i64
%262 = getelementptr inbounds i8, i8* %27, i64 %261
%263 = load i8, i8* %262
%264 = sub nsw i32 %259, %257
%265 = sext i32 %264 to i64
%266 = getelementptr inbounds i8, i8* %27, i64 %265
%267 = load i8, i8* %266
store i8 %267, i8* %262
%268 = load i32, i32* %7
%269 = sub nsw i32 %268, %257
%270 = sext i32 %269 to i64
%271 = getelementptr inbounds i8, i8* %27, i64 %270
store i8 %263, i8* %271
%272 = icmp eq i32 %257, %243
br i1 %272, label %297, label %255
273: ; preds = %233
%274 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0), i32 4)
%275 = icmp eq i64 %274, 0
br i1 %275, label %276, label %293
276: ; preds = %273
%277 = call i32 (i8*, i8*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.16, i64 0, i64 0), i32* %6, i32* %7)
%278 = load i32, i32* %6
%279 = load i32, i32* %7
%280 = icmp sgt i32 %278, %279
br i1 %280, label %281, label %287
281: ; preds = %276
%282 = sext i32 %279 to i64
%283 = getelementptr inbounds i8, i8* %27, i64 %282
%284 = add i32 %278, 1
%285 = sub i32 %284, %279
%286 = call i32 @Rotate_Right(i8* %283, i32 %285)
br label %297
287: ; preds = %276
%288 = sext i32 %278 to i64
%289 = getelementptr inbounds i8, i8* %27, i64 %288
%290 = sub i32 1, %278
%291 = add i32 %290, %279
%292 = call i32 @Rotate_Left(i8* %289, i32 %291)
br label %297
293: ; preds = %273
%294 = load i32, i32* @stderr
%295 = call i32 (i32, i8*, ...) @fprintf(i32 %294, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.17, i64 0, i64 0), i8* %8)
%296 = call i32 @fclose(i32* %18)
br label %303
297: ; preds = %255, %227, %217, %204, %159, %184, %242, %143, %236, %223, %213, %193, %72, %287, %281, %59
%298 = call i32* @fgets(i8* %8, i32 40, i32* %18)
%299 = icmp eq i32* %298, null
br i1 %299, label %300, label %53
300: ; preds = %297, %25
%301 = call i32 @fclose(i32* %18)
%302 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.18, i64 0, i64 0), i8* %27)
br label %303
303: ; preds = %300, %293, %20, %12
%304 = phi i32* [ @EXIT_FAILURE, %12 ], [ @EXIT_FAILURE, %20 ], [ @EXIT_FAILURE, %293 ], [ @EXIT_SUCCESS, %300 ]
%305 = load i32, i32* %304
ret i32 %305
}