text: #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  
  enum op {
    nop,
    acc,
    jmp
  };
  
  static int program[] = {
  #include "input.h"
  };
  static const int commands = (sizeof program)/(2*sizeof(int));
  
  static void execute(int opcode, int oparg, int *accum, int *ins) {
    switch (opcode) {
    case acc:
      *accum += oparg;
    case nop:
      ++*ins;
      break;
    case jmp:
      *ins += oparg;
      break;
    default:
      printf("ERROR!\n");
      exit(1);
    }
  }
  
  static int run(int *accum, int n) {
    char seen[commands] = { 0 };
    int ins = 0;
    int opcode = 0;
    int oparg = 0;
    *accum = 0;
    while (ins < commands && !seen[ins]) {
      opcode = program[2 * ins];
      oparg = program[2 * ins + 1];
      seen[ins] += 1;
      if (opcode == nop || opcode == jmp) {
        if (!n)
          opcode = opcode == nop ? jmp : nop;
        if (n >= 0)
          --n;
      }
      execute(opcode, oparg, accum, &ins);
    }
    return ins >= commands;
  }
  
  int main(int argc, char **argv) {
    int accum = 0;
    int changed = 0;
    for(; !run(&accum, changed); ++changed)
      ;
    printf("%d\n", accum);
    return 0;
  }
  