// File: /workspace/github_c_makefile_star2_O0/mvermeulen[P]wspy/wspy.c
// Function: parse_options
int parse_options(int argc,char *const argv[]){
  FILE *fp;
  int opt;
  int i;
  int value;
  unsigned int lev;
  static struct option long_options[] = {
    { "branch", no_argument, 0, 4 }, 
    { "no-branch", no_argument, 0, 5 },
    { "csv", no_argument, 0, 3 },
    { "cache1", no_argument, 0, 39 },
    { "no-cache1", no_argument, 0, 40 },
    { "cache2", no_argument, 0, 6 }, 
    { "no-cache2", no_argument, 0, 7 },
    { "cache3", no_argument, 0, 8 }, 
    { "no-cache3", no_argument, 0, 9 },
    { "dcache", no_argument, 0, 10 },
    { "no-cache", no_argument, 0, 11 },
    { "float",no_argument,0,33 },
    { "icache", no_argument, 0, 12 },
    { "no-icache", no_argument, 0, 13 },
    { "interval", required_argument, 0, 34 },
    { "ipc", no_argument, 0, 14 }, 
    { "no-ipc", no_argument, 0, 15 },
    { "memory", no_argument, 0, 16 }, 
    { "no-memory", no_argument, 0, 17 },
    { "opcache", no_argument, 0, 18 }, 
    { "no-opcache", no_argument, 0, 19 },
    { "per-core", no_argument, 0, 20 },
    { "rusage", no_argument, 0, 21 },
    { "no-rusage", no_argument, 0, 22 },
    { "software", no_argument, 0, 23 },
    { "no-software", no_argument, 0, 24 },
    { "system", no_argument, 0, 36 },
    { "no-system", no_argument, 0, 37 },
    { "tlb", no_argument, 0, 25 }, 
    { "no-tlb", no_argument, 0, 26 },
    { "topdown", no_argument, 0, 27 }, // (t)
    { "no-topdown", no_argument, 0, 28 },
    { "topdown2", no_argument, 0, 29 }, //
    { "no-topdown2", no_argument, 0, 30 },
    { "topdown-frontend",no_argument, 0, 42 },
    { "no-topdown-frontend",no_argument, 0, 43 },
    { "topdown-backend",no_argument,0,46 },
    { "no-topdown-backend",no_argument,0,47 },
    { "topdown-optlb",no_argument,0,44 },
    { "no-topdown-optlb",no_argument,0,45 },
    { "tree", required_argument, 0, 31 }, //
    { "tree-cmdline",no_argument,0,35 },
    { "tree-open",no_argument,0, 38 },
    { "tree-vmsize",no_argument,0,41 },
    { "verbose", no_argument, 0, 32 },
    { 0,0,0,0 },
  };
  while ((opt = getopt_long(argc,argv,"+abcio:rsStv",long_options,NULL)) != -1){
    switch (opt){
    case 3: //--csv
      csvflag = 1;
      break;
    case 4: // --branch
    case 'b':
      counter_mask |= COUNTER_BRANCH;
      break;
    case 5: // --no-branch
      counter_mask &= (~COUNTER_BRANCH);
      break;
    case 39: // --cache1
      counter_mask |= COUNTER_L1CACHE;
      break;
    case 40:
      counter_mask &= (~COUNTER_L1CACHE);
      break;
    case 6: // --cache2
    case 'c':
      counter_mask |= COUNTER_L2CACHE;
      break;
    case 7: // --no-cache2
      counter_mask &= (~COUNTER_L2CACHE);
      break;
    case 8: // --cache3
      counter_mask |= COUNTER_L3CACHE;
      break;
    case 9: // --no-cache3
      counter_mask &= (~COUNTER_L3CACHE);
      break;
    case 10: // --dcache
      counter_mask |= COUNTER_DCACHE;
      break;
    case 11: // --no-dcache
      counter_mask &= (~COUNTER_DCACHE);
      break;
    case 12: // --icache
      counter_mask |= COUNTER_ICACHE;
      break;
    case 13: // --no-icache
      counter_mask &= (~COUNTER_ICACHE);
      break;
    case 14: // --ipc
    case 'i':
      counter_mask |= COUNTER_IPC;
      break;
    case 15: // --no-ipc
      counter_mask &= (~COUNTER_IPC);
      break;
    case 16: // --memory
    case 'm':
      counter_mask |= COUNTER_MEMORY;
      break;
    case 17: // --no-memory
      counter_mask &= (~COUNTER_MEMORY);
      break;
    case 18: // --opcache
      counter_mask |= COUNTER_OPCACHE;
      break;
    case 19: // --no-opcache
      counter_mask &= (~COUNTER_OPCACHE);
      break;
    case 20: // --per-core
    case 'a':
      aflag = 1;
      break;
    case 'o':
      fp = fopen(optarg,"w");
      if (!fp){
	error("can not open file: %s\n",optarg);
      } else {
	outfile = fp;
	oflag = 1;
      }
      break;
    case 21: // --rusage
    case 'r':
      xflag = 1;
      break;
    case 22: // --no-rusage
      xflag = 0;
      break;
    case 23: // --software
      counter_mask |= COUNTER_SOFTWARE;
      break;
    case 24: // --no-software
      counter_mask &= (~COUNTER_SOFTWARE);
      break;
    case 25: // --tlb
      counter_mask |= COUNTER_TLB;
      break;
    case 26: // --no-tlb
      counter_mask &= (~COUNTER_TLB);
      break;
    case 27: // --topdown
    case 't':
      counter_mask |= COUNTER_TOPDOWN;
      break;
    case 28: // --no-topdown
      counter_mask &= (~COUNTER_TOPDOWN);
      break;
    case 29: // --topdown2
      counter_mask |= COUNTER_TOPDOWN2;
      break;
    case 30: // --no-topdown2
      counter_mask &= (~COUNTER_TOPDOWN2);
      break;
    case 42: // --topdown-frontend
      counter_mask |= COUNTER_TOPDOWN_FE;
      break;
    case 43: // --no-topdown-frontend
      counter_mask &= (~COUNTER_TOPDOWN_FE);
      break;
    case 46: // --topdown-backend
      counter_mask |= COUNTER_TOPDOWN_BE;
      break;
    case 47: // --no-topdown-backend
      counter_mask &= (~COUNTER_TOPDOWN_BE);
      break;      
    case 44: // --topdown-optlb
      counter_mask |= COUNTER_TOPDOWN_OP;
      break;
    case 45: // --no-topdown-optlb
      counter_mask &= (~COUNTER_TOPDOWN_OP);
      break;
    case 31: // --tree
      if ((treefile = fopen(optarg,"w")) == NULL){
	warning("unable to open tree file: %s, ignored\n",optarg);
      } else {
	treeflag = 1;
      }
      break;
    case 32: // --verbose
    case 'v':
      vflag++;
      if (vflag>1) set_error_level(ERROR_LEVEL_DEBUG2);
      else set_error_level(ERROR_LEVEL_DEBUG);
      break;
    case 33: // --float
      counter_mask |= COUNTER_FLOAT;
      break;
    case 34:
      if ((sscanf(optarg,"%d",&value) == 1) && value > 0){
	interval = value;
      } else {
	warning("invalid argument to --interval: %s, ignored\n",optarg);
      }
      break;
    case 35:
      tree_cmdline = 1;
      break;
    case 36: // --system
    case 's':
      sflag = 1;
      break;
    case 37:
      sflag = 0;
      break;
    case 38:
      tree_open = 1;
      trace_syscall = 1;
      break;
    default:
      return 1;
    }
  }
  if (optind >= argc){
    warning("missing command after options\n");
    return 1;
  }
  command_line_argv = calloc(argc-optind+1,sizeof(char *));
  command_line_argc = argc - optind;
  for (i=0;i<command_line_argc;i++){
    command_line_argv[i] = argv[i+optind];
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x9e6c(%rip), %rdx      # 0xd2f9
leaq 0xed4c(%rip), %rcx      # 0x121e0
xorl %eax, %eax
movl %eax, %r8d
callq 0x30d0
movl %eax, -0x1c(%rbp)
cmpl $-0x1, %eax
je 0x3934
movl -0x1c(%rbp), %eax
addl $-0x3, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x73, %eax
ja 0x3923
movq -0x30(%rbp), %rax
leaq 0x9b3a(%rip), %rcx      # 0xd004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, 0xfc0b(%rip)      # 0x130e8
jmp 0x392f
movl 0xecec(%rip), %eax      # 0x121d4
orl $0x40, %eax
movl %eax, 0xece3(%rip)      # 0x121d4
jmp 0x392f
movl 0xecd8(%rip), %eax      # 0x121d4
andl $-0x41, %eax
movl %eax, 0xeccf(%rip)      # 0x121d4
jmp 0x392f
movl 0xecc4(%rip), %eax      # 0x121d4
orl $0x200, %eax            # imm = 0x200
movl %eax, 0xecb9(%rip)      # 0x121d4
jmp 0x392f
movl 0xecae(%rip), %eax      # 0x121d4
andl $0xfffffdff, %eax       # imm = 0xFFFFFDFF
movl %eax, 0xeca3(%rip)      # 0x121d4
jmp 0x392f
movl 0xec98(%rip), %eax      # 0x121d4
orl $0x400, %eax            # imm = 0x400
movl %eax, 0xec8d(%rip)      # 0x121d4
jmp 0x392f
movl 0xec82(%rip), %eax      # 0x121d4
andl $0xfffffbff, %eax       # imm = 0xFFFFFBFF
movl %eax, 0xec77(%rip)      # 0x121d4
jmp 0x392f
movl 0xec6c(%rip), %eax      # 0x121d4
orl $0x800, %eax            # imm = 0x800
movl %eax, 0xec61(%rip)      # 0x121d4
jmp 0x392f
movl 0xec56(%rip), %eax      # 0x121d4
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
movl %eax, 0xec4b(%rip)      # 0x121d4
jmp 0x392f
movl 0xec40(%rip), %eax      # 0x121d4
orl $0x80, %eax
movl %eax, 0xec35(%rip)      # 0x121d4
jmp 0x392f
movl 0xec2a(%rip), %eax      # 0x121d4
andl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
movl %eax, 0xec1f(%rip)      # 0x121d4
jmp 0x392f
movl 0xec14(%rip), %eax      # 0x121d4
orl $0x100, %eax            # imm = 0x100
movl %eax, 0xec09(%rip)      # 0x121d4
jmp 0x392f
movl 0xebfe(%rip), %eax      # 0x121d4
andl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
movl %eax, 0xebf3(%rip)      # 0x121d4
jmp 0x392f
movl 0xebe8(%rip), %eax      # 0x121d4
orl $0x1, %eax
movl %eax, 0xebdf(%rip)      # 0x121d4
jmp 0x392f
movl 0xebd4(%rip), %eax      # 0x121d4
andl $-0x2, %eax
movl %eax, 0xebcb(%rip)      # 0x121d4
jmp 0x392f
movl 0xebc0(%rip), %eax      # 0x121d4
orl $0x1000, %eax           # imm = 0x1000
movl %eax, 0xebb5(%rip)      # 0x121d4
jmp 0x392f
movl 0xebaa(%rip), %eax      # 0x121d4
andl $0xffffefff, %eax       # imm = 0xFFFFEFFF
movl %eax, 0xeb9f(%rip)      # 0x121d4
jmp 0x392f
movl 0xeb94(%rip), %eax      # 0x121d4
orl $0x4000, %eax           # imm = 0x4000
movl %eax, 0xeb89(%rip)      # 0x121d4
jmp 0x392f
movl 0xeb7e(%rip), %eax      # 0x121d4
andl $0xffffbfff, %eax       # imm = 0xFFFFBFFF
movl %eax, 0xeb73(%rip)      # 0x121d4
jmp 0x392f
movl $0x1, 0xfa68(%rip)      # 0x130d8
jmp 0x392f
movq 0xe954(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0xb786(%rip), %rsi      # 0xee0c
callq 0x3270
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x36b0
movq 0xe933(%rip), %rax      # 0x11fd0
movq (%rax), %rsi
leaq 0x9c5f(%rip), %rdi      # 0xd306
movb $0x0, %al
callq 0xbc00
jmp 0x36c5
movq -0x18(%rbp), %rax
movq %rax, 0xfa4d(%rip)      # 0x13108
movl $0x1, 0xfa17(%rip)      # 0x130dc
jmp 0x392f
movl $0x1, 0xeafc(%rip)      # 0x121d0
jmp 0x392f
movl $0x0, 0xeaed(%rip)      # 0x121d0
jmp 0x392f
movl 0xeae6(%rip), %eax      # 0x121d4
orl $0x8000, %eax           # imm = 0x8000
movl %eax, 0xeadb(%rip)      # 0x121d4
jmp 0x392f
movl 0xead0(%rip), %eax      # 0x121d4
andl $0xffff7fff, %eax       # imm = 0xFFFF7FFF
movl %eax, 0xeac5(%rip)      # 0x121d4
jmp 0x392f
movl 0xeaba(%rip), %eax      # 0x121d4
orl $0x2000, %eax           # imm = 0x2000
movl %eax, 0xeaaf(%rip)      # 0x121d4
jmp 0x392f
movl 0xeaa4(%rip), %eax      # 0x121d4
andl $0xffffdfff, %eax       # imm = 0xFFFFDFFF
movl %eax, 0xea99(%rip)      # 0x121d4
jmp 0x392f
movl 0xea8e(%rip), %eax      # 0x121d4
orl $0x2, %eax
movl %eax, 0xea85(%rip)      # 0x121d4
jmp 0x392f
movl 0xea7a(%rip), %eax      # 0x121d4
andl $-0x3, %eax
movl %eax, 0xea71(%rip)      # 0x121d4
jmp 0x392f
movl 0xea66(%rip), %eax      # 0x121d4
orl $0x4, %eax
movl %eax, 0xea5d(%rip)      # 0x121d4
jmp 0x392f
movl 0xea52(%rip), %eax      # 0x121d4
andl $-0x5, %eax
movl %eax, 0xea49(%rip)      # 0x121d4
jmp 0x392f
movl 0xea3e(%rip), %eax      # 0x121d4
orl $0x8, %eax
movl %eax, 0xea35(%rip)      # 0x121d4
jmp 0x392f
movl 0xea2a(%rip), %eax      # 0x121d4
andl $-0x9, %eax
movl %eax, 0xea21(%rip)      # 0x121d4
jmp 0x392f
movl 0xea16(%rip), %eax      # 0x121d4
orl $0x10, %eax
movl %eax, 0xea0d(%rip)      # 0x121d4
jmp 0x392f
movl 0xea02(%rip), %eax      # 0x121d4
andl $-0x11, %eax
movl %eax, 0xe9f9(%rip)      # 0x121d4
jmp 0x392f
movl 0xe9ee(%rip), %eax      # 0x121d4
orl $0x20, %eax
movl %eax, 0xe9e5(%rip)      # 0x121d4
jmp 0x392f
movl 0xe9da(%rip), %eax      # 0x121d4
andl $-0x21, %eax
movl %eax, 0xe9d1(%rip)      # 0x121d4
jmp 0x392f
movq 0xe7c1(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0xb5f3(%rip), %rsi      # 0xee0c
callq 0x3270
movq %rax, 0xf8db(%rip)      # 0x13100
cmpq $0x0, %rax
jne 0x3845
movq 0xe79e(%rip), %rax      # 0x11fd0
movq (%rax), %rsi
leaq 0x9ae1(%rip), %rdi      # 0xd31d
movb $0x0, %al
callq 0xbd10
jmp 0x384f
movl $0x1, 0xf8a1(%rip)      # 0x130f0
jmp 0x392f
movl 0xf88a(%rip), %eax      # 0x130e4
addl $0x1, %eax
movl %eax, 0xf881(%rip)      # 0x130e4
cmpl $0x1, 0xf87a(%rip)      # 0x130e4
jle 0x3878
movl $0x5, %edi
callq 0xc220
jmp 0x3882
movl $0x4, %edi
callq 0xc220
jmp 0x392f
movl 0xe947(%rip), %eax      # 0x121d4
orl $0x10000, %eax          # imm = 0x10000
movl %eax, 0xe93c(%rip)      # 0x121d4
jmp 0x392f
movq 0xe72c(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0xc2d8(%rip), %rsi      # 0xfb86
leaq -0x24(%rbp), %rdx
movb $0x0, %al
callq 0x3230
cmpl $0x1, %eax
jne 0x38cf
cmpl $0x0, -0x24(%rbp)
jle 0x38cf
movl -0x24(%rbp), %eax
movl %eax, 0xf81f(%rip)      # 0x130ec
jmp 0x38e7
movq 0xe6fa(%rip), %rax      # 0x11fd0
movq (%rax), %rsi
leaq 0x9a64(%rip), %rdi      # 0xd344
movb $0x0, %al
callq 0xbd10
jmp 0x392f
movl $0x1, 0xf801(%rip)      # 0x130f4
jmp 0x392f
movl $0x1, 0xf7e1(%rip)      # 0x130e0
jmp 0x392f
movl $0x0, 0xf7d5(%rip)      # 0x130e0
jmp 0x392f
movl $0x1, 0xf7e1(%rip)      # 0x130f8
movl $0x1, 0xf7db(%rip)      # 0x130fc
jmp 0x392f
movl $0x1, -0x4(%rbp)
jmp 0x39d8
jmp 0x347f
movq 0xe68d(%rip), %rax      # 0x11fc8
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jl 0x3959
leaq 0x9a28(%rip), %rdi      # 0xd371
movb $0x0, %al
callq 0xbd10
movl $0x1, -0x4(%rbp)
jmp 0x39d8
movl -0x8(%rbp), %eax
movq 0xe665(%rip), %rcx      # 0x11fc8
subl (%rcx), %eax
addl $0x1, %eax
movslq %eax, %rdi
movl $0x8, %esi
callq 0x31a0
movq %rax, 0xf794(%rip)      # 0x13110
movl -0x8(%rbp), %eax
movq 0xe642(%rip), %rcx      # 0x11fc8
subl (%rcx), %eax
movl %eax, 0xf78a(%rip)      # 0x13118
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl 0xf77a(%rip), %eax      # 0x13118
jge 0x39d1
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
movq 0xe61a(%rip), %rdx      # 0x11fc8
addl (%rdx), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq 0xf752(%rip), %rax      # 0x13110
movslq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x3995
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)